diff options
author | Choe Hwanjin <choe.hwanjin@gmail.com> | 2016-02-21 21:34:28 +0900 |
---|---|---|
committer | Choe Hwanjin <choe.hwanjin@gmail.com> | 2016-02-21 21:39:18 +0900 |
commit | 3cc99981949155e27e6e0db8a26a4c48a79d5e4f (patch) | |
tree | 6d3c4402ff1a8119524d768084ade5c643f6256a /test | |
parent | 5735a1a6e3892a42e1a15475d395493c890b2995 (diff) | |
download | libhangul-3cc99981949155e27e6e0db8a26a4c48a79d5e4f.tar.gz |
input context 입력 옵션 설정 기능 추가: auto reorder
hangul_ic_set_option 함수를 통해서 입력 옵션 설정이 가능하다.
처음에는 filter 함수를 이용해서 라이브러리 외부에서 좀더 유연하게
조종할 수 있도록 하려 했었는데, 옵션을 만드는 쪽이 구현과 사용이 더
쉬울 것 같아서 옵션으로 추가한다.
첫번째 구현으로 auto reorder 옵션을 추가하고, 관련 테스트 코드도
추가한다. 기본값은 MS IME 호환을 위해서 false로 설정한다.
Diffstat (limited to 'test')
-rw-r--r-- | test/test.c | 79 |
1 files changed, 69 insertions, 10 deletions
diff --git a/test/test.c b/test/test.c index 1c8ad57..982e58b 100644 --- a/test/test.c +++ b/test/test.c @@ -8,15 +8,12 @@ #define countof(x) ((sizeof(x)) / (sizeof(x[0]))) static bool -check_preedit(const char* keyboard, const char* input, const wchar_t* output) +check_preedit_with_ic(HangulInputContext* ic, const char* input, const wchar_t* output) { - HangulInputContext* ic; const char* p; const ucschar* preedit; int res; - ic = hangul_ic_new(keyboard); - p = input; while (*p != '\0') { hangul_ic_process(ic, *p); @@ -27,21 +24,31 @@ check_preedit(const char* keyboard, const char* input, const wchar_t* output) res = wcscmp((const wchar_t*)preedit, output); - hangul_ic_delete(ic); - return res == 0; } static bool -check_commit(const char* keyboard, const char* input, const wchar_t* output) +check_preedit(const char* keyboard, const char* input, const wchar_t* output) { HangulInputContext* ic; - const char* p; - const ucschar* commit; int res; ic = hangul_ic_new(keyboard); + res = check_preedit_with_ic(ic, input, output);; + + hangul_ic_delete(ic); + + return res; +} + +static bool +check_commit_with_ic(HangulInputContext* ic, const char* input, const wchar_t* output) +{ + const char* p; + const ucschar* commit; + int res; + p = input; while (*p != '\0') { hangul_ic_process(ic, *p); @@ -52,9 +59,22 @@ check_commit(const char* keyboard, const char* input, const wchar_t* output) res = wcscmp((const wchar_t*)commit, output); + return res == 0; +} + +static bool +check_commit(const char* keyboard, const char* input, const wchar_t* output) +{ + HangulInputContext* ic; + int res; + + ic = hangul_ic_new(keyboard); + + res = check_commit_with_ic(ic, input, output); + hangul_ic_delete(ic); - return res == 0; + return res; } START_TEST(test_hangul_ic_process_2) @@ -271,6 +291,44 @@ START_TEST(test_hangul_ic_process_romaja) } END_TEST +START_TEST(test_hangul_ic_auto_reorder) +{ + HangulInputContext* ic = hangul_ic_new("2"); + + hangul_ic_set_option(ic, HANGUL_IC_OPTION_AUTO_REORDER, true); + hangul_ic_reset(ic); + fail_unless(check_preedit_with_ic(ic, "rk", L"가")); + hangul_ic_reset(ic); + fail_unless(check_preedit_with_ic(ic, "kr", L"가")); + + hangul_ic_set_option(ic, HANGUL_IC_OPTION_AUTO_REORDER, false); + hangul_ic_reset(ic); + fail_unless(check_preedit_with_ic(ic, "rk", L"가")); + hangul_ic_reset(ic); + fail_unless(check_commit_with_ic(ic, "kr", L"ㅏ")); + hangul_ic_reset(ic); + fail_unless(check_preedit_with_ic(ic, "kr", L"ㄱ")); + + hangul_ic_select_keyboard(ic, "3f"); + + hangul_ic_set_option(ic, HANGUL_IC_OPTION_AUTO_REORDER, true); + hangul_ic_reset(ic); + fail_unless(check_preedit_with_ic(ic, "kf", L"가")); + hangul_ic_reset(ic); + fail_unless(check_preedit_with_ic(ic, "fk", L"가")); + + hangul_ic_set_option(ic, HANGUL_IC_OPTION_AUTO_REORDER, false); + hangul_ic_reset(ic); + fail_unless(check_preedit_with_ic(ic, "kf", L"가")); + hangul_ic_reset(ic); + fail_unless(check_commit_with_ic(ic, "fk", L"ㅏ")); + hangul_ic_reset(ic); + fail_unless(check_preedit_with_ic(ic, "fk", L"ㄱ")); + + hangul_ic_delete(ic); +} +END_TEST + START_TEST(test_syllable_iterator) { ucschar str[] = { @@ -432,6 +490,7 @@ Suite* libhangul_suite() tcase_add_test(hangul, test_hangul_ic_process_2y); tcase_add_test(hangul, test_hangul_ic_process_3f); tcase_add_test(hangul, test_hangul_ic_process_romaja); + tcase_add_test(hangul, test_hangul_ic_auto_reorder); tcase_add_test(hangul, test_syllable_iterator); tcase_add_test(hangul, test_hangul_keyboard); tcase_add_test(hangul, test_hangul_jamo_to_cjamo); |