|
@@ -1,347 +0,0 @@
|
1
|
|
-/*
|
2
|
|
- * Copyright (c) 2006-2015 DMDirc Developers
|
3
|
|
- *
|
4
|
|
- * Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
|
- * of this software and associated documentation files (the "Software"), to deal
|
6
|
|
- * in the Software without restriction, including without limitation the rights
|
7
|
|
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
|
- * copies of the Software, and to permit persons to whom the Software is
|
9
|
|
- * furnished to do so, subject to the following conditions:
|
10
|
|
- *
|
11
|
|
- * The above copyright notice and this permission notice shall be included in
|
12
|
|
- * all copies or substantial portions of the Software.
|
13
|
|
- *
|
14
|
|
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
|
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
|
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
|
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
|
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
|
- * SOFTWARE.
|
21
|
|
- */
|
22
|
|
-package com.dmdirc.parser.irc;
|
23
|
|
-
|
24
|
|
-import com.dmdirc.harness.parser.TestParser;
|
25
|
|
-
|
26
|
|
-import com.dmdirc.parser.interfaces.ChannelInfo;
|
27
|
|
-
|
28
|
|
-import org.junit.Ignore;
|
29
|
|
-import org.junit.Test;
|
30
|
|
-import static org.junit.Assert.*;
|
31
|
|
-
|
32
|
|
-public class ChannelInfoTest {
|
33
|
|
-
|
34
|
|
- final IRCChannelInfo ci = new IRCChannelInfo(null, null, null, null, "name");
|
35
|
|
-
|
36
|
|
- @Test
|
37
|
|
- public void testGetName() {
|
38
|
|
- assertEquals("name", ci.getName());
|
39
|
|
- }
|
40
|
|
-
|
41
|
|
- @Test
|
42
|
|
- public void testAddingNames() {
|
43
|
|
- assertTrue(ci.isAddingNames());
|
44
|
|
-
|
45
|
|
- ci.setAddingNames(false);
|
46
|
|
-
|
47
|
|
- assertFalse(ci.isAddingNames());
|
48
|
|
- }
|
49
|
|
-
|
50
|
|
- @Test
|
51
|
|
- public void testCreateTime() {
|
52
|
|
- ci.setCreateTime(12345L);
|
53
|
|
-
|
54
|
|
- assertEquals(12345L, ci.getCreateTime());
|
55
|
|
- }
|
56
|
|
-
|
57
|
|
- @Test
|
58
|
|
- public void testTopicTime() {
|
59
|
|
- ci.setTopicTime(12345L);
|
60
|
|
-
|
61
|
|
- assertEquals(12345L, ci.getTopicTime());
|
62
|
|
- }
|
63
|
|
-
|
64
|
|
- @Test
|
65
|
|
- public void testTopic() {
|
66
|
|
- ci.setInternalTopic("abcdef");
|
67
|
|
-
|
68
|
|
- assertEquals("abcdef", ci.getTopic());
|
69
|
|
- }
|
70
|
|
-
|
71
|
|
- @Test
|
72
|
|
- public void testSendMessage() {
|
73
|
|
- final TestParser parser = new TestParser();
|
74
|
|
- getChannel(parser).sendMessage("hello");
|
75
|
|
-
|
76
|
|
- assertEquals("PRIVMSG #DMDirc_testing :hello", parser.sentLines.get(0));
|
77
|
|
- }
|
78
|
|
-
|
79
|
|
- @Test
|
80
|
|
- public void testSendNotice() {
|
81
|
|
- final TestParser parser = new TestParser();
|
82
|
|
- getChannel(parser).sendNotice("hello");
|
83
|
|
-
|
84
|
|
- assertEquals("NOTICE #DMDirc_testing :hello", parser.sentLines.get(0));
|
85
|
|
- }
|
86
|
|
-
|
87
|
|
- @Test
|
88
|
|
- public void testSendCTCP() {
|
89
|
|
- final TestParser parser = new TestParser();
|
90
|
|
- getChannel(parser).sendCTCP("type", "hello");
|
91
|
|
-
|
92
|
|
- assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "TYPE hello" + ((char) 1),
|
93
|
|
- parser.sentLines.get(0));
|
94
|
|
- }
|
95
|
|
-
|
96
|
|
- @Test
|
97
|
|
- public void testSendCTCPEmpty() {
|
98
|
|
- final TestParser parser = new TestParser();
|
99
|
|
- getChannel(parser).sendCTCP("type", "");
|
100
|
|
-
|
101
|
|
- assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "TYPE" + ((char) 1),
|
102
|
|
- parser.sentLines.get(0));
|
103
|
|
- }
|
104
|
|
-
|
105
|
|
- @Test
|
106
|
|
- public void testSendAction() {
|
107
|
|
- final TestParser parser = new TestParser();
|
108
|
|
- getChannel(parser).sendAction("moo");
|
109
|
|
-
|
110
|
|
- assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "ACTION moo" + ((char) 1),
|
111
|
|
- parser.sentLines.get(0));
|
112
|
|
- }
|
113
|
|
-
|
114
|
|
- @Test
|
115
|
|
- public void testSendCTCPReply() {
|
116
|
|
- final TestParser parser = new TestParser();
|
117
|
|
- getChannel(parser).sendCTCPReply("type", "moo");
|
118
|
|
-
|
119
|
|
- assertEquals("NOTICE #DMDirc_testing :" + ((char) 1) + "TYPE moo" + ((char) 1),
|
120
|
|
- parser.sentLines.get(0));
|
121
|
|
- }
|
122
|
|
-
|
123
|
|
- @Test
|
124
|
|
- public void testSendCTCPReplyEmpty() {
|
125
|
|
- final TestParser parser = new TestParser();
|
126
|
|
- getChannel(parser).sendCTCPReply("type", "");
|
127
|
|
-
|
128
|
|
- assertEquals("NOTICE #DMDirc_testing :" + ((char) 1) + "TYPE" + ((char) 1),
|
129
|
|
- parser.sentLines.get(0));
|
130
|
|
- }
|
131
|
|
-
|
132
|
|
- @Test
|
133
|
|
- public void testSendEmptyMessages() {
|
134
|
|
- final TestParser parser = new TestParser();
|
135
|
|
- final IRCChannelInfo info = getChannel(parser);
|
136
|
|
-
|
137
|
|
- info.sendAction("");
|
138
|
|
- info.sendCTCP("", "");
|
139
|
|
- info.sendCTCPReply("", "");
|
140
|
|
- info.sendMessage("");
|
141
|
|
- info.sendNotice("");
|
142
|
|
-
|
143
|
|
- assertEquals(0, parser.sentLines.size());
|
144
|
|
- }
|
145
|
|
-
|
146
|
|
- @Test
|
147
|
|
- public void testGetSetParamMode() {
|
148
|
|
- final TestParser parser = new TestParser();
|
149
|
|
- final ChannelInfo info = getChannel(parser);
|
150
|
|
- parser.injectLine(":server 324 nick #DMDirc_testing +k lalala");
|
151
|
|
- parser.sentLines.clear();
|
152
|
|
-
|
153
|
|
- assertEquals("lalala", info.getMode('k'));
|
154
|
|
- assertEquals("", info.getMode('z'));
|
155
|
|
-
|
156
|
|
- parser.injectLine(":server MODE #DMDirc_testing -k *");
|
157
|
|
-
|
158
|
|
- assertEquals("", info.getMode('k'));
|
159
|
|
- }
|
160
|
|
-
|
161
|
|
- @Test
|
162
|
|
- public void testModeSendFull() {
|
163
|
|
- final TestParser parser = new TestParser();
|
164
|
|
- final ChannelInfo info = getChannel(parser);
|
165
|
|
-
|
166
|
|
- parser.sentLines.clear();
|
167
|
|
- info.alterMode(true, 'i', null);
|
168
|
|
- info.alterMode(true, 'm', null);
|
169
|
|
- info.alterMode(true, 'n', null);
|
170
|
|
- info.alterMode(true, 'p', null);
|
171
|
|
- info.alterMode(true, 't', null);
|
172
|
|
- info.alterMode(true, 'r', null);
|
173
|
|
-
|
174
|
|
- assertEquals("Parser must send modes as soon as the max number is reached",
|
175
|
|
- 1, parser.sentLines.size());
|
176
|
|
- final String modes = getModes(parser.sentLines.get(0));
|
177
|
|
-
|
178
|
|
- assertTrue(modes.indexOf('i') > -1);
|
179
|
|
- assertTrue(modes.indexOf('m') > -1);
|
180
|
|
- assertTrue(modes.indexOf('n') > -1);
|
181
|
|
- assertTrue(modes.indexOf('p') > -1);
|
182
|
|
- assertTrue(modes.indexOf('t') > -1);
|
183
|
|
- assertTrue(modes.indexOf('r') > -1);
|
184
|
|
- }
|
185
|
|
-
|
186
|
|
- @Test
|
187
|
|
- public void testModeSendExtra() {
|
188
|
|
- final TestParser parser = new TestParser();
|
189
|
|
- final ChannelInfo info = getChannel(parser);
|
190
|
|
-
|
191
|
|
- parser.sentLines.clear();
|
192
|
|
- info.alterMode(true, 'i', null);
|
193
|
|
- info.alterMode(true, 'm', null);
|
194
|
|
- info.alterMode(true, 'n', null);
|
195
|
|
- info.alterMode(true, 'p', null);
|
196
|
|
- info.alterMode(true, 't', null);
|
197
|
|
- info.alterMode(true, 'r', null);
|
198
|
|
- info.alterMode(true, 'N', null);
|
199
|
|
- info.flushModes();
|
200
|
|
-
|
201
|
|
- assertEquals("sendModes must send modes",
|
202
|
|
- 2, parser.sentLines.size());
|
203
|
|
-
|
204
|
|
- final String modes = getModes(parser.sentLines.get(0))
|
205
|
|
- + getModes(parser.sentLines.get(1));
|
206
|
|
-
|
207
|
|
- assertTrue(modes.indexOf('i') > -1);
|
208
|
|
- assertTrue(modes.indexOf('m') > -1);
|
209
|
|
- assertTrue(modes.indexOf('n') > -1);
|
210
|
|
- assertTrue(modes.indexOf('p') > -1);
|
211
|
|
- assertTrue(modes.indexOf('t') > -1);
|
212
|
|
- assertTrue(modes.indexOf('r') > -1);
|
213
|
|
- assertTrue(modes.indexOf('N') > -1);
|
214
|
|
- }
|
215
|
|
-
|
216
|
|
- @Test
|
217
|
|
- public void testModeSendOptimisation1() {
|
218
|
|
- final TestParser parser = new TestParser();
|
219
|
|
- final ChannelInfo info = getChannel(parser);
|
220
|
|
-
|
221
|
|
- parser.sentLines.clear();
|
222
|
|
- info.alterMode(true, 'i', null);
|
223
|
|
- info.alterMode(true, 'm', null);
|
224
|
|
- info.alterMode(true, 'n', null);
|
225
|
|
- info.alterMode(true, 'n', null);
|
226
|
|
- info.alterMode(false, 'i', null);
|
227
|
|
- info.flushModes();
|
228
|
|
-
|
229
|
|
- assertEquals("sendModes must send modes in one go",
|
230
|
|
- 1, parser.sentLines.size());
|
231
|
|
-
|
232
|
|
- final String modes = getModes(parser.sentLines.get(0));
|
233
|
|
-
|
234
|
|
- assertEquals("Setting a negative mode should cancel a positive one",
|
235
|
|
- -1, modes.indexOf('i'));
|
236
|
|
-
|
237
|
|
- assertTrue(modes.indexOf('m') > -1);
|
238
|
|
- }
|
239
|
|
-
|
240
|
|
- @Test
|
241
|
|
- public void testModeSendOptimisation2() {
|
242
|
|
- final TestParser parser = new TestParser();
|
243
|
|
- final ChannelInfo info = getChannel(parser);
|
244
|
|
-
|
245
|
|
- parser.sentLines.clear();
|
246
|
|
- info.alterMode(true, 'm', null);
|
247
|
|
- info.alterMode(true, 'n', null);
|
248
|
|
- info.alterMode(true, 'n', null);
|
249
|
|
- info.flushModes();
|
250
|
|
-
|
251
|
|
- assertEquals("sendModes must send modes in one go",
|
252
|
|
- 1, parser.sentLines.size());
|
253
|
|
-
|
254
|
|
- final String modes = getModes(parser.sentLines.get(0));
|
255
|
|
-
|
256
|
|
- assertEquals("Setting a mode twice should have no effect",
|
257
|
|
- modes.indexOf('n'), modes.lastIndexOf('n'));
|
258
|
|
-
|
259
|
|
- assertTrue(modes.indexOf('m') > -1);
|
260
|
|
- }
|
261
|
|
-
|
262
|
|
- @Test
|
263
|
|
- public void testModeUnsetKey() {
|
264
|
|
- final TestParser parser = new TestParser();
|
265
|
|
- final ChannelInfo info = getChannel(parser);
|
266
|
|
- parser.injectLine(":server 324 nick #DMDirc_testing +k lalala");
|
267
|
|
- parser.sentLines.clear();
|
268
|
|
-
|
269
|
|
- info.alterMode(true, 'k', "foobar");
|
270
|
|
- info.flushModes();
|
271
|
|
-
|
272
|
|
- assertEquals("sendModes must send modes in one go",
|
273
|
|
- 1, parser.sentLines.size());
|
274
|
|
- assertEquals("Setting +k must set -k first",
|
275
|
|
- "-k+k lalala foobar", getModes(parser.sentLines.get(0)));
|
276
|
|
- }
|
277
|
|
-
|
278
|
|
- @Test
|
279
|
|
- public void testIssue1410() {
|
280
|
|
- final TestParser parser = new TestParser();
|
281
|
|
-
|
282
|
|
- parser.injectConnectionStrings();
|
283
|
|
- parser.injectLine(":nick JOIN #DMDirc_testing");
|
284
|
|
- parser.injectLine(":foo!bar@baz JOIN #DMDirc_testing");
|
285
|
|
- parser.injectLine(":flub!floo@fleeee JOIN #DMDirc_testing");
|
286
|
|
-
|
287
|
|
- assertNotSame(parser.getChannel("#DMDirc_testing").getChannelClients(),
|
288
|
|
- parser.getChannel("#DMDirc_testing").getChannelClients());
|
289
|
|
- assertEquals(parser.getChannel("#DMDirc_testing").getChannelClients(),
|
290
|
|
- parser.getChannel("#DMDirc_testing").getChannelClients());
|
291
|
|
- }
|
292
|
|
-
|
293
|
|
- @Test @Ignore
|
294
|
|
- public void testModeUnsetKeyMultiple() {
|
295
|
|
- final TestParser parser = new TestParser();
|
296
|
|
- final ChannelInfo info = getChannel(parser);
|
297
|
|
- parser.injectLine(":server 324 nick #DMDirc_testing +k lalala");
|
298
|
|
- parser.sentLines.clear();
|
299
|
|
-
|
300
|
|
- info.alterMode(true, 'k', "foobar");
|
301
|
|
- info.alterMode(true, 'k', "blahblah");
|
302
|
|
- info.alterMode(true, 'k', "unittest");
|
303
|
|
- info.flushModes();
|
304
|
|
-
|
305
|
|
- assertEquals("sendModes must send modes in one go",
|
306
|
|
- 1, parser.sentLines.size());
|
307
|
|
- assertEquals("Setting a mode multiple times should have no effect",
|
308
|
|
- "-k+k lalala unittest", getModes(parser.sentLines.get(0)));
|
309
|
|
- }
|
310
|
|
-
|
311
|
|
- @Test @Ignore
|
312
|
|
- public void testModeUnsetLimitMultiple() {
|
313
|
|
- final TestParser parser = new TestParser();
|
314
|
|
- final ChannelInfo info = getChannel(parser);
|
315
|
|
- parser.injectLine(":server 324 nick #DMDirc_testing +l 73");
|
316
|
|
- parser.sentLines.clear();
|
317
|
|
-
|
318
|
|
- info.alterMode(true, 'l', "74");
|
319
|
|
- info.alterMode(true, 'l', "75");
|
320
|
|
- info.alterMode(true, 'l', "76");
|
321
|
|
- info.flushModes();
|
322
|
|
-
|
323
|
|
- assertEquals("sendModes must send modes in one go",
|
324
|
|
- 1, parser.sentLines.size());
|
325
|
|
- assertEquals("Setting a mode multiple times should have no effect",
|
326
|
|
- "+l 76", getModes(parser.sentLines.get(0)));
|
327
|
|
- }
|
328
|
|
-
|
329
|
|
- private String getModes(final String line) {
|
330
|
|
- final String res = line.substring("MODE #DMDirc_testing ".length());
|
331
|
|
-
|
332
|
|
- if (res.charAt(0) == '+') {
|
333
|
|
- return res.substring(1);
|
334
|
|
- }
|
335
|
|
-
|
336
|
|
- return res;
|
337
|
|
- }
|
338
|
|
-
|
339
|
|
- private IRCChannelInfo getChannel(final TestParser parser) {
|
340
|
|
- parser.injectConnectionStrings();
|
341
|
|
- parser.injectLine(":nick JOIN #DMDirc_testing");
|
342
|
|
-
|
343
|
|
- parser.sentLines.clear();
|
344
|
|
- return parser.getChannels().iterator().next();
|
345
|
|
- }
|
346
|
|
-
|
347
|
|
-}
|