aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check_nick.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-06-25 14:17:39 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2006-06-25 14:17:39 +0200
commit125b35db3243f55489a6e88efbdeeefc2c24018d (patch)
tree1e24ec316678b6af288ed96d29e82bbba37f70bc /tests/check_nick.c
parent59f5c42a86fe73e95aaed0bfe455c7c816f39d2b (diff)
parent1fc2958b1e503b782081692c1a503bc7bba19fe1 (diff)
Merging from Jelmer (this adds some basic unit testing code).
Diffstat (limited to 'tests/check_nick.c')
-rw-r--r--tests/check_nick.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/check_nick.c b/tests/check_nick.c
new file mode 100644
index 00000000..5858e512
--- /dev/null
+++ b/tests/check_nick.c
@@ -0,0 +1,70 @@
+#include <stdlib.h>
+#include <glib.h>
+#include <gmodule.h>
+#include <check.h>
+#include <string.h>
+#include "irc.h"
+#include "set.h"
+#include "util.h"
+
+START_TEST(test_nick_strip)
+{
+ int i;
+ const char *get[] = { "test:", "test", "test\n",
+ "thisisaveryveryveryverylongnick",
+ "thisisave:ryveryveryverylongnick",
+ "t::::est",
+ NULL };
+ const char *expected[] = { "test", "test", "test",
+ "thisisaveryveryveryveryl",
+ "thisisaveryveryveryveryl",
+ "test",
+ NULL };
+
+ for (i = 0; get[i]; i++) {
+ char copy[30];
+ strcpy(copy, get[i]);
+ nick_strip(copy);
+ fail_unless (strcmp(copy, expected[i]) == 0,
+ "(%d) nick_strip broken: %s -> %s (expected: %s)",
+ i, get[i], copy, expected[i]);
+ }
+}
+END_TEST
+
+START_TEST(test_nick_ok_ok)
+{
+ const char *nicks[] = { "foo", "bar", "bla[", "blie]",
+ "BreEZaH", "\\od^~", NULL };
+ int i;
+
+ for (i = 0; nicks[i]; i++) {
+ fail_unless (nick_ok(nicks[i]) == 1,
+ "nick_ok() failed: %s", nicks[i]);
+ }
+}
+END_TEST
+
+START_TEST(test_nick_ok_notok)
+{
+ const char *nicks[] = { "thisisaveryveryveryveryveryveryverylongnick",
+ "\nillegalchar", "", "nick%", NULL };
+ int i;
+
+ for (i = 0; nicks[i]; i++) {
+ fail_unless (nick_ok(nicks[i]) == 0,
+ "nick_ok() succeeded for invalid: %s", nicks[i]);
+ }
+}
+END_TEST
+
+Suite *nick_suite (void)
+{
+ Suite *s = suite_create("Nick");
+ TCase *tc_core = tcase_create("Core");
+ suite_add_tcase (s, tc_core);
+ tcase_add_test (tc_core, test_nick_ok_ok);
+ tcase_add_test (tc_core, test_nick_ok_notok);
+ tcase_add_test (tc_core, test_nick_strip);
+ return s;
+}