示例#1
0
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);
}
示例#2
0
void test_Backspace_in_select()
{
    ChewingContext *ctx;
    int ret;

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

    type_keystroke_by_string(ctx, "`<B>");
    ok_candidate(ctx, NULL, 0);

    type_keystroke_by_string(ctx, "hk4");
    ret = chewing_cand_TotalChoice(ctx);
    ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be `%d'", ret, 0);

    type_keystroke_by_string(ctx, "<D>");
    ret = chewing_cand_TotalChoice(ctx);
    ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);

    type_keystroke_by_string(ctx, "<B>");
    ret = chewing_cand_TotalChoice(ctx);
    ok(ret == 0, "chewing_cand_TotalChoice() returns `%d' shall be `%d'", ret, 0);

    chewing_delete(ctx);
}
示例#3
0
void test_Capslock()
{
    ChewingContext *ctx;
    int mode;

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

    mode = chewing_get_ChiEngMode(ctx);
    ok(mode == CHINESE_MODE, "mode shall be CHINESE_MODE");

    type_keystroke_by_string(ctx, "ji");        /* ㄨㄛ */
    ok_bopomofo_buffer(ctx, "\xe3\x84\xa8\xe3\x84\x9b" /* ㄨㄛ */ );
    ok_preedit_buffer(ctx, "");
    ok_commit_buffer(ctx, "");

    type_keystroke_by_string(ctx, "<CB>");

    mode = chewing_get_ChiEngMode(ctx);
    ok(mode == SYMBOL_MODE, "mode shall change to SYMBOL_MODE");

    ok_bopomofo_buffer(ctx, "");
    ok_preedit_buffer(ctx, "");
    ok_commit_buffer(ctx, "");

    chewing_delete(ctx);
}
示例#4
0
void test_jk_selection()
{
#if 0
FIXME: libchewing is broken in this case
    ChewingContext *ctx;
    int ret;
    int i;
    const int EXPECT_CAND_LEN[] = { 1, 2, 1, 1, 2, 1, 1 };

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

    type_keystroke_by_string(ctx, "`31hk4g4`31hk4g4`31" /* ,測試,測試, */ );

    ret = chewing_cand_open(ctx);
    ok(ret == 0, "chewing_cand_open() returns `%d' shall be `%d'", ret, 0);

    for (i = ARRAY_SIZE(EXPECT_CAND_LEN) - 1; i >= 0; --i) {
        ret = chewing_cand_TotalChoice(ctx);
        ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
        ok_candidate_len(ctx, EXPECT_CAND_LEN[i]);
        type_keystroke_by_string(ctx, "j");
    }

    for (i = 0; i < ARRAY_SIZE(EXPECT_CAND_LEN); ++i) {
        ret = chewing_cand_TotalChoice(ctx);
        ok(ret > 0, "chewing_cand_TotalChoice() returns `%d' shall be greater than `%d'", ret, 0);
        ok_candidate_len(ctx, EXPECT_CAND_LEN[i]);
        type_keystroke_by_string(ctx, "i");
    }
    chewing_delete(ctx);
#endif
}
示例#5
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);
}
示例#6
0
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);
}
示例#7
0
void test_bopomofo_buffer()
{
    ChewingContext *ctx;

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

    type_keystroke_by_string(ctx, "1ul");
    ok_bopomofo_buffer(ctx, "\xE3\x84\x85\xE3\x84\xA7\xE3\x84\xA0" /* ㄅㄧㄠ */ );

    type_keystroke_by_string(ctx, " ");
    ok_bopomofo_buffer(ctx, "");

    type_keystroke_by_string(ctx, "ul");
    ok_bopomofo_buffer(ctx, "\xE3\x84\xA7\xE3\x84\xA0" /* ㄧㄠ */ );

    type_keystroke_by_string(ctx, " ");
    ok_bopomofo_buffer(ctx, "");

    type_keystroke_by_string(ctx, "3");
    ok_bopomofo_buffer(ctx, "\xCB\x87" /* ˇ */ );

    type_keystroke_by_string(ctx, " ");
    ok_bopomofo_buffer(ctx, "");

    chewing_delete(ctx);
}
示例#8
0
void test_set_spaceAsSelection()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_spaceAsSelection( ctx, value );
		mode = chewing_get_spaceAsSelection( ctx );
		ok( mode == value,
			"spaceAsSelection `%d' shall be `%d'", mode, value );

		chewing_set_spaceAsSelection( ctx, -1 );
		mode = chewing_get_spaceAsSelection( ctx );
		ok( mode == value,
			"spaceAsSelection `%d' shall be `%d'", mode, value );

		chewing_set_spaceAsSelection( ctx, 2 );
		mode = chewing_get_spaceAsSelection( ctx );
		ok( mode == value,
			"spaceAsSelection `%d' shall be `%d'", mode, value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
示例#9
0
void test_set_escCleanAllBuf()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_escCleanAllBuf( ctx, value );
		mode = chewing_get_escCleanAllBuf( ctx );
		ok( mode == value,
			"escCleanAllBuf shall be `%d'", value );

		chewing_set_escCleanAllBuf( ctx, -1 );
		mode = chewing_get_escCleanAllBuf( ctx );
		ok( mode == value,
			"escCleanAllBuf shall be `%d'", value );

		chewing_set_escCleanAllBuf( ctx, 2 );
		mode = chewing_get_escCleanAllBuf( ctx );
		ok( mode == value,
			"escCleanAllBuf shall be `%d'", value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
示例#10
0
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);
}
示例#11
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();
}
示例#12
0
void test_set_candPerPage()
{
	const int VALUE[] = {
		MIN_CAND_PER_PAGE,
		MAX_CAND_PER_PAGE,
	};

	const int INVALID_VALUE[] = {
		MIN_CAND_PER_PAGE - 1,
		MAX_CAND_PER_PAGE + 1,
	};

	ChewingContext *ctx;
	size_t i;
	size_t j;

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

	for ( i = 0; i < ARRAY_SIZE( VALUE ); ++i ) {
		chewing_set_candPerPage( ctx, VALUE[i] );
		ok( chewing_get_candPerPage( ctx ) == VALUE[i],
			"candPerPage shall be `%d'", VALUE[i] );

		for ( j = 0; j < ARRAY_SIZE( INVALID_VALUE ); ++j ) {
			// mode shall not change when set mode has invalid value.
			chewing_set_candPerPage( ctx, INVALID_VALUE[j] );
			ok( chewing_get_candPerPage( ctx ) == VALUE[i],
				"candPerPage shall be `%d'", VALUE[i] );
		}
	}

	chewing_delete( ctx );
}
示例#13
0
void test_set_ShapeMode()
{
	const int VALUE[] = {
		HALFSHAPE_MODE,
		FULLSHAPE_MODE,
	};

	const int INVALID_VALUE[] = {
		-1,
		2,
	};

	ChewingContext *ctx;
	size_t i;
	size_t j;

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

	for ( i = 0; i < ARRAY_SIZE( VALUE ); ++i ) {
		chewing_set_ShapeMode( ctx, VALUE[i] );
		ok( chewing_get_ShapeMode( ctx ) == VALUE[i],
			"ShapeMode shall be `%d'", VALUE[i] );

		for ( j = 0; j < ARRAY_SIZE( INVALID_VALUE ); ++j ) {
			// mode shall not change when set mode has invalid value.
			chewing_set_ShapeMode( ctx, INVALID_VALUE[j] );
			ok( chewing_get_ShapeMode( ctx ) == VALUE[i],
				"ShapeMode shall be `%d'", VALUE[i] );
		}
	}

	chewing_delete( ctx );
}
示例#14
0
void test_set_addPhraseDirection()
{
	ChewingContext *ctx;
	int value;
	int mode;

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

	for ( value = 0; value < 2; ++value ) {
		chewing_set_addPhraseDirection( ctx, value );
		mode = chewing_get_addPhraseDirection( ctx );
		ok( mode == value,
			"addPhraseDirection `%d' shall be `%d'", mode, value );

		chewing_set_addPhraseDirection( ctx, -1 );
		mode = chewing_get_addPhraseDirection( ctx );
		ok( mode == value,
			"addPhraseDirection `%d' shall be `%d'", mode, value );

		chewing_set_addPhraseDirection( ctx, 2 );
		mode = chewing_get_addPhraseDirection( ctx );
		ok( mode == value,
			"addPhraseDirection `%d' shall be `%d'", mode, value );
	}

	chewing_delete( ctx );
}
示例#15
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);
}
示例#16
0
void test_set_autoShiftCur()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_autoShiftCur( ctx, value );
		mode = chewing_get_autoShiftCur( ctx );
		ok( mode = chewing_get_autoShiftCur( ctx ) == value,
			"autoShiftCur shall be `%d'", value );

		chewing_set_autoShiftCur( ctx, -1 );
		mode = chewing_get_autoShiftCur( ctx );
		ok( mode = chewing_get_autoShiftCur( ctx ) == value,
			"autoShiftCur shall be `%d'", value );

		chewing_set_autoShiftCur( ctx, 2 );
		mode = chewing_get_autoShiftCur( ctx );
		ok( mode = chewing_get_autoShiftCur( ctx ) == value,
			"autoShiftCur shall be `%d'", value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
示例#17
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);
}
示例#18
0
void test_set_easySymbolInput()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_easySymbolInput( ctx, value );
		mode = chewing_get_easySymbolInput( ctx );
		ok( mode == value,
			"easySymbolInput `%d', shall be `%d'", mode, value );

		chewing_set_easySymbolInput( ctx, -1 );
		mode = chewing_get_easySymbolInput( ctx );
		ok( mode == value,
			"easySymbolInput `%d', shall be `%d'", mode, value );

		chewing_set_easySymbolInput( ctx, 2 );
		mode = chewing_get_easySymbolInput( ctx );
		ok( mode == value,
			"easySymbolInput `%d', shall be `%d'", mode, value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
示例#19
0
void test_Space_selection_symbol()
{
    const char CAND_1[] = "\xE2\x80\xA6" /* … */ ;
    const char CAND_2[] = "\xE9\x9B\x99\xE7\xB7\x9A\xE6\xA1\x86" /* 雙線框 */ ;

    ChewingContext *ctx;
    const char *const_buf;

    clean_userphrase();

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

    type_keystroke_by_string(ctx, "`");
    chewing_cand_Enumerate(ctx);
    const_buf = chewing_cand_String_static(ctx);
    ok(strcmp(const_buf, CAND_1) == 0, "first candidate list head `%s' shall be `%s'", const_buf, CAND_1);

    type_keystroke_by_string(ctx, " ");
    chewing_cand_Enumerate(ctx);
    const_buf = chewing_cand_String_static(ctx);
    ok(strcmp(const_buf, CAND_2) == 0, "second candidate list head `%s' shall be `%s'", const_buf, CAND_2);

    /* rollover */
    type_keystroke_by_string(ctx, " ");
    chewing_cand_Enumerate(ctx);
    const_buf = chewing_cand_String_static(ctx);
    ok(strcmp(const_buf, CAND_1) == 0, "first candidate list head `%s' shall be `%s'", const_buf, CAND_1);

    chewing_delete(ctx);
}
示例#20
0
void test_set_phraseChoiceRearward()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_phraseChoiceRearward( ctx, value );
		mode = chewing_get_phraseChoiceRearward( ctx );
		ok(  mode == value,
			"phraseChoiceRearward `%d' shall be `%d'", mode, value );

		chewing_set_phraseChoiceRearward( ctx, -1 );
		mode = chewing_get_phraseChoiceRearward( ctx );
		ok(  mode == value,
			"phraseChoiceRearward `%d' shall be `%d'", mode, value );

		chewing_set_phraseChoiceRearward( ctx, 2 );
		mode = chewing_get_phraseChoiceRearward( ctx );
		ok(  mode == value,
			"phraseChoiceRearward `%d' shall be `%d'", mode, value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
示例#21
0
void test_interval()
{
    ChewingContext *ctx;
    IntervalType it;

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

    type_keystroke_by_string(ctx, "`31hk4g4`31hk4g4`31" /* ,測試,測試, */ );

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

    chewing_interval_Enumerate(ctx);

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

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

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

    chewing_delete(ctx);
}
示例#22
0
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();
}
示例#23
0
void test_del_bopomofo_as_mode_switch()
{
    ChewingContext *ctx;

    clean_userphrase();

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

    type_keystroke_by_string(ctx, "2k");        /* ㄉㄜ */
    ok_bopomofo_buffer(ctx, "\xe3\x84\x89\xe3\x84\x9c" /* ㄉㄜ */ );
    ok_preedit_buffer(ctx, "");
    chewing_set_ChiEngMode(ctx, SYMBOL_MODE);
    ok_bopomofo_buffer(ctx, "");
    ok_preedit_buffer(ctx, "");

    chewing_set_ChiEngMode(ctx, CHINESE_MODE);

    type_keystroke_by_string(ctx, "ji");        /* ㄨㄛ */
    ok_bopomofo_buffer(ctx, "\xe3\x84\xa8\xe3\x84\x9b" /* ㄨㄛ */ );
    ok_preedit_buffer(ctx, "");
    chewing_set_ChiEngMode(ctx, SYMBOL_MODE);
    ok_bopomofo_buffer(ctx, "");
    ok_preedit_buffer(ctx, "");

    chewing_delete(ctx);
}
示例#24
0
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();
}
示例#25
0
void test_select_candidate_in_middle_reaward()
{
    ChewingContext *ctx;
    int ret;
    const char *cand;

    clean_userphrase();

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

    type_keystroke_by_string(ctx, "hk4g4u6<L><L>" /* 測試儀*/);

    ret = chewing_cand_open(ctx);
    ok(ret == 0, "chewing_cand_open return %d shall be %d", ret, 0);

    cand = chewing_cand_string_by_index_static(ctx, 0);
    ok(strcmp(cand, "\xE6\xB8\xAC\xE8\xA9\xA6") == 0, "first candidate `%s' shall be `%s'", cand, "\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */);

    ret = chewing_cand_list_next(ctx);
    ok(ret == 0, "chewing_cand_list_next return %d shall be %d", ret, 0);

    cand = chewing_cand_string_by_index_static(ctx, 0);
    ok(strcmp(cand, "\xE5\xB8\x82") == 0, "first candidate `%s' shall be `%s'", cand, "\xE5\xB8\x82" /* 市 */);

    chewing_delete(ctx);
}
示例#26
0
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();
}
示例#27
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);
}
示例#28
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 );
}
示例#29
0
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 );
}
示例#30
0
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);
}