diff libpurple/tests/test_oscar_util.c @ 31204:f1874b08b3f9

Add unit tests for oscar_util_name_compare. I suspected that this function missed a few cases, but I was wrong, it's good. I used ck_assert_int_eq and ck_assert_ne, which look like they might be newer API. If that causes a problem we can change them to fail_if and fail_unless
author Mark Doliner <mark@kingant.net>
date Mon, 14 Feb 2011 03:10:09 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_oscar_util.c	Mon Feb 14 03:10:09 2011 +0000
@@ -0,0 +1,47 @@
+#include <string.h>
+
+#include "tests.h"
+#include "../protocols/oscar/oscar.h"
+
+START_TEST(test_oscar_util_name_compare)
+{
+	int i;
+	const char *good[] = {
+		"test",
+		"TEST",
+		"Test",
+		"teSt",
+		" TesT",
+		"test ",
+		"  T E   s T  "
+	};
+	const char *bad[] = {
+		"toast",
+		"test@example.com",
+		"test@aim.com"
+	};
+
+	for (i = 0; i < G_N_ELEMENTS(good); i++) {
+		ck_assert_int_eq(0, oscar_util_name_compare("test", good[i]));
+		ck_assert_int_eq(0, oscar_util_name_compare(good[i], "test"));
+	}
+	for (i = 0; i < G_N_ELEMENTS(bad); i++) {
+		ck_assert_int_ne(0, oscar_util_name_compare("test", bad[i]));
+		ck_assert_int_ne(0, oscar_util_name_compare(bad[i], "test"));
+	}
+}
+END_TEST
+
+Suite *oscar_util_suite(void)
+{
+	Suite *s;
+	TCase *tc;
+
+	s = suite_create("OSCAR Utility Functions");
+
+	tc = tcase_create("Convert IM from network format to HTML");
+	tcase_add_test(tc, test_oscar_util_name_compare);
+	suite_add_tcase(s, tc);
+
+	return s;
+}