1 | #include <stdlib.h> |
---|
2 | #include <glib.h> |
---|
3 | #include <gmodule.h> |
---|
4 | #include <check.h> |
---|
5 | #include <string.h> |
---|
6 | #include "bitlbee.h" |
---|
7 | #include "user.h" |
---|
8 | #include "testsuite.h" |
---|
9 | |
---|
10 | START_TEST(test_user_add) |
---|
11 | irc_t *irc = torture_irc(); |
---|
12 | user_t *user; |
---|
13 | user = user_add(irc, "foo"); |
---|
14 | fail_if(user == NULL); |
---|
15 | fail_if(strcmp(user->nick, "foo") != 0); |
---|
16 | fail_unless(user_find(irc, "foo") == user); |
---|
17 | END_TEST |
---|
18 | |
---|
19 | START_TEST(test_user_add_exists) |
---|
20 | irc_t *irc = torture_irc(); |
---|
21 | user_t *user; |
---|
22 | user = user_add(irc, "foo"); |
---|
23 | fail_if(user == NULL); |
---|
24 | user = user_add(irc, "foo"); |
---|
25 | fail_unless(user == NULL); |
---|
26 | END_TEST |
---|
27 | |
---|
28 | START_TEST(test_user_add_invalid) |
---|
29 | irc_t *irc = torture_irc(); |
---|
30 | user_t *user; |
---|
31 | user = user_add(irc, ":foo"); |
---|
32 | fail_unless(user == NULL); |
---|
33 | END_TEST |
---|
34 | |
---|
35 | START_TEST(test_user_del_invalid) |
---|
36 | irc_t *irc = torture_irc(); |
---|
37 | fail_unless(user_del(irc, ":foo") == 0); |
---|
38 | END_TEST |
---|
39 | |
---|
40 | START_TEST(test_user_del) |
---|
41 | irc_t *irc = torture_irc(); |
---|
42 | user_t *user; |
---|
43 | user = user_add(irc, "foo"); |
---|
44 | fail_unless(user_del(irc, "foo") == 1); |
---|
45 | fail_unless(user_find(irc, "foo") == NULL); |
---|
46 | END_TEST |
---|
47 | |
---|
48 | START_TEST(test_user_del_nonexistant) |
---|
49 | irc_t *irc = torture_irc(); |
---|
50 | fail_unless(user_del(irc, "foo") == 0); |
---|
51 | END_TEST |
---|
52 | |
---|
53 | START_TEST(test_user_rename) |
---|
54 | irc_t *irc = torture_irc(); |
---|
55 | user_t *user; |
---|
56 | user = user_add(irc, "foo"); |
---|
57 | user_rename(irc, "foo", "bar"); |
---|
58 | fail_unless(user_find(irc, "foo") == NULL); |
---|
59 | fail_if(user_find(irc, "bar") == NULL); |
---|
60 | END_TEST |
---|
61 | |
---|
62 | Suite *user_suite (void) |
---|
63 | { |
---|
64 | Suite *s = suite_create("User"); |
---|
65 | TCase *tc_core = tcase_create("Core"); |
---|
66 | suite_add_tcase (s, tc_core); |
---|
67 | tcase_add_test (tc_core, test_user_add); |
---|
68 | tcase_add_test (tc_core, test_user_add_invalid); |
---|
69 | tcase_add_test (tc_core, test_user_add_exists); |
---|
70 | tcase_add_test (tc_core, test_user_del_invalid); |
---|
71 | tcase_add_test (tc_core, test_user_del_nonexistant); |
---|
72 | tcase_add_test (tc_core, test_user_del); |
---|
73 | tcase_add_test (tc_core, test_user_rename); |
---|
74 | return s; |
---|
75 | } |
---|