void test_in_fullshape_mode()
{
	ChewingContext *ctx;
	size_t i;


	ctx = chewing_new();

	chewing_set_maxChiSymbolLen( ctx, 16 );
	chewing_set_ChiEngMode( ctx, SYMBOL_MODE );
	chewing_set_ShapeMode( ctx, FULLSHAPE_MODE );

	for ( i = 0; i < ARRAY_SIZE( SPECIAL_SYMBOL_TABLE ); ++i ) {
		// If fullshape symbol is collided with special symbol, use
		// fullshape symbol
		if ( is_fullshape_collision_key( SPECIAL_SYMBOL_TABLE[i].token ) )
			continue;

		type_keystroke_by_string( ctx, SPECIAL_SYMBOL_TABLE[i].token );
		ok_preedit_buffer( ctx, "" );
		ok_commit_buffer( ctx, SPECIAL_SYMBOL_TABLE[i].expected );
	}

	chewing_delete( ctx );
}
Exemple #2
0
void test_Numlock_select_candidate()
{
    const TestData NUMLOCK_SELECT[] = {
        {"hk4<D><N1><E>", "\xE5\x86\x8A" /* 冊 */ },
        {"hk4<D><N2><E>", "\xE7\xAD\x96" /* 策 */ },
        {"hk4<D><N3><E>", "\xE6\xB8\xAC" /* 測 */ },
        {"hk4<D><N4><E>", "\xE5\x81\xB4" /* 側 */ },
        {"hk4<D><N5><E>", "\xE5\xBB\x81" /* 廁 */ },
        {"hk4<D><N6><E>", "\xE6\x83\xBB" /* 惻 */ },
        {"hk4<D><N7><E>", "\xE7\xAD\xB4" /* 筴 */ },
        {"hk4<D><N8><E>", "\xE7\x95\x9F" /* 畟 */ },
        {"hk4<D><N9><E>", "\xE8\x8C\xA6" /* 茦 */ },
        {"hk4<D><N0><E>", "\xE7\xB2\xA3" /* 粣 */ },
    };
    size_t i;
    ChewingContext *ctx;

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);

    for (i = 0; i < ARRAY_SIZE(NUMLOCK_SELECT); ++i) {
        type_keystroke_by_string(ctx, NUMLOCK_SELECT[i].token);
        ok_commit_buffer(ctx, NUMLOCK_SELECT[i].expected);
    }

    chewing_delete(ctx);
}
Exemple #3
0
void test_Tab_connect_word()
{
    ChewingContext *ctx;
    IntervalType it;

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);

    type_keystroke_by_string(ctx, "u -4<L>");
    chewing_interval_Enumerate(ctx);

    ok(chewing_interval_hasNext(ctx) == 1, "shall have next interval");
    chewing_interval_Get(ctx, &it);
    ok(it.from == 0 && it.to == 1, "interval (%d, %d) shall be (0, 1)", it.from, it.to);

    ok(chewing_interval_hasNext(ctx) == 1, "shall have next interval");
    chewing_interval_Get(ctx, &it);
    ok(it.from == 1 && it.to == 2, "interval (%d, %d) shall be (1, 2)", it.from, it.to);

    ok(chewing_interval_hasNext(ctx) == 0, "shall not have next interval");

    /* connect 一 and 二 */
    type_keystroke_by_string(ctx, "<T>");
    chewing_interval_Enumerate(ctx);

    ok(chewing_interval_hasNext(ctx) == 1, "shall have next interval");
    chewing_interval_Get(ctx, &it);
    ok(it.from == 0 && it.to == 2, "interval (%d, %d) shall be (0, 2)", it.from, it.to);

    ok(chewing_interval_hasNext(ctx) == 0, "shall not have next interval");

    chewing_delete(ctx);
}
void test_userphrase_auto_learn_hardcode_break()
{
	/* 的 is a hardcode break point, see ChewingIsBreakPoint */
	static const char phrase[] = "\xE7\x9A\x84\xE7\x9A\x84" /* 的的 */;
	static const char bopomofo[] = "\xE3\x84\x89\xE3\x84\x9C\xCB\x99 \xE3\x84\x89\xE3\x84\x9C\xCB\x99" /* ㄉㄜ˙ ㄉㄜ˙ */;
	ChewingContext *ctx;

	remove( TEST_HASH_DIR PLAT_SEPARATOR HASH_FILE );

	chewing_Init( NULL, NULL );

	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );
	chewing_set_addPhraseDirection( ctx, 1 );

	ok( has_userphrase( ctx, bopomofo, phrase ) == 0,
		"`%s' shall not be in userphrase", phrase );

	type_keystroke_by_string( ctx, "2k72k7<E>" );
	ok( has_userphrase( ctx, bopomofo, phrase ) == 0,
		"`%s' shall not be in userphrase", phrase );

	chewing_delete( ctx );
	chewing_Terminate();
}
void test_ShiftRight_add_userphrase()
{
	static const char phrase[] = "\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */;
	static const char bopomofo[] = "\xE3\x84\x98\xE3\x84\x9C\xCB\x8B \xE3\x84\x95\xCB\x8B" /* ㄘㄜˋ ㄕˋ */;
	int cursor;
	ChewingContext *ctx;

	remove( TEST_HASH_DIR PLAT_SEPARATOR HASH_FILE );

	chewing_Init( NULL, NULL );

	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );

	ok( has_userphrase( ctx, bopomofo, phrase ) == 0,
		"`%s' shall not be in userphrase", phrase );

	type_keystroke_by_string( ctx, "hk4g4<L><L><SR><SR><E>" );
	ok_preedit_buffer( ctx, phrase );
	cursor = chewing_cursor_Current( ctx );
	ok( cursor == 2, "cursor position `%d' shall be 2", cursor );
	ok( has_userphrase( ctx, bopomofo, phrase ) == 1,
		"`%s' shall be in userphrase", phrase );

	chewing_delete( ctx );
	chewing_Terminate();
}
void test_libchewing_googlecode_issue_472()
{
    /* FIXME: Add const cause gcc warning */
    static char *INPUT[] = {
        "<T>|&Wt<H>mrJY)G<C2>OqJ<H><H>Yl<R>p0<EE>QE[^<C1>k",
        "+F<C9>hQ$UIICMr!X8/9<C3>(N<T>yU2!-LUI<D>`CS<D>jShm9SF}<EN>[`QYu<C8>k",
        "hk4`2<D>jk",
        "hk4`j 0",
        "hk4<C0>j 0",
    };
    size_t i;
    ChewingContext *ctx;

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);
    chewing_set_autoShiftCur(ctx, 1);

    for (i = 0; i < ARRAY_SIZE(INPUT); ++i) {
        chewing_Reset(ctx);
        type_keystroke_by_string(ctx, INPUT[i]);
    }

    chewing_delete(ctx);
}
void test_CtrlNum_add_phrase_symbol_in_between()
{
	static const char bopomofo[] = "\xE3\x84\x98\xE3\x84\x9C\xCB\x8B \xE3\x84\x95\xCB\x8B" /* ㄘㄜˋ ㄕˋ */;
	int cursor;
	ChewingContext *ctx;

	remove( TEST_HASH_DIR PLAT_SEPARATOR HASH_FILE );

	chewing_Init( NULL, NULL );

	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );
        chewing_set_addPhraseDirection( ctx, 1 );

	ok( has_userphrase( ctx, bopomofo, NULL ) == 0,
		"`%s' shall not be in userphrase", bopomofo );

	type_keystroke_by_string( ctx, "hk4`1g4<C2>" );
	cursor = chewing_cursor_Current( ctx );
	ok( cursor == 3, "cursor position `%d' shall be 3", cursor );

	/*
	 * FIXME: Current buggy here. User phrase shall not be added when there
	 * is a symbol in between.
	 */
	/* ok( has_userphrase( ctx, bopomofo, NULL ) == 0,
		"`%s' shall not be in userphrase", bopomofo ); */

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #8
0
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();
}
Exemple #9
0
void test_select_candidate_4_bytes_utf8()
{
    ChewingContext *ctx;

    clean_userphrase();

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);
    chewing_set_phraseChoiceRearward(ctx, 1);
    chewing_set_autoShiftCur(ctx, 1);

    type_keystroke_by_string(ctx, "2k62k6");    /* ㄉㄜˊ ㄉㄜˊ */
    ok_preedit_buffer(ctx, "\xE5\xBE\x97\xE5\xBE\x97" /* 得得 */ );

    type_keystroke_by_string(ctx, "<H>");

    type_keystroke_by_string(ctx, "<D>8");
    ok_preedit_buffer(ctx, "\xF0\xA2\x94\xA8\xE5\xBE\x97" /* 𢔨得 */ );

    type_keystroke_by_string(ctx, "<D>8");

    ok_preedit_buffer(ctx, "\xF0\xA2\x94\xA8\xF0\xA2\x94\xA8" /* 𢔨𢔨 */ );

    chewing_delete(ctx);
}
MainWindow::MainWindow()
{
  this->_lblChewing = new QLabel();
  this->_lblCommit = new QLabel();
  this->_lblBuffer = new QLabel();
  this->_lblAux = new QLabel();
  this->_lblLine = new QLabel();

  chewing_Init("/usr/share/chewing", ".");
  this->_ct = chewing_new();
  chewing_set_candPerPage(this->_ct, 9);
  chewing_set_maxChiSymbolLen(this->_ct, 20);
  chewing_set_escCleanAllBuf(this->_ct, 1);

  QWidget* container = new QWidget;
  QVBoxLayout* layout = new QVBoxLayout();
  layout->addWidget(new QLabel("Chewing symbol in buffer"));
  layout->addWidget(this->_lblChewing);
  layout->addWidget(new QLabel("Preedit buffer"));
  layout->addWidget(this->_lblBuffer);
  layout->addWidget(new QLabel("Commit output"));
  layout->addWidget(this->_lblCommit);
  layout->addWidget(new QLabel("Aux buffer"));
  layout->addWidget(this->_lblAux);
  layout->addWidget(new QLabel("Final output"));
  layout->addWidget(this->_lblLine);
  container->setLayout(layout);
  this->setCentralWidget(container);
}
Exemple #11
0
void test_Numlock_numeric_input()
{
    const TestData NUMLOCK_INPUT[] = {
        {"<N0>", "0"},
        {"<N1>", "1"},
        {"<N2>", "2"},
        {"<N3>", "3"},
        {"<N4>", "4"},
        {"<N5>", "5"},
        {"<N6>", "6"},
        {"<N7>", "7"},
        {"<N8>", "8"},
        {"<N9>", "9"},
        {"<N+>", "+"},
        {"<N->", "-"},
        {"<N*>", "*"},
        {"<N/>", "/"},
        {"<N.>", "."},
    };
    size_t i;
    ChewingContext *ctx;

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);

    for (i = 0; i < ARRAY_SIZE(NUMLOCK_INPUT); ++i) {
        type_keystroke_by_string(ctx, NUMLOCK_INPUT[i].token);
        ok_commit_buffer(ctx, NUMLOCK_INPUT[i].expected);
    }

    chewing_delete(ctx);
}
void test_libchewing_googlecode_issue_473()
{
    /* FIXME: Add const cause gcc warning */
    static char *INPUT[] = {
        "t<N->_ M1<N+>H[Ls3<L><N1>PL+Z]4<C1>&(^H*H<TT>Sc<N->P]!|<CB>-<C6>S<H><N1><C0>U<B>d}P!f<EN><N.><C7>V!U!w|4-=S<C1>b<N2>Q",
        "wv<C0><C5><N9>$FIF<D><N4>B *<C2>E4*<C2>q)Kf)<SS><TT>4=<N5>%<R>mN4<EN>H<N9><N.>8s{XTD<N6>jZV(y3G`9<C6>JTy<B>J<C1>SNc<E>hC<SL><N/><R><C6>@an<C3><N7>wzF<C3>P*<N*><B>l<C3><N6>W<N*> $<SR><N.><N1><E><E><N0><N6>Y",
    };
    size_t i;
    ChewingContext *ctx;

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);
    chewing_set_autoShiftCur(ctx, 1);
    chewing_set_candPerPage(ctx, 9);
    chewing_set_addPhraseDirection(ctx, 1);
    chewing_set_spaceAsSelection(ctx, 1);

    for (i = 0; i < ARRAY_SIZE(INPUT); ++i) {
        chewing_Reset(ctx);
        type_keystroke_by_string(ctx, INPUT[i]);
    }

    chewing_delete(ctx);
}
Exemple #13
0
void test_select_candidate_4_bytes_utf8()
{
	ChewingContext *ctx;

	remove( TEST_HASH_DIR PLAT_SEPARATOR HASH_FILE );


	ctx = chewing_new();

	chewing_set_maxChiSymbolLen( ctx, 16 );
	chewing_set_phraseChoiceRearward( ctx, 1 );
	chewing_set_autoShiftCur( ctx, 1 );

	type_keystroke_by_string( ctx, "2k62k6" ); /* ㄉㄜˊ ㄉㄜˊ */
	ok_preedit_buffer( ctx, "\xE5\xBE\x97\xE5\xBE\x97" /* 得得 */ );

	type_keystroke_by_string( ctx, "<H>" );

	type_keystroke_by_string( ctx, "<D>8" );
	ok_preedit_buffer( ctx, "\xF0\xA2\x94\xA8\xE5\xBE\x97" /* 𢔨得 */ );

	type_keystroke_by_string( ctx, "<D>8" );

	ok_preedit_buffer( ctx, "\xF0\xA2\x94\xA8\xF0\xA2\x94\xA8" /* 𢔨𢔨 */ );

	chewing_delete( ctx );
}
Exemple #14
0
/**
 * @brief initialize the extra input method
 *
 * @param arg
 * @return successful or not
 **/
