JNIEXPORT jint JNICALL Java_edu_hit_ir_ltp4j_Parser_parse (JNIEnv * env, jclass obj, jobject array_words, jobject array_tags, jobject array_heads, jobject array_deprels){ jclass array_list = env->GetObjectClass(array_words); jclass integer = env->FindClass("java/lang/Integer"); jmethodID list_add = env->GetMethodID(array_list,"add","(Ljava/lang/Object;)Z"); jmethodID list_get = env->GetMethodID(array_list,"get","(I)Ljava/lang/Object;"); jmethodID list_size = env->GetMethodID(array_list,"size","()I"); jmethodID integer_init =env->GetMethodID(integer,"<init>","(I)V"); std::vector<std::string> words,tags,deprels; std::vector<int> heads; int size_words = env->CallIntMethod(array_words,list_size); int size_tags = env->CallIntMethod(array_tags,list_size); if(size_words!=size_tags) { return -1; } for(int i = 0;i<size_words;i++){ jobject tmp = env->CallObjectMethod(array_words,list_get,i); jstring s = reinterpret_cast<jstring> (tmp); const char * st = env->GetStringUTFChars(s,0); std::string s_s(st); words.push_back(s_s); env->ReleaseStringUTFChars( s, st); } for(int i = 0;i<size_tags;i++){ jobject tmp = env->CallObjectMethod(array_tags,list_get,i); jstring s = reinterpret_cast<jstring> (tmp); const char * st = env->GetStringUTFChars(s,0); std::string s_s(st); tags.push_back(s_s); env->ReleaseStringUTFChars( s, st); } int len = parser_parse(parser,words,tags,heads,deprels); if(len<0) { return -1; } int size = heads.size(); for(int i = 0;i<size;i++){ jobject integer_object = env->NewObject(integer,integer_init,heads.at(i)); env->CallBooleanMethod(array_heads,list_add, integer_object); } for(int i = 0;i<size;i++){ jobject tmp = stringToJstring(env,deprels[i].c_str()); env->CallBooleanMethod(array_deprels,list_add,tmp); } return len; }
int test_name0(void *state) { enum parser_error r = parser_parse(state, "name:of Resist Lightning"); struct ego_item *e; eq(r, PARSE_ERROR_NONE); e = parser_priv(state); require(e); require(streq(e->name, "of Resist Lightning")); ok; }
int test_rand0(void *state) { int wasok = 0; errr r = parser_reg(state, "test-rand0 rand r0", helper_rand0); eq(r, 0); parser_setpriv(state, &wasok); r = parser_parse(state, "test-rand0:2d3"); eq(r, 0); eq(wasok, 1); ok; }
int test_int1(void *state) { int wasok = 0; errr r = parser_reg(state, "test-int1 int i0", helper_int1); eq(r, 0); parser_setpriv(state, &wasok); r = parser_parse(state, "test-int1:-3"); eq(r, PARSE_ERROR_NONE); eq(wasok, 1); ok; }
int test_sym1(void *state) { int wasok = 0; errr r = parser_reg(state, "test-sym1 sym foo sym baz", helper_sym1); eq(r, 0); parser_setpriv(state, &wasok); r = parser_parse(state, "test-sym1:bar:quxx"); eq(r, PARSE_ERROR_NONE); eq(wasok, 1); ok; }
int test_skill_shoot0(void *state) { enum parser_error r = parser_parse(state, "skill-shoot:6"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->r_skills[SKILL_TO_HIT_BOW], 6); ok; }
int test_skill_stealth0(void *state) { enum parser_error r = parser_parse(state, "skill-stealth:7"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->r_skills[SKILL_STEALTH], 7); ok; }
int test_skill_device0(void *state) { enum parser_error r = parser_parse(state, "skill-device:3"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->r_skills[SKILL_DEVICE], 3); ok; }
static int test_c0(void *state) { enum parser_error r = parser_parse(state, "C:v"); struct monster_race *mr; eq(r, PARSE_ERROR_NONE); mr = parser_priv(state); require(mr); eq(mr->d_attr, TERM_VIOLET); ok; }
static int test_t0(void *state) { enum parser_error r = parser_parse(state, "T:townsfolk"); struct monster_race *mr; eq(r, PARSE_ERROR_NONE); mr = parser_priv(state); require(mr); require(streq(mr->base->name, "townsfolk")); ok; }
static int test_f0(void *state) { enum parser_error r = parser_parse(state, "F:UNIQUE | MALE"); struct monster_race *mr; eq(r, PARSE_ERROR_NONE); mr = parser_priv(state); require(mr); require(mr->flags); ok; }
static int test_f0(void *state) { errr r = parser_parse(state, "F:STR"); struct object_kind *k; eq(r, 0); k = parser_priv(state); require(k); require(k->flags); ok; }
int test_c0(void *state) { enum parser_error r = parser_parse(state, "C:1|3|5"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->choice, (1 << 5) | (1 << 3) | (1 << 1)); ok; }
main(int argc, char **argv){ if(argc < 2) printf("Nothing to do\n"); else avrsh_init(); parser_parse(argv[1]); avrsh_shutdown(); printf("Success\n"); return 0; }
int test_flags0(void *state) { enum parser_error r = parser_parse(state, "flags:SEE_INVIS"); struct ego_item *e; eq(r, PARSE_ERROR_NONE); e = parser_priv(state); require(e); require(e->flags); ok; }
int test_play_flags0(void *state) { enum parser_error r = parser_parse(state, "player-flags:KNOW_ZAPPER"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); require(pr->pflags); ok; }
int test_skill_disarm0(void *state) { enum parser_error r = parser_parse(state, "skill-disarm-magic:1"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->r_skills[SKILL_DISARM_MAGIC], 1); ok; }
int test_l0(void *state) { enum parser_error r = parser_parse(state, "L:17:STR | CON"); struct artifact *a; eq(r, PARSE_ERROR_NONE); a = parser_priv(state); eq(a->pval[0], 17); require(a->pval_flags[0]); ok; }
int test_skill_save0(void *state) { enum parser_error r = parser_parse(state, "skill-save:5"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->r_skills[SKILL_SAVE], 5); ok; }
int test_flags0(void *state) { enum parser_error r = parser_parse(state, "flags:SEE_INVIS | HOLD_LIFE"); struct artifact *a; eq(r, PARSE_ERROR_NONE); a = parser_priv(state); require(a); require(a->flags); ok; }
int test_skill_melee0(void *state) { enum parser_error r = parser_parse(state, "skill-melee:4"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->r_skills[SKILL_TO_HIT_MELEE], 4); ok; }
int test_values0(void *state) { enum parser_error r = parser_parse(state, "values:STR[1] | CON[1]"); struct artifact *a; eq(r, PARSE_ERROR_NONE); a = parser_priv(state); eq(a->modifiers[0], 1); eq(a->modifiers[4], 1); ok; }
int test_sym0(void *state) { int wasok = 0; errr r = parser_reg(state, "test-sym0 sym foo", helper_sym0); eq(r, 0); parser_setpriv(state, &wasok); r = parser_parse(state, "test-sym0:bar"); eq(r, PARSE_ERROR_NONE); eq(wasok, 1); ok; }
int test_skill_throw0(void *state) { enum parser_error r = parser_parse(state, "skill-throw:8"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->r_skills[SKILL_TO_HIT_THROW], 8); ok; }
int test_int0(void *state) { int wasok = 0; errr r = parser_reg(state, "test-int0 int i0 int i1", helper_int0); eq(r, 0); parser_setpriv(state, &wasok); r = parser_parse(state, "test-int0:42:81"); eq(r, PARSE_ERROR_NONE); eq(wasok, 1); ok; }
int test_skill_dig0(void *state) { enum parser_error r = parser_parse(state, "skill-dig:10"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); eq(pr->r_skills[SKILL_DIGGING], 10); ok; }
int test_str0(void *state) { int wasok = 0; errr r = parser_reg(state, "test-str0 str s0", helper_str0); eq(r, 0); parser_setpriv(state, &wasok); r = parser_parse(state, "test-str0:foo:bar:baz quxx..."); eq(r, PARSE_ERROR_NONE); eq(wasok, 1); ok; }
int test_obj_flags0(void *state) { enum parser_error r = parser_parse(state, "obj-flags:SUST_DEX"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); require(pr->flags); ok; }
int test_rand1(void *state) { int wasok = 0; errr r = parser_reg(state, "test-rand1 rand r0 rand r1", helper_rand1); eq(r, 0); parser_setpriv(state, &wasok); r = parser_parse(state, "test-rand1:2d3:4d5"); eq(r, 0); eq(wasok, 1); ok; }
int test_smell0(void *state) { enum parser_error r = parser_parse(state, "smell:30"); struct monster_race *mr; eq(r, PARSE_ERROR_NONE); mr = parser_priv(state); require(mr); eq(mr->smell, 30); ok; }