source: tests/check_nick.c @ 125b35d

Last change on this file since 125b35d was 1fc2958, checked in by Jelmer Vernooij <jelmer@…>, at 2006-06-16T12:07:51Z

Add checks for nick functions as well, fix bug where nick lengths weren't
being honored.

  • Property mode set to 100644
File size: 1.6 KB
Line 
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 "util.h"
9
10START_TEST(test_nick_strip)
11{
12        int i;
13        const char *get[] = { "test:", "test", "test\n", 
14                "thisisaveryveryveryverylongnick", 
15                "thisisave:ryveryveryverylongnick",
16                "t::::est",
17                NULL };
18        const char *expected[] = { "test", "test", "test", 
19                "thisisaveryveryveryveryl", 
20                "thisisaveryveryveryveryl", 
21                "test",
22                NULL };
23
24        for (i = 0; get[i]; i++) {
25                char copy[30];
26                strcpy(copy, get[i]);
27                nick_strip(copy);
28                fail_unless (strcmp(copy, expected[i]) == 0, 
29                                         "(%d) nick_strip broken: %s -> %s (expected: %s)", 
30                                         i, get[i], copy, expected[i]);
31        }
32}
33END_TEST
34
35START_TEST(test_nick_ok_ok)
36{
37        const char *nicks[] = { "foo", "bar", "bla[", "blie]", 
38                                    "BreEZaH", "\\od^~", NULL };
39        int i;
40
41        for (i = 0; nicks[i]; i++) {
42                fail_unless (nick_ok(nicks[i]) == 1,
43                                         "nick_ok() failed: %s", nicks[i]);
44        }
45}
46END_TEST
47
48START_TEST(test_nick_ok_notok)
49{
50        const char *nicks[] = { "thisisaveryveryveryveryveryveryverylongnick",
51                                    "\nillegalchar", "", "nick%", NULL };
52        int i;
53
54        for (i = 0; nicks[i]; i++) {
55                fail_unless (nick_ok(nicks[i]) == 0,
56                                         "nick_ok() succeeded for invalid: %s", nicks[i]);
57        }
58}
59END_TEST
60
61Suite *nick_suite (void)
62{
63        Suite *s = suite_create("Nick");
64        TCase *tc_core = tcase_create("Core");
65        suite_add_tcase (s, tc_core);
66        tcase_add_test (tc_core, test_nick_ok_ok);
67        tcase_add_test (tc_core, test_nick_ok_notok);
68        tcase_add_test (tc_core, test_nick_strip);
69        return s;
70}
Note: See TracBrowser for help on using the repository browser.