]>
Commit | Line | Data |
---|---|---|
6f88bf5c EK |
1 | /* |
2 | * Copyright (C) 2020 Ed Kellett | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
17 | * USA | |
18 | */ | |
19 | #include <stdio.h> | |
20 | #include <string.h> | |
21 | #include <stdlib.h> | |
22 | #include <unistd.h> | |
23 | #include "tap/basic.h" | |
24 | ||
25 | #include "ircd_util.h" | |
26 | #include "client_util.h" | |
27 | ||
28 | #include "send.h" | |
29 | #include "s_serv.h" | |
30 | #include "monitor.h" | |
31 | #include "s_conf.h" | |
32 | #include "hash.h" | |
33 | ||
34 | #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__ | |
35 | ||
36 | static void sendto_multiline_basic(void) | |
37 | { | |
38 | struct Client *user = make_local_person(); | |
39 | const char *s; | |
40 | ||
41 | /* multiline with no items should do nothing */ | |
42 | send_multiline_init(user, " ", "foo"); | |
43 | send_multiline_fini(user, NULL); | |
44 | is_client_sendq_empty(user, MSG); | |
45 | ||
46 | /* 510 = 17 * 30. line the end of an item with the end of the 510-byte data exactly */ | |
47 | send_multiline_init(user, " ", "prefix78901234567 "); | |
48 | for (size_t i = 0; i < 29; i++) | |
49 | send_multiline_item(user, "item567890123456"); | |
50 | send_multiline_fini(user, NULL); | |
51 | ||
52 | s = get_client_sendq(user); | |
53 | is_int(512, strlen(s), MSG); | |
54 | is_string("item567890123456\r\n", &s[494], MSG); | |
55 | is_client_sendq_empty(user, MSG); | |
56 | ||
57 | /* just run exactly the same thing again, there's static state */ | |
58 | send_multiline_init(user, " ", "prefix78901234567 "); | |
59 | for (size_t i = 0; i < 29; i++) | |
60 | send_multiline_item(user, "item567890123456"); | |
61 | send_multiline_fini(user, NULL); | |
62 | ||
63 | s = get_client_sendq(user); | |
64 | is_int(512, strlen(s), MSG); | |
65 | is_string("item567890123456\r\n", &s[494], MSG); | |
66 | is_client_sendq_empty(user, MSG); | |
67 | ||
68 | /* the same thing again but with one extra character, so we have an item that just won't fit */ | |
69 | send_multiline_init(user, " ", "prefix789012345678 "); | |
70 | for (size_t i = 0; i < 29; i++) | |
71 | send_multiline_item(user, "item567890123456"); | |
72 | send_multiline_item(user, "bar"); | |
73 | send_multiline_fini(user, "foo "); | |
74 | ||
75 | s = get_client_sendq(user); | |
76 | is_string("item567890123456\r\n", &s[478], MSG); | |
77 | is_client_sendq("foo item567890123456 bar\r\n", user, MSG); | |
78 | ||
79 | remove_local_person(user); | |
80 | } | |
81 | ||
82 | static void sendto_multiline_extra_space(void) | |
83 | { | |
84 | struct Client *server = make_remote_server_full(&me, "remote.test", "777"); | |
85 | struct Client *luser = make_local_person(); | |
86 | struct Client *ruser = make_remote_person(server); | |
87 | const char *s; | |
88 | ||
89 | strcpy(ruser->id, "777000001"); | |
90 | add_to_id_hash(ruser->id, ruser); | |
91 | ||
92 | /* ":me.test foo4567890123 local_test :" -> 22 + 13 = 35 */ | |
93 | send_multiline_init(luser, " ", ":%s foo4567890123 %s :", | |
94 | get_id(&me, luser), get_id(luser, luser)); | |
95 | /* both of these should be noop */ | |
96 | send_multiline_remote_pad(luser, &me); | |
97 | send_multiline_remote_pad(luser, luser); | |
98 | /* so all this should fit on one line */ | |
99 | for (size_t i = 0; i < 28; i++) | |
100 | send_multiline_item(luser, "item567890123456"); | |
101 | send_multiline_fini(luser, NULL); | |
102 | ||
103 | s = get_client_sendq(luser); | |
104 | is_int(512, strlen(s), MSG); | |
105 | is_string("item567890123456\r\n", &s[494], MSG); | |
106 | is_client_sendq_empty(luser, MSG); | |
107 | ||
108 | /* as above, but remote_test is one longer */ | |
109 | send_multiline_init(ruser, " ", ":%s foo456789012 %s :", | |
110 | get_id(&me, ruser), get_id(ruser, ruser)); | |
111 | /* should add "me.test" - 3 = 4 */ | |
112 | send_multiline_remote_pad(ruser, &me); | |
113 | /* should add "remote_test" - 9 = 2 */ | |
114 | send_multiline_remote_pad(ruser, ruser); | |
115 | /* so all this should fit on one line */ | |
116 | for (size_t i = 0; i < 28; i++) | |
117 | send_multiline_item(ruser, "item567890123456"); | |
118 | /* and this shouldn't */ | |
119 | send_multiline_item(ruser, "x"); | |
120 | send_multiline_fini(ruser, NULL); | |
121 | ||
122 | s = get_client_sendq(server); | |
123 | is_int(506, strlen(s), MSG); | |
124 | is_string("item567890123456\r\n", &s[488], MSG); | |
125 | is_client_sendq(":0AA foo456789012 777000001 :x\r\n", server, MSG); | |
126 | } | |
127 | ||
128 | int main(int argc, char *argv[]) | |
129 | { | |
130 | plan_lazy(); | |
131 | ||
132 | ircd_util_init(__FILE__); | |
133 | client_util_init(); | |
134 | ||
135 | sendto_multiline_basic(); | |
136 | sendto_multiline_extra_space(); | |
137 | ||
138 | client_util_free(); | |
139 | ircd_util_free(); | |
140 | return 0; | |
141 | } |