__EXPORT_API
void* FcitxChewingCreate(FcitxInstance* instance)
{
    if (GetFcitxChewingConfigDesc() == NULL)
        return NULL;
    
    char* user_path = NULL;
    FILE* fp = FcitxXDGGetFileUserWithPrefix("chewing", ".place_holder", "w", NULL);
    if (fp)
        fclose(fp);
    FcitxXDGGetFileUserWithPrefix("chewing", "", NULL, &user_path);
    FcitxLog(INFO, "Chewing storage path %s", user_path);
    if (0 == chewing_Init(CHEWING_DATADIR, user_path)) {
        FcitxLog(DEBUG, "chewing init ok");
    } else {
        FcitxLog(DEBUG, "chewing init failed");
        return NULL;
    }
    
    FcitxChewing* chewing = (FcitxChewing*) fcitx_utils_malloc0(sizeof(FcitxChewing));
    FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(instance);
    FcitxInputState *input = FcitxInstanceGetInputState(instance);
    FcitxCandidateWordSetChoose(FcitxInputStateGetCandidateList(input), DIGIT_STR_CHOOSE);
    
    bindtextdomain("fcitx-chewing", LOCALEDIR);

    chewing->context = chewing_new();
    ChewingContext * c = chewing->context;
    chewing->owner = instance;
    chewing_set_ChiEngMode(c, CHINESE_MODE);
    chewing_set_maxChiSymbolLen(c, 16);
    // chewing will crash without set page
    chewing_set_candPerPage(c, config->iMaxCandWord);
    FcitxCandidateWordSetPageSize(FcitxInputStateGetCandidateList(input), config->iMaxCandWord);
    chewing_set_selKey(c, selKey, 10);
    LoadChewingConfig(&chewing->config);
    ConfigChewing(chewing);

    FcitxInstanceRegisterIM(
        instance,
        chewing,
        "chewing",
        _("Chewing"),
        "chewing",
        FcitxChewingInit,
        FcitxChewingReset,
        FcitxChewingDoInput,
        FcitxChewingGetCandWords,
        NULL,
        NULL,
        FcitxChewingReloadConfig,
        NULL,
        1,
        "zh_TW"
    );
    return chewing;
}
/* Additional symbol buffer length */
gboolean maxChiSymbolLen_apply_callback(PropertyContext * ctx,
					gpointer userData)
{
    GValue *value = &(ctx->value);
    IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent;
    chewing_set_maxChiSymbolLen(icPreEdit->context,
				g_value_get_int(value));
    return TRUE;
}
Exemple #16
0
void test_set_maxChiSymbolLen()
{
	ChewingContext *ctx;
	int i;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	chewing_set_maxChiSymbolLen( ctx, 16 );
	ok( chewing_get_maxChiSymbolLen( ctx ) == 16,
		"maxChiSymbolLen shall be 16" );

	chewing_set_maxChiSymbolLen( ctx, MIN_CHI_SYMBOL_LEN - 1 );
	ok( chewing_get_maxChiSymbolLen( ctx ) == 16,
		"maxChiSymbolLen shall not change when set to %d",
		MIN_CHI_SYMBOL_LEN - 1 );

	chewing_set_maxChiSymbolLen( ctx, MAX_CHI_SYMBOL_LEN + 1 );
	ok( chewing_get_maxChiSymbolLen( ctx ) == 16,
		"maxChiSymbolLen shall not change when set to %d",
		MAX_CHI_SYMBOL_LEN + 1 );


	// Test auto commit
	chewing_set_maxChiSymbolLen( ctx, MAX_CHI_SYMBOL_LEN );

	// In boundary
	for ( i = 0; i < MAX_CHI_SYMBOL_LEN; ++i )
		type_keystroke_by_string( ctx, "hk4" );
	ok( chewing_commit_Check( ctx ) == 0,
		"auto commit shall not be triggered when entering %d symbols",
		MAX_CHI_SYMBOL_LEN );

	// Out of boundary
	type_keystroke_by_string( ctx, "hk4" );
	ok( chewing_commit_Check( ctx ) == 1,
		"auto commit shall be triggered when entering %d symbols",
		MAX_CHI_SYMBOL_LEN + 1);

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #17
0
Chewing::Chewing(  bool spaceAsSelection, int keyLayout ) {
    ctx = chewing_new();
    
	chewing_set_KBType( ctx, keyLayout );
	chewing_set_candPerPage( ctx, 9 );
	chewing_set_maxChiSymbolLen( ctx, 20 );
	//chewing_set_addPhraseDirection( ctx, 1 );
	//chewing_set_selKey( ctx, selKey_define, 10 );
	chewing_set_spaceAsSelection( ctx, spaceAsSelection );
}
Exemple #18
0
void test_Backspace_word()
{
    ChewingContext *ctx;

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);

    type_keystroke_by_string(ctx, "hk4u g4<L><B><E>");
    ok_commit_buffer(ctx, "\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */ );

    chewing_delete(ctx);
}
Exemple #19
0
CHEWING_API int chewing_Configure( ChewingContext *ctx, ChewingConfigData *pcd )
{
	chewing_set_candPerPage( ctx, pcd->candPerPage );
	chewing_set_maxChiSymbolLen( ctx, pcd->maxChiSymbolLen );
	chewing_set_selKey( ctx, pcd->selKey, MAX_SELKEY );
	chewing_set_addPhraseDirection( ctx, pcd->bAddPhraseForward );
	chewing_set_spaceAsSelection( ctx, pcd->bSpaceAsSelection );
	chewing_set_escCleanAllBuf( ctx, pcd->bEscCleanAllBuf );
	chewing_set_autoShiftCur( ctx, pcd->bAutoShiftCur );
	chewing_set_easySymbolInput( ctx, pcd->bEasySymbolInput );
	chewing_set_phraseChoiceRearward( ctx, pcd->bPhraseChoiceRearward );

	return 0;
}
Exemple #20
0
void test_auto_commit_symbol()
{
    ChewingContext *ctx;

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 2);

    type_keystroke_by_string(ctx, "`31hk4g4" /* ,測試 */ );
    ok_preedit_buffer(ctx, "\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */ );
    ok_commit_buffer(ctx, "\xEF\xBC\x8C" /* , */ );

    chewing_delete(ctx);
}
void test_libchewing_data_issue_1()
{
    const TestData DATA = { "e03y.3", "\xE8\xB6\x95\xE8\xB5\xB0" /* 趕走 */  };
    ChewingContext *ctx;

    clean_userphrase();

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);
    type_keystroke_by_string(ctx, DATA.token);
    ok_preedit_buffer(ctx, DATA.expected);

    chewing_delete(ctx);
}
Exemple #22
0
int main(int argc, char *argv[])
{
    ChewingContext *ctx;
    int i;
    FILE *fp = stdin;

    /* Initialize libchewing */
    putenv("CHEWING_PATH=" CHEWING_DATA_PREFIX);
    /* for the sake of testing, we should not change existing hash data */
    putenv("CHEWING_USER_PATH=" TEST_HASH_DIR);

    if (argc == 2) {
        fp = fopen(argv[1], "r");
        if (!fp) {
            fprintf(stderr, "failed to open '%s'\n", argv[1]);
            return 1;
        }
    }

    /* Request handle to ChewingContext */
    ctx = chewing_new();

    /* Set keyboard type */
    chewing_set_KBType(ctx, chewing_KBStr2Num("KB_DEFAULT"));

    chewing_set_candPerPage(ctx, 9);
    chewing_set_maxChiSymbolLen(ctx, 16);
    chewing_set_addPhraseDirection(ctx, 1);
    chewing_set_selKey(ctx, selKey_define, 10);
    chewing_set_spaceAsSelection(ctx, 1);

    while (1) {
        i = get_keystroke(get_char_from_fp, fp);
        if (i == END)
            goto end;
        type_single_keystroke(ctx, i);
        commit_string(ctx);
    }
  end:
    /* Free Chewing IM handle */
    chewing_delete(ctx);
    if (fp)
        fclose(fp);

    return 0;
}
Exemple #23
0
void test_type_easy_symbol()
{
	chewing_Init( NULL, NULL );

	ChewingContext *ctx = chewing_new();
	ok( ctx, "chewing_new shall not return NULL" );

	chewing_set_maxChiSymbolLen( ctx, 16 );
	chewing_set_easySymbolInput( ctx, 1 );

	for ( int i = 0; i < ARRAY_SIZE( EASY_SYMBOL ); ++i ) {
		type_keystoke_by_string( ctx, EASY_SYMBOL[i].token );
		ok_commit_buffer( ctx, EASY_SYMBOL[i].expected );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #24
0
void test_PageDown_not_entering_chewing()
{
    ChewingContext *ctx;
    int cursor;

    ctx = chewing_new();
    start_testcase(ctx, fd);
    chewing_set_maxChiSymbolLen(ctx, 16);

    type_keystroke_by_string(ctx, "hk4g4<L><L>");
    cursor = chewing_cursor_Current(ctx);
    ok(cursor == 0, "cursor `%d' shall be 0", cursor);

    type_keystroke_by_string(ctx, "<PD>");
    cursor = chewing_cursor_Current(ctx);
    ok(cursor == 2, "cursor `%d' shall be 2", cursor);

    chewing_delete(ctx);
}
Exemple #25
0
void test_End()
{
	ChewingContext *ctx;
	int cursor;


	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );

	type_keystroke_by_string( ctx, "hk4g4<L><L>" );
	cursor = chewing_cursor_Current( ctx );
	ok( cursor == 0, "cursor `%d' shall be 0", cursor );

	type_keystroke_by_string( ctx, "<EN>" );
	cursor = chewing_cursor_Current( ctx );
	ok( cursor == 2, "cursor `%d' shall be 2", cursor );

	chewing_delete( ctx );
}
Exemple #26
0
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);
}
Exemple #27
0
void test_select_candidate_rearward()
{
    /*
     * The following phrases are in dict
     * 一上來
     * 上來
     * 移上來
     * 移上
     */

    static const char *CAND_1[] = {
        "\xE4\xB8\x80\xE4\xB8\x8A\xE4\xBE\x86" /* 一上來 */ ,
        "\xE7\xA7\xBB\xE4\xB8\x8A\xE4\xBE\x86" /* 移上來 */ ,
    };

    static const char *CAND_2[] = {
        "\xE4\xB8\x8A\xE4\xBE\x86" /* 上來 */ ,
    };
    ChewingContext *ctx;

    clean_userphrase();

    ctx = chewing_new();
    start_testcase(ctx, fd);

    chewing_set_maxChiSymbolLen(ctx, 16);
    chewing_set_phraseChoiceRearward(ctx, 1);

    type_keystroke_by_string(ctx, "u6g;4x96");  /* ㄧˊㄕㄤˋㄌㄞˊ */
    ok_preedit_buffer(ctx, CAND_1[0]);

    type_keystroke_by_string(ctx, "<D>");       /* ㄧˊㄕㄤˋㄌㄞˊ */
    ok_candidate(ctx, CAND_1, ARRAY_SIZE(CAND_1));

    type_keystroke_by_string(ctx, "<D>");       /* ㄕㄤˋㄌㄞˊ */
    ok_candidate(ctx, CAND_2, ARRAY_SIZE(CAND_2));

    type_keystroke_by_string(ctx, "<D><D>2<E>");        /* select 移上來 */
    ok_commit_buffer(ctx, CAND_1[1]);

    chewing_delete(ctx);
}
void test_in_easy_symbol_mode()
{
	ChewingContext *ctx;
	size_t i;


	ctx = chewing_new();

	chewing_set_maxChiSymbolLen( ctx, 16 );
	chewing_set_easySymbolInput( ctx, 1 );

	for ( i = 0; i < ARRAY_SIZE( SPECIAL_SYMBOL_TABLE ); ++i ) {
		type_keystroke_by_string( ctx, SPECIAL_SYMBOL_TABLE[i].token );
		ok_preedit_buffer( ctx, SPECIAL_SYMBOL_TABLE[i].expected );
		type_keystroke_by_string( ctx, "<E>" );
		ok_commit_buffer( ctx, SPECIAL_SYMBOL_TABLE[i].expected );
	}

	chewing_delete( ctx );
}
Exemple #29
0
void test_symbol_cand_page()
{
	ChewingContext *ctx;

	chewing_Init( NULL, NULL );

	ctx = chewing_new();

	chewing_set_candPerPage( ctx, 10 );
	chewing_set_maxChiSymbolLen( ctx, 16 );

	chewing_handle_Default( ctx, '`' );
	ok( chewing_cand_CurrentPage( ctx ) == 0, "current page shall be 0" );
	ok( chewing_cand_TotalPage( ctx ) == 2, "total page shall be 2" );

	ok_candidate( ctx, CAND, ARRAY_SIZE( CAND ) );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #30
0
void test_Numlock_select_candidate()
{
	const TestData NUMLOCK_SELECT[] = {
		{ "hk4<D><N3><E>", "\xE6\xB8\xAC" /* 測 */ },
		{ "`<N1><E>", "\xE2\x80\xA6" /* … */ },
	};
	size_t i;
	ChewingContext *ctx;


	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );

	for ( i = 0; i < ARRAY_SIZE( NUMLOCK_SELECT ); ++i ) {
		type_keystroke_by_string( ctx, NUMLOCK_SELECT[ i ].token );
		ok_commit_buffer( ctx, NUMLOCK_SELECT[i].expected );
	}

	chewing_delete( ctx );
}