diff options
author | Choe Hwanjin <choe.hwanjin@gmail.com> | 2018-12-23 22:14:18 +0900 |
---|---|---|
committer | Choe Hwanjin <choe.hwanjin@gmail.com> | 2018-12-23 22:17:00 +0900 |
commit | 10c479525e694d0a32fdccaa5d909f9fa1495925 (patch) | |
tree | 2790f890dd8795b78f3ebcc55add6f46baf528dc | |
parent | 1a4acc36e17fb7d91537ffd0ea095593f7bab77e (diff) | |
download | ibus-hangul-10c479525e694d0a32fdccaa5d909f9fa1495925.tar.gz |
Add test code for UString
Test codes and test program for UString are added.
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/test-ustring.c | 62 |
2 files changed, 70 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c9208d1..2efff43 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ AM_LDFLAGS = \ $(NULL) check_PROGRAMS = \ + test-ustring $(NULL) TESTS = \ @@ -82,3 +83,10 @@ hangul.xml: hangul.xml.in test: ibus-engine-hangul $(builddir)/ibus-engine-hangul + +test_ustring_CFLAGS = $(IBUS_CFLAGS) $(HANGUL_CFLAGS) +test_ustring_LDADD = $(IBUS_LIBS) +test_ustring_SOURCES = test-ustring.c ustring.c ustring.h + +check-local: + $(builddir)/test-ustring diff --git a/src/test-ustring.c b/src/test-ustring.c new file mode 100644 index 0000000..0798a65 --- /dev/null +++ b/src/test-ustring.c @@ -0,0 +1,62 @@ +/* vim: set et sts=4: */ +/* ibus-hangul - The Hangul Engine For IBus + * Copyright (C) 2018 Choe Hwanjin <choe.hwanjin@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "ustring.h" + +#include <glib.h> + + +static void +test_ustring_compare(void) +{ + UString* s1 = ustring_new(); + UString* s2 = ustring_new(); + + ustring_append_utf8(s1, "abc"); + ustring_append_utf8(s2, "abd"); + g_assert_cmpint(ustring_compare(s1, s2), <, 0); + + ustring_clear(s1); + ustring_clear(s2); + + ustring_append_utf8(s1, "abc"); + ustring_append_utf8(s2, "abb"); + g_assert_cmpint(ustring_compare(s1, s2), >, 0); + + ustring_clear(s1); + ustring_clear(s2); + + ustring_append_utf8(s1, "abc"); + ustring_append_utf8(s2, "abc"); + g_assert_cmpint(ustring_compare(s1, s2), ==, 0); + + ustring_delete(s1); + ustring_delete(s2); +} + +int +main(int argc, char* argv[]) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/ibus-hangul/ustring/compare", test_ustring_compare); + + int result = g_test_run(); + return result; +} |