]> jfr.im git - solanum.git/blob - tests/send1.c
tests: add sendto_* test framework
[solanum.git] / tests / send1.c
1 /*
2 * send1.c: Test sendto_* under various conditions
3 * Copyright 2017 Simon Arlott
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 */
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "tap/basic.h"
25
26 #include "ircd_util.h"
27 #include "client_util.h"
28
29 #include "send.h"
30
31 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
32
33 static void sendto_one_numeric1(void)
34 {
35 struct Client *user = make_local_person();
36
37 sendto_one_numeric(user, 1, "Hello %s!", "World");
38 is_client_sendq(":" TEST_ME_NAME " 001 " TEST_NICK " Hello World!" CRLF, user, MSG);
39
40 remove_local_person(user);
41 }
42
43 static void sendto_wallops_flags1(void)
44 {
45 struct Client *user1 = make_local_person_nick("user1");
46 struct Client *user2 = make_local_person_nick("user2");
47 struct Client *oper1 = make_local_person_nick("oper1");
48 struct Client *oper2 = make_local_person_nick("oper2");
49 struct Client *oper3 = make_local_person_nick("oper3");
50 struct Client *oper4 = make_local_person_nick("oper4");
51
52 rb_dlinkAddAlloc(oper1, &local_oper_list);
53 rb_dlinkAddAlloc(oper1, &oper_list);
54 SetOper(oper1);
55
56 rb_dlinkAddAlloc(oper2, &local_oper_list);
57 rb_dlinkAddAlloc(oper2, &oper_list);
58 SetOper(oper2);
59
60 rb_dlinkAddAlloc(oper3, &local_oper_list);
61 rb_dlinkAddAlloc(oper3, &oper_list);
62 SetOper(oper3);
63
64 rb_dlinkAddAlloc(oper4, &local_oper_list);
65 rb_dlinkAddAlloc(oper4, &oper_list);
66 SetOper(oper4);
67
68 user1->umodes |= UMODE_WALLOP;
69 oper1->umodes |= UMODE_WALLOP | UMODE_OPERWALL;
70 oper2->umodes |= UMODE_WALLOP | UMODE_OPERWALL | UMODE_ADMIN;
71 oper3->umodes |= UMODE_WALLOP;
72 oper4->umodes |= UMODE_OPERWALL;
73
74 sendto_wallops_flags(UMODE_WALLOP, oper1, "Test to users");
75 is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, user1, "User is +w; " MSG);
76 is_client_sendq_empty(user2, "User is -w; " MSG);
77 is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper1, "User is +w; " MSG);
78 is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper2, "User is +w; " MSG);
79 is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper3, "User is +w; " MSG);
80 is_client_sendq_empty(oper4, "User is -w; " MSG);
81
82 sendto_wallops_flags(UMODE_OPERWALL, oper2, "Test to opers");
83 is_client_sendq_empty(user1, "Not an oper; " MSG);
84 is_client_sendq_empty(user2, "Not an oper; " MSG);
85 is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper1, "Oper is +z; " MSG);
86 is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper2, "Oper is +z; " MSG);
87 is_client_sendq_empty(oper3, "Oper is -z; " MSG);
88 is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper4, "Oper is +z; " MSG);
89
90 sendto_wallops_flags(UMODE_ADMIN, &me, "Test to admins");
91 is_client_sendq_empty(user1, "Not an admin; " MSG);
92 is_client_sendq_empty(user2, "Not an admin; " MSG);
93 is_client_sendq_empty(oper1, "Not an admin; " MSG);
94 is_client_sendq(":" TEST_ME_NAME " WALLOPS :Test to admins" CRLF, oper2, MSG);
95 is_client_sendq_empty(oper3, "Not an admin; " MSG);
96 is_client_sendq_empty(oper4, "Not an admin; " MSG);
97
98 remove_local_person(user1);
99 remove_local_person(user2);
100 remove_local_person(oper1);
101 remove_local_person(oper2);
102 remove_local_person(oper3);
103 remove_local_person(oper4);
104 }
105
106 int main(int argc, char *argv[])
107 {
108 plan_lazy();
109
110 ircd_util_init(__FILE__);
111 client_util_init();
112
113 sendto_one_numeric1();
114 sendto_wallops_flags1();
115
116 client_util_free();
117 ircd_util_free();
118 return 0;
119 }