source: tests/check_nick.c @ af359b4

Last change on this file since af359b4 was 1bed2e1, checked in by dequis <dx@…>, at 2014-02-28T00:00:03Z

Fix check_nick tests (Ticket #1102)

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