summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChoe Hwanjin <choe.hwanjin@gmail.com>2008-12-20 20:56:45 +0900
committerChoe Hwanjin <choe.hwanjin@gmail.com>2008-12-20 20:56:45 +0900
commit76a37cd2463ea085f55bab9777fe6201bddb49b1 (patch)
tree4426a75553accbb74a6a476ffc51da0be8de15bf
parentfa3b58f093b444d9f0fef7afa7934a41ae95a7cd (diff)
downloadlibhangul-76a37cd2463ea085f55bab9777fe6201bddb49b1.tar.gz
unit test 코드 적용:
* check 라이브러리를 이용하여 구현 * check 라이브러리가 없어도 libhangul을 빌드하는 데는 문제 없게 설정 * 시범삼아 syllable iterator 코드의 테스트 코드 작성 git-svn-id: http://kldp.net/svn/hangul/libhangul/trunk@190 8f00fcd2-89fc-0310-932e-b01be5b65e01
-rw-r--r--configure.ac5
-rw-r--r--test/Makefile.am6
-rw-r--r--test/test.c144
3 files changed, 155 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index d5f70a4..6f8770e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,11 @@ AC_FUNC_REALLOC
AC_CHECK_FUNCS([munmap])
AC_CHECK_FUNCS([strcasecmp])
+# Checks for unit test framework
+PKG_PROG_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+ PKG_CHECK_EXISTS(check, [ PKG_CHECK_MODULES([CHECK], [check]) ])
+fi
AC_CONFIG_FILES([
Makefile
diff --git a/test/Makefile.am b/test/Makefile.am
index 25aebd5..e53aa22 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,3 +8,9 @@ hangul_LDADD = ../hangul/libhangul.la
hanja_CFLAGS =
hanja_SOURCES = hanja.c
hanja_LDADD = ../hangul/libhangul.la
+
+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
diff --git a/test/test.c b/test/test.c
new file mode 100644
index 0000000..788231d
--- /dev/null
+++ b/test/test.c
@@ -0,0 +1,144 @@
+#include <stdlib.h>
+#include <check.h>
+
+#include "../hangul/hangul.h"
+
+#define countof(x) ((sizeof(x)) / (sizeof(x[0])))
+
+START_TEST(test_syllable_iterator)
+{
+ ucschar str[] = {
+ // L L V V T T
+ 0x1107, 0x1107, 0x116e, 0x1166, 0x11af, 0x11a8, // 0
+ // L V T
+ 0x1108, 0x1170, 0x11b0, // 6
+ // L L V V T T M
+ 0x1107, 0x1107, 0x116e, 0x1166, 0x11af, 0x11a8, 0x302E, // 9
+ // L V T M
+ 0x1108, 0x1170, 0x11b0, 0x302F, // 16
+ // Lf V
+ 0x115f, 0x1161, // 20
+ // L Vf
+ 0x110c, 0x1160, // 22
+ // L LVT T
+ 0x1107, 0xbc14, 0x11a8, // 24
+ // L LV T
+ 0x1100, 0xac00, 0x11a8, // 27
+ // LVT
+ 0xc00d, // 30
+ // other
+ 'a', // 31
+ 0 // 32
+ };
+
+ const ucschar* begin = str;
+ const ucschar* end = str + countof(str) - 1;
+ const ucschar* s = str;
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 6,
+ "error: next syllable: L L V V T T");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 9,
+ "error: next syllable: L V T");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 16,
+ "error: next syllable: L L V V T T M");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 20,
+ "error: next syllable: L V T M");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 22,
+ "error: next syllable: Lf V");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 24,
+ "error: next syllable: L Vf");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 27,
+ "error: next syllable: L LVT T");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 30,
+ "error: next syllable: L LV T");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 31,
+ "error: next syllable: LVT");
+
+ s = hangul_syllable_iterator_next(s, end);
+ fail_unless(s - str == 32,
+ "error: next syllable: other");
+
+ s = end;
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 31,
+ "error: prev syllable: other");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 30,
+ "error: prev syllable: LVT");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 27,
+ "error: prev syllable: L LV T");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 24,
+ "error: prev syllable: L LVT T");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 22,
+ "error: prev syllable: L Vf");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 20,
+ "error: prev syllable: Lf V");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 16,
+ "error: prev syllable: L V T M");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 9,
+ "error: prev syllable: L L V V T T M");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 6,
+ "error: prev syllable: L V T");
+
+ s = hangul_syllable_iterator_prev(s, begin);
+ fail_unless(s - str == 0,
+ "error: prev syllable: L L V V T T");
+}
+END_TEST
+
+Suite* libhangul_suite()
+{
+ Suite* s = suite_create("libhangul");
+
+ TCase* hangul = tcase_create("hangul");
+ tcase_add_test(hangul, test_syllable_iterator);
+ suite_add_tcase(s, hangul);
+
+ return s;
+}
+
+int main()
+{
+ int number_failed;
+ Suite* s = libhangul_suite();
+ SRunner* sr = srunner_create(s);
+
+ srunner_run_all(sr, CK_NORMAL);
+
+ number_failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}