Merge skyped bugfix (#945).
[bitlbee.git] / tests / check_nick.c
blob6c4267cd204f622d12866a5dfb3f0bef4ac1553f
1 #include <stdlib.h>
2 #include <glib.h>
3 #include <gmodule.h>
4 #include <check.h>
5 #include <string.h>
6 #include "irc.h"
7 #include "set.h"
8 #include "misc.h"
10 START_TEST(test_nick_strip)
12 int i;
13 const char *get[] = { "test:", "test", "test\n",
14 "thisisaveryveryveryverylongnick",
15 "thisisave:ryveryveryverylongnick",
16 "t::::est",
17 "test123",
18 "123test",
19 "123",
20 NULL };
21 const char *expected[] = { "test", "test", "test",
22 "thisisaveryveryveryveryl",
23 "thisisaveryveryveryveryl",
24 "test",
25 "test123",
26 "_123test",
27 "_123",
28 NULL };
30 for (i = 0; get[i]; i++) {
31 char copy[60];
32 strcpy(copy, get[i]);
33 nick_strip(copy);
34 fail_unless (strcmp(copy, expected[i]) == 0,
35 "(%d) nick_strip broken: %s -> %s (expected: %s)",
36 i, get[i], copy, expected[i]);
39 END_TEST
41 START_TEST(test_nick_ok_ok)
43 const char *nicks[] = { "foo", "bar123", "bla[", "blie]", "BreEZaH",
44 "\\od^~", "_123", "_123test", NULL };
45 int i;
47 for (i = 0; nicks[i]; i++) {
48 fail_unless (nick_ok(nicks[i]) == 1,
49 "nick_ok() failed: %s", nicks[i]);
52 END_TEST
54 START_TEST(test_nick_ok_notok)
56 const char *nicks[] = { "thisisaveryveryveryveryveryveryverylongnick",
57 "\nillegalchar", "", "nick%", "123test", NULL };
58 int i;
60 for (i = 0; nicks[i]; i++) {
61 fail_unless (nick_ok(nicks[i]) == 0,
62 "nick_ok() succeeded for invalid: %s", nicks[i]);
65 END_TEST
67 Suite *nick_suite (void)
69 Suite *s = suite_create("Nick");
70 TCase *tc_core = tcase_create("Core");
71 suite_add_tcase (s, tc_core);
72 tcase_add_test (tc_core, test_nick_ok_ok);
73 tcase_add_test (tc_core, test_nick_ok_notok);
74 tcase_add_test (tc_core, test_nick_strip);
75 return s;