Mercurial > pidgin
changeset 15040:ba149ceb20b7
[gaim-migrate @ 17823]
baby steps: 4 unit tests for libgaim
to run these, you'll need check (http://check.sf.net/) 0.9.4 or later installed
they run when you run 'make check'
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 26 Nov 2006 22:03:23 +0000 |
parents | 9a69964d8c18 |
children | 3d87d9b7491c |
files | configure.ac libgaim/Makefile.am libgaim/tests/Makefile.am libgaim/tests/check_libgaim.c |
diffstat | 4 files changed, 86 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Sun Nov 26 20:45:29 2006 +0000 +++ b/configure.ac Sun Nov 26 22:03:23 2006 +0000 @@ -1807,6 +1807,14 @@ fi dnl ####################################################################### +dnl # Check for check +dnl ####################################################################### +PKG_CHECK_MODULES(CHECK, check >= 0.9.4, have_check=yes, have_check=no) +AM_CONDITIONAL(HAVE_CHECK, test "x$have_check" = "xyes") +AC_SUBST(CHECK_CFLAGS) +AC_SUBST(CHECK_LIBS) + +dnl ####################################################################### dnl # Check for Doxygen and dot (part of GraphViz) dnl ####################################################################### AC_ARG_ENABLE(doxygen, @@ -1906,6 +1914,7 @@ libgaim/protocols/toc/Makefile libgaim/protocols/yahoo/Makefile libgaim/protocols/zephyr/Makefile + libgaim/tests/Makefile console/Makefile console/libgnt/Makefile console/libgnt/gnt.pc
--- a/libgaim/Makefile.am Sun Nov 26 20:45:29 2006 +0000 +++ b/libgaim/Makefile.am Sun Nov 26 22:03:23 2006 +0000 @@ -23,7 +23,7 @@ GCONF_DIR=gconf endif -SUBDIRS = $(GCONF_DIR) plugins protocols +SUBDIRS = $(GCONF_DIR) plugins protocols tests gaim_coresources = \ account.c \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgaim/tests/Makefile.am Sun Nov 26 22:03:23 2006 +0000 @@ -0,0 +1,7 @@ +if HAVE_CHECK +TESTS = check_libgaim +check_PROGRAMS = check_libgaim +check_libgaim_SOURCES = check_libgaim.c $(top_builddir)/libgaim/gaim.h +check_libgaim_CFLAGS = @CHECK_CFLAGS@ $(GLIB_CFLAGS) +check_libgaim_LDADD = @CHECK_LIBS@ $(GLIB_LIBS) $(top_builddir)/libgaim/libgaim.la +endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgaim/tests/check_libgaim.c Sun Nov 26 22:03:23 2006 +0000 @@ -0,0 +1,69 @@ +#include <glib.h> +#include <check.h> +#include <stdlib.h> +#include "../util.h" + +START_TEST(test_util_base16_encode) +{ + gchar *out = gaim_base16_encode("hello, world!", 14); + fail_unless(strcmp("68656c6c6f2c20776f726c642100", out) == 0, NULL); + g_free(out); +} +END_TEST + +START_TEST(test_util_base16_decode) +{ + gsize sz = 0; + guchar *out = gaim_base16_decode("21646c726f77202c6f6c6c656800", &sz); + fail_unless(sz == 14, NULL); + fail_unless(strcmp("!dlrow ,olleh", out) == 0, NULL); + g_free(out); +} +END_TEST + +START_TEST(test_util_base64_encode) +{ + gchar *out = gaim_base64_encode("forty-two", 10); + fail_unless(strcmp("Zm9ydHktdHdvAA==",out) == 0, NULL); + g_free(out); +} +END_TEST + +START_TEST(test_util_base64_decode) +{ + gsize sz; + guchar *out = gaim_base64_decode("b3d0LXl0cm9mAA==", &sz); + fail_unless(sz == 10, NULL); + fail_unless(strcmp("owt-ytrof", out) == 0, NULL); + g_free(out); +} +END_TEST + +Suite * +util_suite(void) +{ + Suite *s = suite_create("Utility Functions"); + + TCase *tc = tcase_create("Base16"); + tcase_add_test(tc, test_util_base16_encode); + tcase_add_test(tc, test_util_base16_decode); + suite_add_tcase(s, tc); + + tc = tcase_create("Base64"); + tcase_add_test(tc, test_util_base64_encode); + tcase_add_test(tc, test_util_base64_decode); + suite_add_tcase(s, tc); + + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = util_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; +}