source: tests/check_nick.c @ 1521a85

Last change on this file since 1521a85 was 0f47613, checked in by Wilmer van der Gaast <wilmer@…>, at 2007-12-10T22:57:13Z

Don't allow nicks that start with a number.

  • Property mode set to 100644
File size: 1.7 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 "misc.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                "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 };
29
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]);
37        }
38}
39END_TEST
40
41START_TEST(test_nick_ok_ok)
42{
43        const char *nicks[] = { "foo", "bar123", "bla[", "blie]", "BreEZaH",
44                                "\\od^~", "_123", "_123test", NULL };
45        int i;
46
47        for (i = 0; nicks[i]; i++) {
48                fail_unless (nick_ok(nicks[i]) == 1,
49                                         "nick_ok() failed: %s", nicks[i]);
50        }
51}
52END_TEST
53
54START_TEST(test_nick_ok_notok)
55{
56        const char *nicks[] = { "thisisaveryveryveryveryveryveryverylongnick",
57                                    "\nillegalchar", "", "nick%", "123test", NULL };
58        int i;
59
60        for (i = 0; nicks[i]; i++) {
61                fail_unless (nick_ok(nicks[i]) == 0,
62                                         "nick_ok() succeeded for invalid: %s", nicks[i]);
63        }
64}
65END_TEST
66
67Suite *nick_suite (void)
68{
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;
76}
Note: See TracBrowser for help on using the repository browser.