1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include <stdlib.h>
#include <glib.h>
#include <gmodule.h>
#include <check.h>
#include <string.h>
#include "irc.h"
#include "set.h"
#include "misc.h"
#include "bitlbee.h"
START_TEST(test_nick_strip){
int i;
const char *get[] = { "test:", "test", "test\n",
"thisisaveryveryveryverylongnick",
"thisisave:ryveryveryverylongnick",
"t::::est",
"test123",
"123test",
"123",
NULL };
const char *expected[] = { "test", "test", "test",
"thisisaveryveryveryveryl",
"thisisaveryveryveryveryl",
"test",
"test123",
"_123test",
"_123",
NULL };
for (i = 0; get[i]; i++) {
char copy[60];
strcpy(copy, get[i]);
nick_strip(NULL, 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", "bar123", "bla[", "blie]", "BreEZaH",
"\\od^~", "_123", "_123test", NULL };
int i;
for (i = 0; nicks[i]; i++) {
fail_unless(nick_ok(NULL, nicks[i]) == 1,
"nick_ok() failed: %s", nicks[i]);
}
}
END_TEST
START_TEST(test_nick_ok_notok)
{
const char *nicks[] = { "thisisaveryveryveryveryveryveryverylongnick",
"\nillegalchar", "", "nick%", "123test", NULL };
int i;
for (i = 0; nicks[i]; i++) {
fail_unless(nick_ok(NULL, 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;
}
|