changeset 15042:edd78a0c6698

[gaim-migrate @ 17825] partition the tests committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 26 Nov 2006 23:31:16 +0000
parents 3d87d9b7491c
children 603960420450
files libgaim/tests/Makefile.am libgaim/tests/check_libgaim.c libgaim/tests/test_util.c libgaim/tests/tests.h
diffstat 4 files changed, 138 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/tests/Makefile.am	Sun Nov 26 22:29:21 2006 +0000
+++ b/libgaim/tests/Makefile.am	Sun Nov 26 23:31:16 2006 +0000
@@ -1,7 +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_SOURCES = check_libgaim.c tests.h test_util.c $(top_builddir)/libgaim/util.h
 check_libgaim_CFLAGS = @CHECK_CFLAGS@ $(GLIB_CFLAGS)
 check_libgaim_LDADD = @CHECK_LIBS@ $(GLIB_LIBS) $(top_builddir)/libgaim/libgaim.la
 endif
--- a/libgaim/tests/check_libgaim.c	Sun Nov 26 22:29:21 2006 +0000
+++ b/libgaim/tests/check_libgaim.c	Sun Nov 26 23:31:16 2006 +0000
@@ -1,58 +1,10 @@
-#include <glib.h>
-#include <check.h>
+#include "tests.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)
+Suite*
+master_suite(void)
 {
-	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);
+	Suite *s = suite_create("Master Suite");
 
 	return s;
 }
@@ -60,8 +12,10 @@
 int main(void)
 {
 	int number_failed;
-	Suite *s = util_suite ();
-	SRunner *sr = srunner_create (s);
+	SRunner *sr = srunner_create (master_suite());
+
+	srunner_add_suite(sr, util_suite());
+
 	srunner_run_all (sr, CK_NORMAL);
 	number_failed = srunner_ntests_failed (sr);
 	srunner_free (sr);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgaim/tests/test_util.c	Sun Nov 26 23:31:16 2006 +0000
@@ -0,0 +1,104 @@
+#include "tests.h"
+#include "../util.h"
+
+START_TEST(test_util_base16_encode)
+{
+	assert_string_equal_free("68656c6c6f2c20776f726c642100", gaim_base16_encode("hello, world!", 14));
+}
+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)
+{
+	assert_string_equal_free("Zm9ydHktdHdvAA==", gaim_base64_encode("forty-two", 10));
+}
+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
+
+START_TEST(test_util_escape_filename)
+{
+	assert_string_equal("foo", gaim_escape_filename("foo"));
+	assert_string_equal("@oo", gaim_escape_filename("@oo"));
+	assert_string_equal("#oo", gaim_escape_filename("#oo"));
+	assert_string_equal("-oo", gaim_escape_filename("-oo"));
+	assert_string_equal("_oo", gaim_escape_filename("_oo"));
+	assert_string_equal(".oo", gaim_escape_filename(".oo"));
+	assert_string_equal("%25oo", gaim_escape_filename("%oo"));
+	assert_string_equal("%21oo", gaim_escape_filename("!oo"));
+}
+END_TEST
+
+START_TEST(test_util_unescape_filename)
+{
+	assert_string_equal("bar", gaim_unescape_filename("bar"));
+	assert_string_equal("@ar", gaim_unescape_filename("@ar"));
+	assert_string_equal("!ar", gaim_unescape_filename("!ar"));
+	assert_string_equal("!ar", gaim_unescape_filename("%21ar"));
+	assert_string_equal("%ar", gaim_unescape_filename("%25ar"));
+}
+END_TEST
+
+
+START_TEST(test_util_text_strip_mnemonic)
+{
+	assert_string_equal_free("", gaim_text_strip_mnemonic(""));
+	assert_string_equal_free("foo", gaim_text_strip_mnemonic("foo"));
+	assert_string_equal_free("foo", gaim_text_strip_mnemonic("_foo"));
+
+}
+END_TEST
+
+START_TEST(test_util_email_is_valid)
+{
+	fail_unless(gaim_email_is_valid("gaim-devel@lists.sf.net"));
+}
+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);
+
+	tc = tcase_create("Filenames");
+	tcase_add_test(tc, test_util_escape_filename);
+	tcase_add_test(tc, test_util_unescape_filename);
+	suite_add_tcase(s, tc);
+
+	tc = tcase_create("Strip Mnemonic");
+	tcase_add_test(tc, test_util_text_strip_mnemonic);
+	suite_add_tcase(s, tc);
+
+	tc = tcase_create("Email");
+	tcase_add_test(tc, test_util_email_is_valid);
+	suite_add_tcase(s, tc);
+
+	return s;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgaim/tests/tests.h	Sun Nov 26 23:31:16 2006 +0000
@@ -0,0 +1,25 @@
+#ifndef TESTS_H
+#  define TESTS_H
+
+#include <glib.h>
+#include <check.h>
+
+/* define the test suites here */
+/* remember to add the suite to the runner in check_libgaim.c */
+Suite * util_suite(void);
+
+/* helper macros */
+#define assert_string_equal(expected, actual) { \
+	const gchar *a = actual; \
+	fail_unless(strcmp(expected, a) == 0, "Expecting '%s' but got '%s'", expected, a); \
+}
+
+#define assert_string_equal_free(expected, actual) { \
+	gchar *a = actual; \
+	assert_string_equal(expected, a); \
+	g_free(a); \
+}
+
+
+#endif /* ifndef TESTS_H */
+