Permalink
Browse files

test 코드에서 속편하게 wchar_t로 비교

wchar_t 내용이 UCS-4라고 가정해서는 안되지만, GCC를 사용하는 경우에
한해서 사용이 쉬우므로 이렇게 수정한다.


git-svn-id: http://kldp.net/svn/hangul/libhangul/trunk@265 8f00fcd2-89fc-0310-932e-b01be5b65e01
  • Loading branch information...
1 parent c2c8b0a commit dabd63b8de364fdf30acff5e4a3358709c20660c @choehwanjin committed Aug 28, 2011
Showing with 59 additions and 82 deletions.
  1. +2 −2 test/Makefile.am
  2. +57 −80 test/test.c
View
@@ -12,5 +12,5 @@ hanja_LDADD = ../hangul/libhangul.la $(LTLIBINTL)
TESTS = test
check_PROGRAMS = test
test_SOURCES = test.c ../hangul/hangul.h
-test_CFLAGS = @CHECK_CFLAGS@
-test_LDADD = @CHECK_LIBS@ $(top_builddir)/hangul/libhangul.la $(LTLIBINTL)
+test_CFLAGS = $(CHECK_CFLAGS)
+test_LDADD = $(CHECK_LIBS) $(top_builddir)/hangul/libhangul.la $(LTLIBINTL)
View
@@ -1,19 +1,19 @@
#include <stdarg.h>
#include <stdlib.h>
+#include <wchar.h>
#include <check.h>
#include "../hangul/hangul.h"
#define countof(x) ((sizeof(x)) / (sizeof(x[0])))
static bool
-check_preedit(const char* keyboard, const char* input, ...)
+check_preedit(const char* keyboard, const char* input, const wchar_t* output)
{
HangulInputContext* ic;
const char* p;
const ucschar* preedit;
- ucschar code;
- va_list ap;
+ int res;
ic = hangul_ic_new(keyboard);
@@ -25,32 +25,20 @@ check_preedit(const char* keyboard, const char* input, ...)
preedit = hangul_ic_get_preedit_string(ic);
- va_start(ap, input);
-
- code = va_arg(ap, ucschar);
- while (code != 0) {
- if (*preedit != code)
- return false;
-
- code = va_arg(ap, ucschar);
- preedit++;
- }
-
- va_end(ap);
+ res = wcscmp((const wchar_t*)preedit, output);
hangul_ic_delete(ic);
- return true;
+ return res == 0;
}
static bool
-check_commit(const char* keyboard, const char* input, ...)
+check_commit(const char* keyboard, const char* input, const wchar_t* output)
{
HangulInputContext* ic;
const char* p;
const ucschar* commit;
- ucschar code;
- va_list ap;
+ int res;
ic = hangul_ic_new(keyboard);
@@ -62,105 +50,94 @@ check_commit(const char* keyboard, const char* input, ...)
commit = hangul_ic_get_commit_string(ic);
- va_start(ap, input);
-
- code = va_arg(ap, ucschar);
- while (code != 0) {
- if (*commit != code)
- return false;
-
- code = va_arg(ap, ucschar);
- commit++;
- }
-
- va_end(ap);
+ res = wcscmp((const wchar_t*)commit, output);
hangul_ic_delete(ic);
- return true;
+ return res == 0;
}
START_TEST(test_hangul_ic_process_2)
{
/* ㄱㅏㅉ */
- fail_unless(check_commit("2", "rkW", 0xac00, 0));
- fail_unless(check_preedit("2", "rkW", 0x3149, 0));
+ fail_unless(check_commit("2", "rkW", L""));
+ fail_unless(check_preedit("2", "rkW", L""));
/* ㅂㅓㅅㅅㅡ */
- fail_unless(check_commit("2", "qjttm", 0xbc97, 0));
- fail_unless(check_preedit("2", "qjttm", 0xc2a4, 0));
+ fail_unless(check_commit("2", "qjttm", L""));
+ fail_unless(check_preedit("2", "qjttm", L""));
/* ㅂㅓㅆㅡ */
- fail_unless(check_commit("2", "qjTm", 0xbc84, 0));
- fail_unless(check_preedit("2", "qjTm", 0xc4f0, 0));
+ fail_unless(check_commit("2", "qjTm", L""));
+ fail_unless(check_preedit("2", "qjTm", L""));
/* ㅁㅏㄹㄱㅗ */
- fail_unless(check_preedit("2", "akfr", 0xb9d1, 0));
- fail_unless(check_commit("2", "akfrh", 0xb9d0, 0));
- fail_unless(check_preedit("2", "akfrh", 0xace0, 0));
+ fail_unless(check_preedit("2", "akfr", L""));
+ fail_unless(check_commit("2", "akfrh", L""));
+ fail_unless(check_preedit("2", "akfrh", L""));
}
END_TEST
START_TEST(test_hangul_ic_process_2y)
{
/**/
- fail_unless(check_preedit("2y", "g", 0x314e, 0));
+ fail_unless(check_preedit("2y", "g", L""));
/**/
- fail_unless(check_preedit("2y", "h", 0x3157, 0));
+ fail_unless(check_preedit("2y", "h", L""));
/**/
- fail_unless(check_preedit("2y", "x", 0x314c, 0));
+ fail_unless(check_preedit("2y", "x", L""));
/* ㅂㅇ */
- fail_unless(check_preedit("2y", "qd", 0x3178, 0));
+ fail_unless(check_preedit("2y", "qd", L"\x3178"));
/**/
- fail_unless(check_preedit("2y", "Z", 0x113c, 0x1160, 0));
+ fail_unless(check_preedit("2y", "Z", L"\x113c\x1160"));
/**/
- fail_unless(check_preedit("2y", "V", 0x1150, 0x1160, 0));
+ fail_unless(check_preedit("2y", "V", L"\x1150\x1160"));
/**/
- fail_unless(check_preedit("2y", "sg", 0x115d, 0x1160, 0));
+ fail_unless(check_preedit("2y", "sg", L"\x115d\x1160"));
/* ㄱㅏㅇ */
- fail_unless(check_preedit("2y", "rkd", 0xac15, 0));
+ fail_unless(check_preedit("2y", "rkd", L""));
/* ㄹㅐ */
- fail_unless(check_preedit("2y", "fo", 0xb798, 0));
+ fail_unless(check_preedit("2y", "fo", L""));
/* ㅎ. ㄴ */
- fail_unless(check_preedit("2y", "gKs", 0x1112, 0x119e, 0x11ab, 0));
+ fail_unless(check_preedit("2y", "gKs", L"\x1112\x119e\x11ab"));
/* ㅂㅂㅇㅏㅁㅅㅅ */
- fail_unless(check_preedit("2y", "qqdhatt", 0x112c, 0x1169, 0x11de, 0));
+ fail_unless(check_preedit("2y", "qqdhatt", L"\x112c\x1169\x11de"));
/* ㅂㅂㅇㅏㅁㅅㅅㅛ */
- fail_unless(check_commit("2y", "qqdhatty", 0x112c, 0x1169, 0x11dd, 0));
- fail_unless(check_preedit("2y", "qqdhatty", 0xc1fc, 0));
+ fail_unless(check_commit("2y", "qqdhatty", L"\x112c\x1169\x11dd"));
+ fail_unless(check_preedit("2y", "qqdhatty", L""));
/* ㅂㅂㅇㅏㅁㅆㅛ */
- fail_unless(check_commit("2y", "qqdhaTy", 0x112c, 0x1169, 0x11b7, 0));
- fail_unless(check_preedit("2y", "qqdhaTy", 0xc448, 0));
+ fail_unless(check_commit("2y", "qqdhaTy", L"\x112c\x1169\x11b7"));
+ fail_unless(check_preedit("2y", "qqdhaTy", L""));
/* 옛이응 처리 */
/* ㅇㅇㅏㅇㅇㅏ */
- fail_unless(check_commit("2y", "ddkdd", 0x1147, 0x1161, 0x11bc, 0));
- fail_unless(check_preedit("2y", "ddkdd", 0x3147, 0));
+ fail_unless(check_commit("2y", "ddkdd", L"\x1147\x1161\x11bc"));
+ fail_unless(check_preedit("2y", "ddkdd", L""));
/* ㄱㅏㆁㆁ */
- fail_unless(check_preedit("2y", "rkDD", 0x1100, 0x1161, 0x11ee, 0));
+ fail_unless(check_preedit("2y", "rkDD", L"\x1100\x1161\x11ee"));
/* ㄱㅏㆁㆁㅏ */
- fail_unless(check_commit("2y", "rkDDk", 0x1100, 0x1161, 0x11f0, 0));
- fail_unless(check_preedit("2y", "rkDDk", 0x114c, 0x1161, 0));
+ fail_unless(check_commit("2y", "rkDDk", L"\x1100\x1161\x11f0"));
+ fail_unless(check_preedit("2y", "rkDDk", L"\x114c\x1161"));
/* ㅏㅏㅏㅏ */
- fail_unless(check_preedit("2y", "kkkk", 0x115f, 0x11a2, 0));
+ fail_unless(check_preedit("2y", "kkkk", L"\x115f\x11a2"));
}
END_TEST
START_TEST(test_hangul_ic_process_3f)
{
/* L V T */
/**/
- fail_unless(check_preedit("3f", "m", 0x314e, 0));
+ fail_unless(check_preedit("3f", "m", L""));
/**/
- fail_unless(check_preedit("3f", "v", 0x3157, 0));
+ fail_unless(check_preedit("3f", "v", L""));
/**/
- fail_unless(check_preedit("3f", "W", 0x314c, 0));
+ fail_unless(check_preedit("3f", "W", L""));
/* ㄱㅏㅇ */
- fail_unless(check_preedit("3f", "kfa", 0xac15, 0));
+ fail_unless(check_preedit("3f", "kfa", L""));
/* ㄹㅐ */
- fail_unless(check_preedit("3f", "yr", 0xb798, 0));
+ fail_unless(check_preedit("3f", "yr", L""));
/* ㄴ ㅁ */
- fail_unless(check_preedit("3f", "hz", 0x1102, 0x1160, 0x11b7, 0));
+ fail_unless(check_preedit("3f", "hz", L"\x1102\x1160\x11b7"));
/* ㅜㅅ */
- fail_unless(check_preedit("3f", "tq", 0x115f, 0x1165, 0x11ba, 0));
+ fail_unless(check_preedit("3f", "tq", L"\x115f\x1165\x11ba"));
}
END_TEST
@@ -180,7 +157,7 @@ START_TEST(test_hangul_ic_process_romaja)
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
- fail_unless(preedit[0] == 0xd55c); //
+ fail_unless(preedit[0] == L'');
fail_unless(commit[0] == 0);
hangul_ic_reset(ic);
@@ -190,7 +167,7 @@ START_TEST(test_hangul_ic_process_romaja)
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
- fail_unless(preedit[0] == 0xc544); //
+ fail_unless(preedit[0] == L'');
fail_unless(commit[0] == 0);
// remove correctly when automatically ㅇ was inserted
@@ -208,7 +185,7 @@ START_TEST(test_hangul_ic_process_romaja)
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
fail_unless(preedit[0] == 0x314c); //
- fail_unless(commit[0] == 0xd2b8); //
+ fail_unless(commit[0] == L'');
// ng makes trailing ㅇ
hangul_ic_reset(ic);
@@ -219,16 +196,16 @@ START_TEST(test_hangul_ic_process_romaja)
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
- fail_unless(preedit[0] == 0xac15); //
+ fail_unless(preedit[0] == L''); //
fail_unless(commit[0] == 0);
// gangi makes 강이
hangul_ic_process(ic, 'i');
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
- fail_unless(preedit[0] == 0xc774); //
- fail_unless(commit[0] == 0xac15); //
+ fail_unless(preedit[0] == L'');
+ fail_unless(commit[0] == L''); //
// nanG makes 난ㄱ
// uppercase makes new syllable
@@ -240,7 +217,7 @@ START_TEST(test_hangul_ic_process_romaja)
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
fail_unless(preedit[0] == 0x3131); //
- fail_unless(commit[0] == 0xb09c); //
+ fail_unless(commit[0] == L''); //
// special operation for x
// x generate ㅈ for leading consonant
@@ -251,15 +228,15 @@ START_TEST(test_hangul_ic_process_romaja)
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
fail_unless(preedit[0] == 0x3148); //
- fail_unless(commit[0] == 0xc988);
+ fail_unless(commit[0] == L'');
hangul_ic_reset(ic);
hangul_ic_process(ic, 'x');
hangul_ic_process(ic, 'y');
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
- fail_unless(preedit[0] == 0xc9c0); //
+ fail_unless(preedit[0] == L''); //
fail_unless(commit[0] == 0x0);
// x generate ㄱㅅ for trailing consonant
@@ -273,8 +250,8 @@ START_TEST(test_hangul_ic_process_romaja)
preedit = hangul_ic_get_preedit_string(ic);
commit = hangul_ic_get_commit_string(ic);
- fail_unless(preedit[0] == 0xc2dc); //
- fail_unless(commit[0] == 0xc139); //
+ fail_unless(preedit[0] == L''); //
+ fail_unless(commit[0] == L''); //
hangul_ic_delete(ic);
}

0 comments on commit dabd63b

Please sign in to comment.