void test_enumerate_keyboard_type() { ChewingContext *ctx; size_t i; char *keyboard_string; ctx = chewing_new(); ok( chewing_kbtype_Total( ctx ) == ARRAY_SIZE( KEYBOARD_STRING ), "total keyboard_string type shall be %d", ARRAY_SIZE( KEYBOARD_STRING ) ); chewing_kbtype_Enumerate( ctx ); for ( i = 0; i < ARRAY_SIZE( KEYBOARD_STRING ); ++i ) { ok( chewing_kbtype_hasNext( ctx ) == 1 , "shall have next keyboard_string type" ); keyboard_string = chewing_kbtype_String( ctx ); ok( strcmp( keyboard_string, KEYBOARD_STRING[i] ) == 0, "`%s' shall be `%s'", keyboard_string, KEYBOARD_STRING[i] ); chewing_free( keyboard_string ); } ok( chewing_kbtype_hasNext( ctx ) == 0 , "shall not have next keyboard_string type" ); keyboard_string = chewing_kbtype_String( ctx ); ok( strcmp( keyboard_string, "" ) == 0, "`%s' shall be `%s'", keyboard_string, "" ); chewing_free( keyboard_string ); chewing_delete( ctx ); }
void test_Space_selection_word() { ChewingContext *ctx; char *buf; int len; clean_userphrase(); ctx = chewing_new(); start_testcase(ctx, fd); chewing_set_spaceAsSelection(ctx, 1); type_keystroke_by_string(ctx, "hk4g4<H>" /* 測試 */ ); type_keystroke_by_string(ctx, " "); /* open candidate window */ chewing_cand_Enumerate(ctx); buf = chewing_cand_String(ctx); len = ueStrLen(buf); ok(len == 2, "candidate `%s' length `%d' shall be `%d'", buf, len, 2); chewing_free(buf); type_keystroke_by_string(ctx, " "); /* next candidate list */ chewing_cand_Enumerate(ctx); buf = chewing_cand_String(ctx); len = ueStrLen(buf); ok(len == 1, "candidate `%s' length `%d' shall be `%d'", buf, len, 1); chewing_free(buf); type_keystroke_by_string(ctx, " "); /* next page */ ok(chewing_cand_CurrentPage(ctx) == 1, "current page shall be 1"); chewing_delete(ctx); }
void internal_ok_candidate( const char *file, int line, ChewingContext *ctx, const char *cand[], size_t cand_len ) { size_t i; char *buf; assert( ctx ); chewing_cand_Enumerate( ctx ); for ( i = 0; i < cand_len; ++i ) { internal_ok( file, line, chewing_cand_hasNext( ctx ), __func__, "shall has next candidate" ); buf = chewing_cand_String( ctx ); internal_ok( file, line, strcmp( buf, cand[i] ) == 0, __func__, "candidate `%s' shall be `%s'", buf, cand[i] ); chewing_free( buf ); buf = chewing_cand_string_by_index( ctx, i ); internal_ok( file, line, strcmp( buf, cand[i] ) == 0, __func__, "candndate `%s' shall be `%s'", buf, cand[i] ); chewing_free( buf ); } internal_ok( file, line , !chewing_cand_hasNext( ctx ), __func__, "shall not have next candidate" ); buf = chewing_cand_String( ctx ); internal_ok( file, line, strcmp( buf, "" ) == 0, __func__, "candndate `%s' shall be `%s'", buf, "" ); chewing_free( buf ); }
void internal_ok_buffer( const char *file, int line, ChewingContext *ctx, const char *expected, const BufferType *buffer ) { char *buf; int actual_ret; int expected_ret; int expected_len; assert( ctx ); assert( expected ); assert( buffer ); expected_len = ueStrLen( expected ); if ( buffer->check ) { actual_ret = buffer->check( ctx ); expected_ret = !!expected_len; internal_ok( file, line, actual_ret == expected_ret, "actual_ret == expected_ret", "%s check function returned `%d' shall be `%d'", buffer->name, actual_ret, expected_ret ); } if ( buffer->check_alt ) { actual_ret = buffer->check_alt( ctx ); expected_ret = !expected_len; internal_ok( file, line, actual_ret == expected_ret, "actual_ret == expected_ret", "%s check function returned `%d' shall be `%d'", buffer->name, actual_ret, expected_ret ); } if ( buffer->get_length ) { actual_ret = buffer->get_length( ctx ); expected_ret = expected_len; internal_ok( file, line, actual_ret == expected_ret, "actual_ret == expected_ret", "%s get length function returned `%d' shall be `%d'", buffer->name, actual_ret, expected_ret ); } if ( buffer->get_string ) { buf = buffer->get_string( ctx ); internal_ok( file, line, !strcmp( buf, expected ), "!strcmp( buf, expected )", "%s string function returned `%s' shall be `%s'", buffer->name, buf, expected ); chewing_free( buf ); } if ( buffer->get_string_alt ) { buf = buffer->get_string_alt( ctx, &actual_ret ); expected_ret = expected_len; internal_ok( file, line, actual_ret == expected_ret, "actual_ret == expected_ret", "%s string function returned parameter `%d' shall be `%d'", buffer->name, actual_ret, expected_ret ); internal_ok( file, line, !strcmp( buf, expected ), "!strcmp( buf, expected )", "%s string function returned `%s' shall be `%s'", buffer->name, buf, expected ); chewing_free( buf ); } }
void test_set_selKey() { ChewingContext *ctx; int *select_key; chewing_Init( 0, 0 ); ctx = chewing_new(); chewing_set_maxChiSymbolLen( ctx, 16 ); // XXX: chewing_set_selKey shall accept const char *. chewing_set_selKey( ctx, ALTERNATE_SELECT_KEY, ARRAY_SIZE( ALTERNATE_SELECT_KEY )); select_key = chewing_get_selKey( ctx ); ok( select_key, "chewing_get_selKey shall not return NULL" ); ok( !memcmp( select_key, ALTERNATE_SELECT_KEY, sizeof( ALTERNATE_SELECT_KEY )), "select key shall be ALTERNATE_SELECT_KEY"); type_keystroke_by_string( ctx, DATA.token ); ok_preedit_buffer( ctx, DATA.expected ); chewing_free( select_key ); chewing_delete( ctx ); chewing_Terminate(); }
/* * Return the i-th candidate wchar (WCH_SIZE bytes), i starts from 0. * User MUST free() the return value of this sub-routine, * even if it's a false value. */ char* Chewing::Selection(int i) { /* FIXME: This can be more efficient */ int j = 0; chewing_cand_Enumerate(ctx); for (j = 0; chewing_cand_hasNext(ctx) && j < i; j++) chewing_free(chewing_cand_String(ctx)); return chewing_cand_String(ctx); }
void test_select_candidate_rearward_start_with_symbol() { ChewingContext *ctx; int ret; char *buf; int len; clean_userphrase(); ctx = chewing_new(); start_testcase(ctx, fd); chewing_set_phraseChoiceRearward(ctx, 1); type_keystroke_by_string(ctx, "`31hk4g4" /* ,測試 */ ); type_keystroke_by_string(ctx, "<EE><H><D>"); ret = chewing_cand_TotalChoice(ctx); ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall greater than 0 at pos `%d'", ret, 0); chewing_cand_Enumerate(ctx); buf = chewing_cand_String(ctx); len = ueStrLen(buf); ok(len == 1, "candidate `%s' length `%d' shall be `%d' at pos `%d'", buf, len, 1, 0); chewing_free(buf); type_keystroke_by_string(ctx, "<EE><H><R><D>"); ret = chewing_cand_TotalChoice(ctx); ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall greater than 0 at pos `%d'", ret, 1); chewing_cand_Enumerate(ctx); buf = chewing_cand_String(ctx); len = ueStrLen(buf); ok(len == 1, "candidate `%s' length `%d' shall be `%d' at pos `%d'", buf, len, 1, 1); chewing_free(buf); type_keystroke_by_string(ctx, "<EE><H><R><R><D>"); ret = chewing_cand_TotalChoice(ctx); ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall greater than 0 at pos `%d'", ret, 2); chewing_cand_Enumerate(ctx); buf = chewing_cand_String(ctx); len = ueStrLen(buf); ok(len == 2, "candidate `%s' length `%d' shall be `%d' at pos `%d'", buf, len, 2, 2); chewing_free(buf); chewing_delete(ctx); }
void test_set_keyboard_type() { ChewingContext *ctx; size_t i; char *keyboard_string; int keyboard_type; ctx = chewing_new(); keyboard_string = chewing_get_KBString( ctx ); ok( strcmp( keyboard_string, KEYBOARD_STRING[KEYBOARD_DEFAULT_TYPE] ) == 0, "`%s' shall be `%s'", keyboard_string, KEYBOARD_STRING[KEYBOARD_DEFAULT_TYPE] ); chewing_free( keyboard_string ); keyboard_type = chewing_get_KBType( ctx ); ok( keyboard_type == KEYBOARD_DEFAULT_TYPE , "`%d' shall be `%d'", keyboard_type, KEYBOARD_DEFAULT_TYPE ); for ( i = 0; i < ARRAY_SIZE( KEYBOARD_STRING ); ++i ) { ok ( chewing_set_KBType( ctx, i ) == 0, "return shall be 0" ); keyboard_string = chewing_get_KBString( ctx ); ok( strcmp( keyboard_string, KEYBOARD_STRING[i] ) == 0, "`%s' shall be `%s'", keyboard_string, KEYBOARD_STRING[i] ); chewing_free( keyboard_string ); keyboard_type = chewing_get_KBType( ctx ); ok( keyboard_type == (int)i , "`%d' shall be `%d'", keyboard_type, (int)i ); } // The invalid KBType will reset KBType to default value. ok( chewing_set_KBType( ctx, -1 ) == -1, "return shall be -1" ); keyboard_type = chewing_get_KBType( ctx ); ok( keyboard_type == KEYBOARD_DEFAULT_TYPE , "`%d' shall be `%d'", keyboard_type, KEYBOARD_DEFAULT_TYPE ); ok( chewing_set_KBType( ctx, ARRAY_SIZE( KEYBOARD_STRING ) + 1 ), "return shall be -1" ); keyboard_type = chewing_get_KBType( ctx ); ok( keyboard_type == KEYBOARD_DEFAULT_TYPE , "`%d' shall be `%d'", keyboard_type, KEYBOARD_DEFAULT_TYPE ); chewing_delete( ctx ); }
/* * Return i-th selection-key. i starts from 0. */ char Chewing::SelKey(int i) { char ret; int *selkey = chewing_get_selKey( ctx ); if ( 0 <= i && i < 10 ) ret = selkey[i]; else ret = 0; chewing_free( selkey ); return ret; }
void test_set_selKey_error_handling() { ChewingContext *ctx; int *select_key; ctx = chewing_new(); start_testcase( ctx, fd ); chewing_set_selKey( NULL, ALTERNATE_SELECT_KEY, ARRAY_SIZE( ALTERNATE_SELECT_KEY ) ); select_key = chewing_get_selKey( ctx ); ok( select_key, "chewing_get_selKey shall not return NULL" ); ok( !memcmp( select_key, DEFAULT_SELECT_KEY, sizeof( DEFAULT_SELECT_KEY )), "select key shall be DEFAULT_SELECT_KEY"); chewing_free( select_key ); chewing_set_selKey( ctx, NULL, ARRAY_SIZE( ALTERNATE_SELECT_KEY ) ); select_key = chewing_get_selKey( ctx ); ok( select_key, "chewing_get_selKey shall not return NULL" ); ok( !memcmp( select_key, DEFAULT_SELECT_KEY, sizeof( DEFAULT_SELECT_KEY )), "select key shall be DEFAULT_SELECT_KEY"); chewing_free( select_key ); chewing_set_selKey( ctx, ALTERNATE_SELECT_KEY, 0 ); select_key = chewing_get_selKey( ctx ); ok( select_key, "chewing_get_selKey shall not return NULL" ); ok( !memcmp( select_key, DEFAULT_SELECT_KEY, sizeof( DEFAULT_SELECT_KEY )), "select key shall be DEFAULT_SELECT_KEY"); chewing_free( select_key ); chewing_set_selKey( ctx, ALTERNATE_SELECT_KEY, 11 ); select_key = chewing_get_selKey( ctx ); ok( select_key, "chewing_get_selKey shall not return NULL" ); ok( !memcmp( select_key, DEFAULT_SELECT_KEY, sizeof( DEFAULT_SELECT_KEY )), "select key shall be DEFAULT_SELECT_KEY"); chewing_free( select_key ); chewing_delete( ctx ); }
/** * @brief Process Key Input and return the status * * @param keycode keycode from XKeyEvent * @param state state from XKeyEvent * @param count count from XKeyEvent * @return INPUT_RETURN_VALUE **/ __EXPORT_API INPUT_RETURN_VALUE FcitxChewingDoInput(void* arg, FcitxKeySym sym, unsigned int state) { FcitxChewing* chewing = (FcitxChewing*) arg; FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner); ChewingContext * c = chewing->context; if (FcitxCandidateWordGetListSize(FcitxInputStateGetCandidateList(input)) > 0 && (FcitxHotkeyIsHotKeyDigit(sym, state) || FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT) || FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT))) return IRV_TO_PROCESS; if (FcitxHotkeyIsHotKeySimple(sym, state)) { int scan_code = (int) sym & 0xff; chewing_handle_Default(c, scan_code); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) { chewing_handle_Backspace(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) { chewing_handle_Esc(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_DELETE)) { chewing_handle_Del(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) { chewing_handle_Space(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_UP)) { chewing_handle_Up(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_DOWN)) { chewing_handle_Down(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGUP)) { chewing_handle_PageDown(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGDN)) { chewing_handle_PageUp(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT)) { chewing_handle_Right(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT)) { chewing_handle_Left(c); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) { chewing_handle_Enter(c); } else if (state == FcitxKeyState_Ctrl && FcitxHotkeyIsHotKeyDigit(sym, FcitxKeyState_None)) { chewing_handle_CtrlNum(c, sym); } else { // to do: more chewing_handle return IRV_TO_PROCESS; } if (chewing_keystroke_CheckAbsorb(c)) { return IRV_DISPLAY_CANDWORDS; } else if (chewing_keystroke_CheckIgnore(c)) { return IRV_TO_PROCESS; } else if (chewing_commit_Check(c)) { char* str = chewing_commit_String(c); strcpy(FcitxInputStateGetOutputString(input), str); chewing_free(str); return IRV_COMMIT_STRING; } else return IRV_DISPLAY_CANDWORDS; }
int Chewing::Enter() { int rt; uint16_t *oldSeq = chewing_get_phoneSeq(ctx); int seqLen = chewing_get_phoneSeqLen(ctx); rt = chewing_handle_Enter(ctx); if (chewing_commit_Check(ctx)) { memcpy(g_lastPhoneSeq, oldSeq, seqLen*sizeof(uint16_t)); g_lastPhoneSeq[seqLen] = 0; } chewing_free(oldSeq); return rt; }
void test_default_value() { int *select_key; ChewingContext *ctx; chewing_Init( 0, 0 ); ctx = chewing_new(); select_key = chewing_get_selKey( ctx ); ok( select_key, "chewing_get_selKey shall not return NULL" ); ok( !memcmp( select_key, DEFAULT_SELECT_KEY, sizeof( DEFAULT_SELECT_KEY )), "select key shall be default value"); chewing_free( select_key ); ok( chewing_get_candPerPage( ctx ) == DEFAULT_CAND_PER_PAGE, "candPerPage shall be default value" ); ok( chewing_get_maxChiSymbolLen( ctx ) == 0, "maxChiSymbolLen shall be 0" ); ok( chewing_get_addPhraseDirection( ctx ) == 0, "addPhraseDirection shall be 0" ); ok( chewing_get_spaceAsSelection( ctx ) == 0, "spaceAsSelection shall be 0" ); ok( chewing_get_escCleanAllBuf( ctx ) == 0, "escCleanAllBuf shall be 0" ); ok( chewing_get_hsuSelKeyType( ctx ) == 0, "hsuSelKeyType shall be 0" ); ok( chewing_get_autoShiftCur( ctx ) == 0, "autoShiftCur shall be 0" ); ok( chewing_get_easySymbolInput( ctx ) == 0, "easySymbolInput shall be 0" ); ok( chewing_get_phraseChoiceRearward( ctx ) == 0, "phraseChoiceRearward shall be 0" ); ok( chewing_get_ChiEngMode( ctx ) == CHINESE_MODE, "ChiEngMode shall be CHINESE_MODE" ); ok( chewing_get_ShapeMode( ctx ) == HALFSHAPE_MODE, "ShapeMode shall be HALFSHAPE_MODE" ); chewing_delete( ctx ); chewing_Terminate(); }
void test_default_value() { int *select_key; ChewingContext *ctx; print_function_name(); ctx = chewing_new(); select_key = chewing_get_selKey( ctx ); ok( select_key, "chewing_get_selKey shall not return NULL" ); ok( !memcmp( select_key, DEFAULT_SELECT_KEY, sizeof( DEFAULT_SELECT_KEY )), "default select key shall be default value" ); chewing_free( select_key ); ok( chewing_get_candPerPage( ctx ) == DEFAULT_CAND_PER_PAGE, "default candPerPage shall be %d", DEFAULT_CAND_PER_PAGE ); ok( chewing_get_maxChiSymbolLen( ctx ) == MAX_CHI_SYMBOL_LEN, "default maxChiSymbolLen shall be %d", MAX_CHI_SYMBOL_LEN ); ok( chewing_get_addPhraseDirection( ctx ) == 0, "default addPhraseDirection shall be 0" ); ok( chewing_get_spaceAsSelection( ctx ) == 0, "default spaceAsSelection shall be 0" ); ok( chewing_get_escCleanAllBuf( ctx ) == 0, "default escCleanAllBuf shall be 0" ); ok( chewing_get_hsuSelKeyType( ctx ) == 0, "default hsuSelKeyType shall be 0" ); ok( chewing_get_autoShiftCur( ctx ) == 0, "default autoShiftCur shall be 0" ); ok( chewing_get_easySymbolInput( ctx ) == 0, "default easySymbolInput shall be 0" ); ok( chewing_get_phraseChoiceRearward( ctx ) == 0, "default phraseChoiceRearward shall be 0" ); ok( chewing_get_ChiEngMode( ctx ) == CHINESE_MODE, "default ChiEngMode shall be CHINESE_MODE" ); ok( chewing_get_ShapeMode( ctx ) == HALFSHAPE_MODE, "default ShapeMode shall be HALFSHAPE_MODE" ); chewing_delete( ctx ); }
void internal_ok_candidate_len( const char *file, int line, ChewingContext *ctx, size_t expected_len ) { char *buf; int actual_len; assert( ctx ); buf = chewing_cand_string_by_index( ctx, 0 ); actual_len = ueStrLen( buf ); internal_ok( file, line, actual_len == expected_len, __func__, "candidate length `%d' shall be `%d'", actual_len, expected_len ); chewing_free( buf ); }
void test_get_phoneSeq() { static const struct { char *token; unsigned short phone[5]; } DATA[] = { { "hk4g4", {10268, 8708, 0} }, { "hk4g4`31hk4g4", {10268, 8708, 10268, 8708, 0} }, { "`31`31", {0} }, }; ChewingContext *ctx; size_t i; int expected_len; int len; unsigned short *phone; ctx = chewing_new(); start_testcase(ctx, fd); chewing_set_maxChiSymbolLen(ctx, 16); for (i = 0; i < ARRAY_SIZE(DATA); ++i) { chewing_Reset(ctx); type_keystroke_by_string(ctx, DATA[i].token); expected_len = 0; while (DATA[i].phone[expected_len] != 0) ++expected_len; len = chewing_get_phoneSeqLen(ctx); ok(len == expected_len, "phoneSeqLen `%d' shall be `%d'", len, expected_len); phone = chewing_get_phoneSeq(ctx); ok(memcmp(phone, DATA[i].phone, sizeof(phone[0]) * expected_len) == 0, "phoneSeq shall be expected value"); chewing_free(phone); } chewing_delete(ctx); }
INPUT_RETURN_VALUE FcitxChewingGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxChewing* chewing = (FcitxChewing*) candWord->owner; ChewingCandWord* w = (ChewingCandWord*) candWord->priv; FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(chewing->owner); FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner); int page = w->index / config->iMaxCandWord; int off = w->index % config->iMaxCandWord; if (page < 0 || page >= chewing_cand_TotalPage(chewing->context)) return IRV_TO_PROCESS; int lastPage = chewing_cand_CurrentPage(chewing->context); while (page != chewing_cand_CurrentPage(chewing->context)) { if (page < chewing_cand_CurrentPage(chewing->context)) { chewing_handle_Left(chewing->context); } if (page > chewing_cand_CurrentPage(chewing->context)) { chewing_handle_Right(chewing->context); } /* though useless, but take care if there is a bug cause freeze */ if (lastPage == chewing_cand_CurrentPage(chewing->context)) { break; } lastPage = chewing_cand_CurrentPage(chewing->context); } chewing_handle_Default( chewing->context, selKey[off] ); if (chewing_keystroke_CheckAbsorb(chewing->context)) { return IRV_DISPLAY_CANDWORDS; } else if (chewing_keystroke_CheckIgnore(chewing->context)) { return IRV_TO_PROCESS; } else if (chewing_commit_Check(chewing->context)) { char* str = chewing_commit_String(chewing->context); strcpy(FcitxInputStateGetOutputString(input), str); chewing_free(str); return IRV_COMMIT_STRING; } else return IRV_DISPLAY_CANDWORDS; }
void test_null() { int ret; char *buf; const char *const_buf; int *key; unsigned short *phone; start_testcase(NULL, fd); chewing_Reset(NULL); // shall not crash ret = chewing_set_KBType(NULL, 0); ok(ret == -1, "chewing_set_KBType() returns `%d' shall be `%d'", ret, -1); ret = chewing_get_KBType(NULL); ok(ret == -1, "chewing_get_KBType() returns `%d' shall be `%d'", ret, -1); buf = chewing_get_KBString(NULL); ok(strcmp(buf, "") == 0, "chewing_get_KBString() returns `%s' shall be `%s'", buf, ""); chewing_free(buf); chewing_delete(NULL); // shall not crash chewing_free(NULL); // shall not crash chewing_set_candPerPage(NULL, 0); // shall not crash ret = chewing_get_candPerPage(NULL); ok(ret == -1, "chewing_get_candPerPage() returns `%d' shall be `%d'", ret, -1); chewing_set_maxChiSymbolLen(NULL, 0); // shall not crash ret = chewing_get_maxChiSymbolLen(NULL); ok(ret == -1, "chewing_get_maxChiSymbolLen() returns `%d' shall be `%d'", ret, -1); chewing_set_selKey(NULL, NULL, 0); // shall not crash key = chewing_get_selKey(NULL); ok(key == NULL, "chewing_get_selKey() returns NULL"); chewing_free(key); chewing_set_addPhraseDirection(NULL, 0); // shall not crash ret = chewing_get_addPhraseDirection(NULL); ok(ret == -1, "chewing_get_addPhraseDirection() returns `%d' shall be `%d'", ret, -1); chewing_set_spaceAsSelection(NULL, 0); // shall not crash ret = chewing_get_spaceAsSelection(NULL); ok(ret == -1, "chewing_get_spaceAsSelection() returns `%d' shall be `%d'", ret, -1); chewing_set_escCleanAllBuf(NULL, 0); // shall not crash ret = chewing_get_escCleanAllBuf(NULL); ok(ret == -1, "chewing_get_escCleanAllBuf() returns `%d' shall be `%d'", ret, -1); chewing_set_autoShiftCur(NULL, 0); // shall not crash ret = chewing_get_autoShiftCur(NULL); ok(ret == -1, "chewing_get_autoShiftCur() returns `%d' shall be `%d'", ret, -1); chewing_set_easySymbolInput(NULL, 0); // shall not crash ret = chewing_get_easySymbolInput(NULL); ok(ret == -1, "chewing_get_easySymbolInput() returns `%d' shall be `%d'", ret, -1); chewing_set_phraseChoiceRearward(NULL, 0); ret = chewing_get_phraseChoiceRearward(NULL); ok(ret == -1, "chewing_get_phraseChoiceRearward() returns `%d' shall be `%d'", ret, -1); chewing_set_ChiEngMode(NULL, 0); // shall not crash ret = chewing_get_ChiEngMode(NULL); ok(ret == -1, "chewing_get_ChiEngMode() returns `%d' shall be `%d'", ret, -1); chewing_set_ShapeMode(NULL, 0); // shall not crash ret = chewing_handle_Space(NULL); ok(ret == -1, "chewing_handle_Space() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Esc(NULL); ok(ret == -1, "chewing_handle_Esc() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Enter(NULL); ok(ret == -1, "chewing_handle_Enter() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Del(NULL); ok(ret == -1, "chewing_handle_Del() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Backspace(NULL); ok(ret == -1, "chewing_handle_Backspace() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Up(NULL); ok(ret == -1, "chewing_handle_Up() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Down(NULL); ok(ret == -1, "chewing_handle_Down() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_ShiftLeft(NULL); ok(ret == -1, "chewing_handle_ShiftLeft() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Left(NULL); ok(ret == -1, "chewing_handle_Left() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_ShiftRight(NULL); ok(ret == -1, "chewing_handle_ShiftRight() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Right(NULL); ok(ret == -1, "chewing_handle_Right() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Tab(NULL); ok(ret == -1, "chewing_handle_Tab() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_DblTab(NULL); ok(ret == -1, "chewing_handle_DblTab() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Capslock(NULL); ok(ret == -1, "chewing_handle_Capslock() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Home(NULL); ok(ret == -1, "chewing_handle_Home() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_PageUp(NULL); ok(ret == -1, "chewing_handle_PageUp() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_PageDown(NULL); ok(ret == -1, "chewing_handle_PageDown() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Default(NULL, 0); ok(ret == -1, "chewing_handle_Default() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_CtrlNum(NULL, 0); ok(ret == -1, "chewing_handle_CtrlNum() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_ShiftSpace(NULL); ok(ret == -1, "chewing_handle_ShiftSpace() returns `%d' shall be `%d'", ret, -1); ret = chewing_handle_Numlock(NULL, 0); ok(ret == -1, "chewing_handle_Numlock() returns `%d' shall be `%d'", ret, -1); phone = chewing_get_phoneSeq(NULL); ok(phone == NULL, "chewing_get_phoneSeq() returns NULL"); chewing_free(phone); ret = chewing_get_phoneSeqLen(NULL); ok(ret == -1, "chewing_get_phoneSeqLen() returns `%d' shall be `%d'", ret, -1); chewing_set_logger(NULL, NULL, NULL); ret = chewing_userphrase_enumerate(NULL); ok(ret == -1, "chewing_userphrase_enumerate() returns `%d' shall be `%d'", ret, -1); ret = chewing_userphrase_has_next(NULL, NULL, NULL); ok(ret == 0, "chewing_userphrase_has_next() returns `%d' shall be `%d'", ret, 0); ret = chewing_userphrase_get(NULL, NULL, 0, NULL, 0); ok(ret == -1, "chewing_userphrase_get() returns `%d' shall be `%d'", ret, -1); ret = chewing_userphrase_add(NULL, NULL, NULL); ok(ret == -1, "chewing_userphrase_add() returns `%d' shall be `%d'", ret, -1); ret = chewing_userphrase_remove(NULL, NULL, NULL); ok(ret == -1, "chewing_userphrase_remove() returns `%d' shall be `%d'", ret, -1); ret = chewing_userphrase_lookup(NULL, NULL, NULL); ok(ret == 0, "chewing_userphrase_lookup() returns `%d' shall be `%d'", ret, 0); ret = chewing_cand_open(NULL); ok(ret == -1, "chewing_cand_open() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_close(NULL); ok(ret == -1, "chewing_cand_open() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_choose_by_index(NULL, 0); ok(ret == -1, "chewing_cand_choose_by_index() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_list_first(NULL); ok(ret == -1, "chewing_cand_list_first() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_list_last(NULL); ok(ret == -1, "chewing_cand_list_last() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_list_has_next(NULL); ok(ret == 0, "chewing_cand_list_has_next() returns `%d' shall be `%d'", ret, 0); ret = chewing_cand_list_has_prev(NULL); ok(ret == 0, "chewing_cand_list_has_prev() returns `%d' shall be `%d'", ret, 0); ret = chewing_cand_list_next(NULL); ok(ret == -1, "chewing_cand_list_next() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_list_prev(NULL); ok(ret == -1, "chewing_cand_list_prev() returns `%d' shall be `%d'", ret, -1); ret = chewing_commit_preedit_buf(NULL); ok(ret == -1, "chewing_commit_preedit_buf() returns `%d' shall be `%d'", ret, -1); ret = chewing_clean_preedit_buf(NULL); ok(ret == -1, "chewing_clean_preedit_buf() returns `%d' shall be `%d'", ret, -1); ret = chewing_clean_bopomofo_buf(NULL); ok(ret == -1, "chewing_clean_bopomofo_buf() returns `%d' shall be `%d'", ret, -1); ret = chewing_commit_Check(NULL); ok(ret == -1, "chewing_commit_Check() returns `%d' shall be `%d'", ret, -1); buf = chewing_commit_String(NULL); ok(strcmp(buf, "") == 0, "chewing_commit_String() returns `%s' shall be `%s'", buf, ""); chewing_free(buf); const_buf = chewing_commit_String_static(NULL); ok(strcmp(const_buf, "") == 0, "chewing_commit_String() returns `%s' shall be `%s'", const_buf, ""); ret = chewing_buffer_Check(NULL); ok(ret == -1, "chewing_buffer_Check() returns `%d' shall be `%d'", ret, -1); ret = chewing_buffer_Len(NULL); ok(ret == -1, "chewing_buffer_Len() returns `%d' shall be `%d'", ret, -1); buf = chewing_buffer_String(NULL); ok(strcmp(buf, "") == 0, "chewing_buffer_String() returns `%s' shall be `%s'", buf, ""); chewing_free(buf); const_buf = chewing_buffer_String_static(NULL); ok(strcmp(const_buf, "") == 0, "chewing_buffer_String_static() returns `%s' shall be `%s'", const_buf, ""); const_buf = chewing_bopomofo_String_static(NULL); ok(strcmp(const_buf, "") == 0, "chewing_bopomofo_String_static() returns `%s' shall be `%s'", const_buf, ""); BEGIN_IGNORE_DEPRECATIONS buf = chewing_zuin_String(NULL, NULL); END_IGNORE_DEPRECATIONS ok(strcmp(buf, "") == 0, "chewing_zuin_String() returns `%s' shall be `%s'", buf, ""); chewing_free(buf); ret = chewing_bopomofo_Check(NULL); ok(ret == -1, "chewing_bopomofo_Check() returns `%d' shall be `%d'", ret, -1); BEGIN_IGNORE_DEPRECATIONS chewing_zuin_Check(NULL); // shall not crash END_IGNORE_DEPRECATIONS ret = chewing_cursor_Current(NULL); ok(ret == -1, "chewing_cursor_Current() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_CheckDone(NULL); ok(ret == -1, "chewing_cand_CheckDone() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_TotalPage(NULL); ok(ret == -1, "chewing_cand_TotalPage() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_ChoicePerPage(NULL); ok(ret == -1, "chewing_cand_ChoicePerPage() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_TotalChoice(NULL); ok(ret == -1, "chewing_cand_TotalChoice() returns `%d' shall be `%d'", ret, -1); ret = chewing_cand_CurrentPage(NULL); ok(ret == -1, "chewing_cand_CurrentPage() returns `%d' shall be `%d'", ret, -1); chewing_cand_Enumerate(NULL); // shall not crash ret = chewing_cand_hasNext(NULL); ok(ret == -1, "chewing_cand_hasNext() returns `%d' shall be `%d'", ret, -1); const_buf = chewing_cand_String_static(NULL); ok(strcmp(const_buf, "") == 0, "chewing_cand_String_static() returns `%s' shall be `%s'", const_buf, ""); buf = chewing_cand_String(NULL); ok(strcmp(buf, "") == 0, "chewing_cand_String() returns `%s' shall be `%s'", buf, ""); chewing_free(buf); chewing_interval_Enumerate(NULL); // shall not crash ret = chewing_interval_hasNext(NULL); ok(ret == -1, "chewing_interval_hasNext() returns `%d' shall be `%d'", ret, -1); chewing_interval_Get(NULL, NULL); // shall not crash ret = chewing_aux_Check(NULL); ok(ret == -1, "chewing_aux_Check() returns `%d' shall be `%d'", ret, -1); ret = chewing_aux_Length(NULL); ok(ret == -1, "chewing_aux_Length() returns `%d' shall be `%d'", ret, -1); const_buf = chewing_aux_String_static(NULL); ok(strcmp(const_buf, "") == 0, "chewing_aux_String_static() returns `%s' shall be `%s'", const_buf, ""); buf = chewing_aux_String(NULL); ok(strcmp(buf, "") == 0, "chewing_aux_String() returns `%s' shall be `%s'", buf, ""); chewing_free(buf); ret = chewing_keystroke_CheckIgnore(NULL); ok(ret == -1, "chewing_keystroke_CheckIgnore() returns `%d' shall be `%d'", ret, -1); ret = chewing_keystroke_CheckAbsorb(NULL); ok(ret == -1, "chewing_keystroke_CheckAbsorb() returns `%d' shall be `%d'", ret, -1); chewing_kbtype_Enumerate(NULL); // shall not crash ret = chewing_kbtype_hasNext(NULL); ok(ret == -1, "chewing_kbtype_hasNext() returns `%d' shall be `%d'", ret, -1); const_buf = chewing_kbtype_String_static(NULL); ok(strcmp(const_buf, "") == 0, "chewing_kbtype_String_static() returns `%s' shall be `%s'", const_buf, ""); buf = chewing_kbtype_String(NULL); ok(strcmp(buf, "") == 0, "chewing_kbtype_String() returns `%s' shall be `%s'", buf, ""); chewing_free(buf); }
/** * @brief Process Key Input and return the status * * @param keycode keycode from XKeyEvent * @param state state from XKeyEvent * @param count count from XKeyEvent * @return INPUT_RETURN_VALUE **/ __EXPORT_API INPUT_RETURN_VALUE FcitxChewingDoInput(void* arg, FcitxKeySym sym, unsigned int state) { FcitxChewing* chewing = (FcitxChewing*) arg; FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner); ChewingContext * ctx = chewing->context; int zuin_len; FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); if (FcitxCandidateWordGetListSize(candList) > 0) { if (FcitxHotkeyIsHotKeyDigit(sym, state) || FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT) || FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT)) return IRV_TO_PROCESS; if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) { if (FcitxCandidateWordGoNextPage(candList)) return IRV_DISPLAY_MESSAGE; else return IRV_DO_NOTHING; } } if (FcitxHotkeyIsHotKeySimple(sym, state)) { int scan_code = (int) sym & 0xff; chewing_handle_Default(ctx, scan_code); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) { char * zuin_str = chewing_zuin_String(ctx, &zuin_len); chewing_free(zuin_str); if (chewing_buffer_Len(ctx) + zuin_len == 0) return IRV_TO_PROCESS; chewing_handle_Backspace(ctx); if (chewing_buffer_Len(ctx) + zuin_len == 0) return IRV_CLEAN; } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) { chewing_handle_Esc(ctx); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_DELETE)) { char * zuin_str = chewing_zuin_String(ctx, &zuin_len); chewing_free(zuin_str); if (chewing_buffer_Len(ctx) + zuin_len == 0) return IRV_TO_PROCESS; chewing_handle_Del(ctx); if (chewing_buffer_Len(ctx) + zuin_len == 0) return IRV_CLEAN; } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) { chewing_handle_Space(ctx); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_UP)) { chewing_handle_Up(ctx); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_DOWN)) { chewing_handle_Down(ctx); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGUP)) { chewing_handle_PageDown(ctx); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGDN)) { chewing_handle_PageUp(ctx); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT)) { chewing_handle_Right(ctx); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT)) { chewing_handle_Left(ctx); } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) { chewing_handle_Enter(ctx); } else if (state == FcitxKeyState_Ctrl && FcitxHotkeyIsHotKeyDigit(sym, FcitxKeyState_None)) { chewing_handle_CtrlNum(ctx, sym); } else { // to do: more chewing_handle return IRV_TO_PROCESS; } if (chewing_keystroke_CheckAbsorb(ctx)) { return IRV_DISPLAY_CANDWORDS; } else if (chewing_keystroke_CheckIgnore(ctx)) { return IRV_TO_PROCESS; } else if (chewing_commit_Check(ctx)) { char* str = chewing_commit_String(ctx); FcitxInputContext* ic = FcitxInstanceGetCurrentIC(chewing->owner); FcitxInstanceCommitString(chewing->owner, ic, str); chewing_free(str); return IRV_DISPLAY_CANDWORDS; } else return IRV_DISPLAY_CANDWORDS; }
/** * @brief function DoInput has done everything for us. * * @param searchMode * @return INPUT_RETURN_VALUE **/ __EXPORT_API INPUT_RETURN_VALUE FcitxChewingGetCandWords(void* arg) { FcitxChewing* chewing = (FcitxChewing*) arg; FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner); FcitxMessages *msgPreedit = FcitxInputStateGetPreedit(input); FcitxMessages *clientPreedit = FcitxInputStateGetClientPreedit(input); ChewingContext * c = chewing->context; FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(chewing->owner); chewing_set_candPerPage(c, config->iMaxCandWord); FcitxCandidateWordSetPageSize(FcitxInputStateGetCandidateList(input), config->iMaxCandWord); //clean up window asap FcitxInstanceCleanInputWindow(chewing->owner); char * buf_str = chewing_buffer_String(c); char * zuin_str = chewing_zuin_String(c, NULL); ConfigChewing(chewing); FcitxLog(DEBUG, "%s %s", buf_str, zuin_str); /* if not check done, so there is candidate word */ if (!chewing_cand_CheckDone(c)) { //get candidate word chewing_cand_Enumerate(c); int index = 0; while (chewing_cand_hasNext(c)) { char* str = chewing_cand_String(c); FcitxCandidateWord cw; ChewingCandWord* w = (ChewingCandWord*) fcitx_utils_malloc0(sizeof(ChewingCandWord)); w->index = index; cw.callback = FcitxChewingGetCandWord; cw.owner = chewing; cw.priv = w; cw.strExtra = NULL; cw.strWord = strdup(str); cw.wordType = MSG_OTHER; FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &cw); chewing_free(str); index ++; } } // setup cursor FcitxInputStateSetShowCursor(input, true); int buf_len = chewing_buffer_Len(c); int cur = chewing_cursor_Current(c); FcitxLog(DEBUG, "buf len: %d, cur: %d", buf_len, cur); int rcur = FcitxChewingGetRawCursorPos(buf_str, cur); FcitxInputStateSetCursorPos(input, rcur); FcitxInputStateSetClientCursorPos(input, rcur); // insert zuin in the middle char * half1 = strndup(buf_str, rcur); char * half2 = strdup(buf_str + rcur); FcitxMessagesAddMessageAtLast(msgPreedit, MSG_INPUT, "%s%s%s", half1, zuin_str, half2); FcitxMessagesAddMessageAtLast(clientPreedit, MSG_INPUT, "%s%s%s", half1, zuin_str, half2); chewing_free(buf_str); chewing_free(zuin_str); free(half1); free(half2); return IRV_DISPLAY_CANDWORDS; }