Kaynağa Gözat

Add tests

tags/0.6.3
Shane Mc Cormack 15 yıl önce
ebeveyn
işleme
7f07e023bd

+ 128
- 0
test/com/dmdirc/parser/common/IgnoreListTest.java Dosyayı Görüntüle

@@ -0,0 +1,128 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.common;
24
+
25
+import java.util.ArrayList;
26
+import java.util.Arrays;
27
+import java.util.List;
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+
32
+public class IgnoreListTest {
33
+    
34
+    private final String[][] tests = {
35
+        {"a@b.c", "a@b\\.c"},
36
+        {"*chris*", ".*chris.*"},
37
+        {"c???s", "c...s"},
38
+        {"c*?*", "c.*..*"},
39
+        {"foo?", "foo."},
40
+        {".^$[]\\(){}|+", "\\.\\^\\$\\[\\]\\\\\\(\\)\\{\\}\\|\\+"},
41
+    }; 
42
+    
43
+    private final String[] illegals = {
44
+        "a+",
45
+        "a*",
46
+        "a.{4}",
47
+        "a|b",
48
+        "a?",
49
+        "foo\\",
50
+        "a\\?",
51
+        "a\\*",
52
+    };
53
+
54
+    @Test
55
+    public void testToRegex() {
56
+        for (String[] test : tests) {
57
+            final String convert1 = IgnoreList.simpleToRegex(test[0]);
58
+            assertEquals(test[1], convert1);
59
+        }
60
+    }
61
+    
62
+    @Test
63
+    public void testToSimple() {
64
+        for (String[] test : tests) {
65
+            final String convert2 = IgnoreList.regexToSimple(test[1]);
66
+            assertEquals(test[0], convert2);
67
+        }
68
+    }    
69
+    
70
+    @Test
71
+    public void testIllegals() {
72
+        for (String test : illegals) {
73
+            boolean except = false;
74
+            
75
+            try {
76
+                String converted = IgnoreList.regexToSimple(test);
77
+            } catch (UnsupportedOperationException ex) {
78
+                except = true;
79
+            }
80
+            
81
+            assertTrue(except);
82
+        }
83
+    }
84
+    
85
+    @Test
86
+    public void testConstructor() {
87
+        final List<String> items = Arrays.asList(new String[]{"abc", "def"});
88
+        final IgnoreList list = new IgnoreList(items);
89
+        
90
+        assertEquals(items, list.getRegexList());
91
+    }
92
+    
93
+    @Test
94
+    public void testAddSimple() {
95
+        final IgnoreList list = new IgnoreList();
96
+        
97
+        for (String[] test : tests) {
98
+            list.addSimple(test[0]);
99
+            assertTrue(list.getRegexList().contains(test[1]));
100
+        }
101
+    }
102
+    
103
+    @Test
104
+    public void testCanConvert() {
105
+        final IgnoreList list = new IgnoreList();
106
+        assertTrue(list.canConvert());
107
+        
108
+        list.addSimple("abc!def@ghi");
109
+        assertTrue(list.canConvert());
110
+        
111
+        list.add(illegals[0]);
112
+        assertFalse(list.canConvert());
113
+    }
114
+    
115
+    @Test
116
+    public void testGetSimpleList() throws UnsupportedOperationException {
117
+        final IgnoreList list = new IgnoreList();
118
+        final List<String> items = new ArrayList<String>();
119
+        
120
+        for (String[] test : tests) {
121
+            items.add(test[0]);
122
+            list.add(test[1]);
123
+        }
124
+        
125
+        assertEquals(items, list.getSimpleList());
126
+    }
127
+    
128
+}

+ 102
- 0
test/com/dmdirc/parser/irc/ChannelClientInfoTest.java Dosyayı Görüntüle

@@ -0,0 +1,102 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+
27
+import java.util.HashMap;
28
+import java.util.Map;
29
+import org.junit.Test;
30
+import static org.junit.Assert.*;
31
+
32
+public class ChannelClientInfoTest {
33
+        
34
+    @Test
35
+    public void testImportantMode() {
36
+        final TestParser parser = new TestParser();
37
+
38
+        parser.injectConnectionStrings();
39
+        parser.injectLine(":nick JOIN #DMDirc_testing");
40
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
41
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
42
+
43
+        final IRCChannelClientInfo cci = parser.getClient("luser").getChannelClients().get(0);
44
+
45
+        assertEquals("v", cci.getImportantMode());
46
+        assertEquals("+", cci.getImportantModePrefix());
47
+        assertEquals("+luser", cci.toString());
48
+        assertEquals("+luser", cci.toFullString());
49
+        final long value = cci.getImportantModeValue();
50
+
51
+        parser.injectLine(":server MODE #DMDirc_testing +o luser");
52
+        assertEquals("o", cci.getImportantMode());
53
+        assertEquals("@", cci.getImportantModePrefix());
54
+        assertEquals("@luser", cci.toString());
55
+        assertEquals("@+luser", cci.toFullString());
56
+        assertTrue(cci.getImportantModeValue() > value);
57
+
58
+        parser.injectLine(":server MODE #DMDirc_testing -ov luser luser");
59
+        assertEquals("", cci.getImportantMode());
60
+        assertEquals("", cci.getImportantModePrefix());
61
+        assertEquals("luser", cci.toString());
62
+        assertEquals("luser", cci.toFullString());
63
+        assertEquals(0l, cci.getImportantModeValue());
64
+    }
65
+    
66
+    @Test
67
+    public void testMap() {
68
+        final TestParser parser = new TestParser();
69
+
70
+        parser.injectConnectionStrings();
71
+        parser.injectLine(":nick JOIN #DMDirc_testing");
72
+        final Map<Object, Object> map1 = new HashMap<Object, Object>();
73
+        final Map<Object, Object> map2 = new HashMap<Object, Object>();
74
+        
75
+        final IRCChannelClientInfo cci = parser.getClient("nick").getChannelClients().get(0);
76
+        
77
+        cci.setMap(map1);
78
+        assertSame(map1, cci.getMap());
79
+        
80
+        cci.setMap(map2);
81
+        assertSame(map2, cci.getMap());
82
+    }
83
+    
84
+    @Test
85
+    public void testKick() {
86
+        final TestParser parser = new TestParser();
87
+
88
+        parser.injectConnectionStrings();
89
+        parser.injectLine(":nick JOIN #DMDirc_testing");
90
+        parser.sentLines.clear();
91
+        
92
+        parser.getClient("nick").getChannelClients().get(0).kick("");
93
+        assertEquals(1, parser.sentLines.size());
94
+        assertEquals("KICK #DMDirc_testing nick", parser.sentLines.get(0));
95
+        parser.sentLines.clear();
96
+        
97
+        parser.getClient("nick").getChannelClients().get(0).kick("booya");
98
+        assertEquals(1, parser.sentLines.size());
99
+        assertEquals("KICK #DMDirc_testing nick :booya", parser.sentLines.get(0));
100
+    }
101
+
102
+}

+ 358
- 0
test/com/dmdirc/parser/irc/ChannelInfoTest.java Dosyayı Görüntüle

@@ -0,0 +1,358 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+import java.util.HashMap;
28
+import java.util.Map;
29
+
30
+import org.junit.Ignore;
31
+import org.junit.Test;
32
+import static org.junit.Assert.*;
33
+
34
+public class ChannelInfoTest {
35
+
36
+    final IRCChannelInfo ci = new IRCChannelInfo(null, "name");
37
+
38
+    @Test
39
+    public void testGetName() {
40
+        assertEquals("name", ci.getName());
41
+    }
42
+
43
+    @Test
44
+    public void testAddingNames() {
45
+        assertTrue(ci.isAddingNames());
46
+
47
+        ci.setAddingNames(false);
48
+
49
+        assertFalse(ci.isAddingNames());
50
+    }
51
+
52
+    @Test
53
+    public void testMap() {
54
+        final Map map = new HashMap();
55
+
56
+        ci.setMap(map);
57
+
58
+        assertEquals(map, ci.getMap());
59
+    }
60
+
61
+    @Test
62
+    public void testCreateTime() {
63
+        ci.setCreateTime(12345l);
64
+
65
+        assertEquals(12345l, ci.getCreateTime());
66
+    }
67
+
68
+    @Test
69
+    public void testTopicTime() {
70
+        ci.setTopicTime(12345l);
71
+
72
+        assertEquals(12345l, ci.getTopicTime());
73
+    }
74
+
75
+    @Test
76
+    public void testTopic() {
77
+        ci.setInternalTopic("abcdef");
78
+
79
+        assertEquals("abcdef", ci.getTopic());
80
+    }
81
+
82
+    @Test
83
+    public void testSendMessage() {
84
+        final TestParser parser = new TestParser();
85
+        getChannel(parser).sendMessage("hello");
86
+
87
+        assertEquals("PRIVMSG #DMDirc_testing :hello", parser.sentLines.get(0));
88
+    }
89
+
90
+    @Test
91
+    public void testSendNotice() {
92
+        final TestParser parser = new TestParser();
93
+        getChannel(parser).sendNotice("hello");
94
+
95
+        assertEquals("NOTICE #DMDirc_testing :hello", parser.sentLines.get(0));
96
+    }
97
+
98
+    @Test
99
+    public void testSendCTCP() {
100
+        final TestParser parser = new TestParser();
101
+        getChannel(parser).sendCTCP("type", "hello");
102
+
103
+        assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "TYPE hello" + ((char) 1),
104
+                parser.sentLines.get(0));
105
+    }
106
+
107
+    @Test
108
+    public void testSendCTCPEmpty() {
109
+        final TestParser parser = new TestParser();
110
+        getChannel(parser).sendCTCP("type", "");
111
+
112
+        assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "TYPE" + ((char) 1),
113
+                parser.sentLines.get(0));
114
+    }
115
+
116
+    @Test
117
+    public void testSendAction() {
118
+        final TestParser parser = new TestParser();
119
+        getChannel(parser).sendAction("moo");
120
+
121
+        assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "ACTION moo" + ((char) 1),
122
+                parser.sentLines.get(0));
123
+    }
124
+
125
+    @Test
126
+    public void testSendCTCPReply() {
127
+        final TestParser parser = new TestParser();
128
+        getChannel(parser).sendCTCPReply("type", "moo");
129
+
130
+        assertEquals("NOTICE #DMDirc_testing :" + ((char) 1) + "TYPE moo" + ((char) 1),
131
+                parser.sentLines.get(0));
132
+    }
133
+
134
+    @Test
135
+    public void testSendCTCPReplyEmpty() {
136
+        final TestParser parser = new TestParser();
137
+        getChannel(parser).sendCTCPReply("type", "");
138
+
139
+        assertEquals("NOTICE #DMDirc_testing :" + ((char) 1) + "TYPE" + ((char) 1),
140
+                parser.sentLines.get(0));
141
+    }
142
+    
143
+    @Test
144
+    public void testSendEmptyMessages() {
145
+        final TestParser parser = new TestParser();
146
+        final IRCChannelInfo info = getChannel(parser);
147
+        
148
+        info.sendAction("");
149
+        info.sendCTCP("", "");
150
+        info.sendCTCPReply("", "");
151
+        info.sendMessage("");
152
+        info.sendNotice("");
153
+
154
+        assertEquals(0, parser.sentLines.size());
155
+    }
156
+    
157
+    @Test
158
+    public void testGetSetParamMode() {
159
+        final TestParser parser = new TestParser();
160
+        final ChannelInfo info = getChannel(parser);
161
+        parser.injectLine(":server 324 nick #DMDirc_testing +k lalala");
162
+        parser.sentLines.clear();
163
+        
164
+        assertEquals("lalala", info.getMode('k'));
165
+        assertEquals("", info.getMode('z'));
166
+        
167
+        parser.injectLine(":server MODE #DMDirc_testing -k *");
168
+        
169
+        assertEquals("", info.getMode('k'));
170
+    }
171
+    
172
+    @Test
173
+    public void testModeSendFull() {
174
+        final TestParser parser = new TestParser();
175
+        final ChannelInfo info = getChannel(parser);
176
+
177
+        parser.sentLines.clear();
178
+        info.alterMode(true, 'i', null);
179
+        info.alterMode(true, 'm', null);
180
+        info.alterMode(true, 'n', null);
181
+        info.alterMode(true, 'p', null);
182
+        info.alterMode(true, 't', null);
183
+        info.alterMode(true, 'r', null);
184
+        
185
+        assertEquals("Parser must send modes as soon as the max number is reached",
186
+                1, parser.sentLines.size());
187
+        final String modes = getModes(parser.sentLines.get(0));
188
+        
189
+        assertTrue(modes.indexOf('i') > -1);
190
+        assertTrue(modes.indexOf('m') > -1);
191
+        assertTrue(modes.indexOf('n') > -1);
192
+        assertTrue(modes.indexOf('p') > -1);
193
+        assertTrue(modes.indexOf('t') > -1);
194
+        assertTrue(modes.indexOf('r') > -1);
195
+    }
196
+    
197
+    @Test
198
+    public void testModeSendExtra() {
199
+        final TestParser parser = new TestParser();
200
+        final ChannelInfo info = getChannel(parser);
201
+
202
+        parser.sentLines.clear();
203
+        info.alterMode(true, 'i', null);
204
+        info.alterMode(true, 'm', null);
205
+        info.alterMode(true, 'n', null);
206
+        info.alterMode(true, 'p', null);
207
+        info.alterMode(true, 't', null);
208
+        info.alterMode(true, 'r', null);
209
+        info.alterMode(true, 'N', null);
210
+        info.flushModes();
211
+        
212
+        assertEquals("sendModes must send modes",
213
+                2, parser.sentLines.size());
214
+        
215
+        final String modes = getModes(parser.sentLines.get(0))
216
+                + getModes(parser.sentLines.get(1));
217
+        
218
+        assertTrue(modes.indexOf('i') > -1);
219
+        assertTrue(modes.indexOf('m') > -1);
220
+        assertTrue(modes.indexOf('n') > -1);
221
+        assertTrue(modes.indexOf('p') > -1);
222
+        assertTrue(modes.indexOf('t') > -1);
223
+        assertTrue(modes.indexOf('r') > -1);
224
+        assertTrue(modes.indexOf('N') > -1);
225
+    }
226
+    
227
+    @Test
228
+    public void testModeSendOptimisation1() {
229
+        final TestParser parser = new TestParser();
230
+        final ChannelInfo info = getChannel(parser);
231
+
232
+        parser.sentLines.clear();
233
+        info.alterMode(true, 'i', null);
234
+        info.alterMode(true, 'm', null);
235
+        info.alterMode(true, 'n', null);
236
+        info.alterMode(true, 'n', null);
237
+        info.alterMode(false, 'i', null);
238
+        info.flushModes();
239
+        
240
+        assertEquals("sendModes must send modes in one go",
241
+                1, parser.sentLines.size());
242
+        
243
+        final String modes = getModes(parser.sentLines.get(0));
244
+        
245
+        assertEquals("Setting a negative mode should cancel a positive one",
246
+                -1, modes.indexOf('i'));
247
+        
248
+        assertTrue(modes.indexOf('m') > -1);
249
+    }
250
+    
251
+    @Test
252
+    public void testModeSendOptimisation2() {
253
+        final TestParser parser = new TestParser();
254
+        final ChannelInfo info = getChannel(parser);
255
+
256
+        parser.sentLines.clear();
257
+        info.alterMode(true, 'm', null);
258
+        info.alterMode(true, 'n', null);
259
+        info.alterMode(true, 'n', null);
260
+        info.flushModes();
261
+        
262
+        assertEquals("sendModes must send modes in one go",
263
+                1, parser.sentLines.size());
264
+        
265
+        final String modes = getModes(parser.sentLines.get(0));
266
+        
267
+        assertEquals("Setting a mode twice should have no effect",
268
+                modes.indexOf('n'), modes.lastIndexOf('n'));
269
+        
270
+        assertTrue(modes.indexOf('m') > -1);
271
+    }
272
+    
273
+    @Test
274
+    public void testModeUnsetKey() {
275
+        final TestParser parser = new TestParser();
276
+        final ChannelInfo info = getChannel(parser);
277
+        parser.injectLine(":server 324 nick #DMDirc_testing +k lalala");
278
+        parser.sentLines.clear();
279
+        
280
+        info.alterMode(true, 'k', "foobar");
281
+        info.flushModes();
282
+        
283
+        assertEquals("sendModes must send modes in one go",
284
+                1, parser.sentLines.size());
285
+        assertEquals("Setting +k must set -k first",
286
+                "-k+k lalala foobar", getModes(parser.sentLines.get(0)));
287
+    }
288
+    
289
+    @Test
290
+    public void testIssue1410() {
291
+        final TestParser parser = new TestParser();
292
+
293
+        parser.injectConnectionStrings();
294
+        parser.injectLine(":nick JOIN #DMDirc_testing");
295
+        parser.injectLine(":foo!bar@baz JOIN #DMDirc_testing");
296
+        parser.injectLine(":flub!floo@fleeee JOIN #DMDirc_testing");
297
+
298
+        assertNotSame(parser.getChannel("#DMDirc_testing").getChannelClients(),
299
+                parser.getChannel("#DMDirc_testing").getChannelClients());
300
+        assertEquals(parser.getChannel("#DMDirc_testing").getChannelClients(),
301
+                parser.getChannel("#DMDirc_testing").getChannelClients());
302
+    }
303
+    
304
+    @Test @Ignore
305
+    public void testModeUnsetKeyMultiple() {
306
+        final TestParser parser = new TestParser();
307
+        final ChannelInfo info = getChannel(parser);
308
+        parser.injectLine(":server 324 nick #DMDirc_testing +k lalala");
309
+        parser.sentLines.clear();
310
+        
311
+        info.alterMode(true, 'k', "foobar");
312
+        info.alterMode(true, 'k', "blahblah");
313
+        info.alterMode(true, 'k', "unittest");
314
+        info.flushModes();
315
+        
316
+        assertEquals("sendModes must send modes in one go",
317
+                1, parser.sentLines.size());
318
+        assertEquals("Setting a mode multiple times should have no effect",
319
+                "-k+k lalala unittest", getModes(parser.sentLines.get(0)));
320
+    }
321
+    
322
+    @Test @Ignore
323
+    public void testModeUnsetLimitMultiple() {
324
+        final TestParser parser = new TestParser();
325
+        final ChannelInfo info = getChannel(parser);
326
+        parser.injectLine(":server 324 nick #DMDirc_testing +l 73");
327
+        parser.sentLines.clear();
328
+        
329
+        info.alterMode(true, 'l', "74");
330
+        info.alterMode(true, 'l', "75");
331
+        info.alterMode(true, 'l', "76");
332
+        info.flushModes();
333
+        
334
+        assertEquals("sendModes must send modes in one go",
335
+                1, parser.sentLines.size());
336
+        assertEquals("Setting a mode multiple times should have no effect",
337
+                "+l 76", getModes(parser.sentLines.get(0)));
338
+    }
339
+    
340
+    private String getModes(final String line) {
341
+        final String res = line.substring("MODE #DMDirc_testing ".length());
342
+        
343
+        if (res.charAt(0) == '+') {
344
+            return res.substring(1);
345
+        }
346
+        
347
+        return res;
348
+    }
349
+
350
+    private IRCChannelInfo getChannel(final TestParser parser) {
351
+        parser.injectConnectionStrings();
352
+        parser.injectLine(":nick JOIN #DMDirc_testing");
353
+
354
+        parser.sentLines.clear();
355
+        return parser.getChannels().iterator().next();
356
+    }
357
+
358
+}

+ 128
- 0
test/com/dmdirc/parser/irc/ClientInfoTest.java Dosyayı Görüntüle

@@ -0,0 +1,128 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import java.util.HashMap;
26
+import java.util.Map;
27
+
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class ClientInfoTest {
32
+    
33
+    @Test
34
+    public void testMap() {
35
+        final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
36
+        final Map<Object, Object> map = new HashMap<Object, Object>();
37
+        
38
+        ci.setMap(map);
39
+        assertEquals(map, ci.getMap());
40
+    }
41
+    
42
+    @Test
43
+    public void testFake() {
44
+        final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
45
+        assertFalse(ci.isFake());
46
+        ci.setFake(true);
47
+        assertTrue(ci.isFake());
48
+        ci.setFake(false);
49
+        assertFalse(ci.isFake());
50
+    }
51
+    
52
+    @Test
53
+    public void testParseHost() {
54
+        final String string1 = ":nick!ident@host";
55
+        final String string2 = "nick";
56
+        final String string3 = ":nick@host";
57
+        
58
+        assertEquals("nick", IRCClientInfo.parseHost(string1));
59
+        assertEquals("nick", IRCClientInfo.parseHost(string2));
60
+        assertEquals("nick", IRCClientInfo.parseHost(string3));
61
+    }
62
+    
63
+    @Test
64
+    public void testParseHostFull() {
65
+        final String string1 = ":nick!ident@host";
66
+        final String string2 = "nick";
67
+        final String string3 = ":nick@host";
68
+        
69
+        assertEquals("nick", IRCClientInfo.parseHostFull(string1)[0]);
70
+        assertEquals("ident", IRCClientInfo.parseHostFull(string1)[1]);
71
+        assertEquals("host", IRCClientInfo.parseHostFull(string1)[2]);
72
+        
73
+        assertEquals("nick", IRCClientInfo.parseHostFull(string2)[0]);
74
+        assertEquals("nick", IRCClientInfo.parseHostFull(string3)[0]);
75
+        assertEquals("host", IRCClientInfo.parseHostFull(string3)[2]);
76
+    }
77
+    
78
+    @Test
79
+    public void testSetUserBits() {
80
+        final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
81
+        ci.setUserBits("nick2!ident2@host2", false);
82
+        
83
+        assertEquals("nick", ci.getNickname());
84
+        assertEquals("ident2", ci.getUsername());
85
+        assertEquals("host2", ci.getHostname());
86
+        
87
+        ci.setUserBits(":nick3@host3", true);
88
+        
89
+        assertEquals("nick3", ci.getNickname());
90
+        assertEquals("ident2", ci.getUsername());
91
+        assertEquals("host3", ci.getHostname());
92
+    }
93
+    
94
+    @Test
95
+    public void testToString() {
96
+        final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
97
+        assertEquals("nick!ident@host", ci.toString());
98
+    }
99
+    
100
+    @Test
101
+    public void testAwayState() {
102
+        final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
103
+        assertFalse(ci.getAwayState());
104
+        ci.setAwayState(true);
105
+        assertTrue(ci.getAwayState());
106
+    }
107
+    
108
+    @Test
109
+    public void testAwayReason() {
110
+        final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
111
+        ci.setAwayState(true);
112
+        ci.setAwayReason("away reason");
113
+        
114
+        assertEquals("away reason", ci.getAwayReason());
115
+        ci.setAwayState(false);
116
+        assertEquals("", ci.getAwayReason());
117
+    }
118
+    
119
+    @Test
120
+    public void testRealName() {
121
+        final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
122
+        ci.setRealName("abc def");
123
+        assertEquals("abc def", ci.getRealname());
124
+        ci.setRealName("abc 123 def");
125
+        assertEquals("abc 123 def", ci.getRealname());
126
+    }
127
+    
128
+}

+ 540
- 0
test/com/dmdirc/parser/irc/IRCParserTest.java Dosyayı Görüntüle

@@ -0,0 +1,540 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.parser.common.MyInfo;
26
+import com.dmdirc.parser.common.ChannelListModeItem;
27
+import com.dmdirc.parser.common.ParserError;
28
+import com.dmdirc.harness.parser.TestIPrivateCTCP;
29
+import com.dmdirc.harness.parser.TestParser;
30
+import com.dmdirc.harness.parser.TestIConnectError;
31
+import com.dmdirc.harness.parser.TestINoticeAuth;
32
+import com.dmdirc.harness.parser.TestINumeric;
33
+import com.dmdirc.harness.parser.TestIServerError;
34
+import com.dmdirc.harness.parser.TestIPost005;
35
+import com.dmdirc.harness.parser.TestIPrivateMessage;
36
+import com.dmdirc.harness.parser.TestIPrivateAction;
37
+import com.dmdirc.parser.interfaces.callbacks.AuthNoticeListener;
38
+import com.dmdirc.parser.common.CallbackNotFoundException;
39
+import com.dmdirc.parser.interfaces.callbacks.AwayStateListener;
40
+import com.dmdirc.parser.interfaces.callbacks.CallbackInterface;
41
+import com.dmdirc.parser.interfaces.callbacks.ChannelKickListener;
42
+
43
+import com.dmdirc.parser.interfaces.callbacks.ConnectErrorListener;
44
+import com.dmdirc.parser.interfaces.callbacks.ErrorInfoListener;
45
+import com.dmdirc.parser.interfaces.callbacks.NumericListener;
46
+import com.dmdirc.parser.interfaces.callbacks.Post005Listener;
47
+import com.dmdirc.parser.interfaces.callbacks.PrivateActionListener;
48
+import com.dmdirc.parser.interfaces.callbacks.PrivateCtcpListener;
49
+import com.dmdirc.parser.interfaces.callbacks.PrivateMessageListener;
50
+import com.dmdirc.parser.interfaces.callbacks.ServerErrorListener;
51
+import java.util.Arrays;
52
+import java.util.Collection;
53
+
54
+import javax.net.ssl.TrustManager;
55
+
56
+import org.junit.Ignore;
57
+import org.junit.Test;
58
+import static org.junit.Assert.*;
59
+import static org.mockito.Mockito.*;
60
+
61
+public class IRCParserTest {
62
+
63
+    private static interface TestCallback extends CallbackInterface { }
64
+
65
+    @Test
66
+    public void testIssue42() {
67
+        // Invalid callback names are silently ignored instead of raising exceptions
68
+        
69
+        boolean res = false;
70
+
71
+        try {
72
+            final IRCParser myParser = new IRCParser();
73
+            myParser.getCallbackManager().addCallback(TestCallback.class, mock(TestCallback.class));
74
+        } catch (CallbackNotFoundException ex) {
75
+            res = true;
76
+        }
77
+
78
+        assertTrue("addCallback() should throw exception for non-existant callbacks", res);
79
+    }
80
+
81
+    @Test
82
+    public void testIssue1674() {
83
+        // parser nick change error with dual 001
84
+        final ErrorInfoListener error = mock(ErrorInfoListener.class);
85
+
86
+        final TestParser myParser = new TestParser();
87
+        myParser.getCallbackManager().addCallback(ErrorInfoListener.class, error);
88
+        myParser.injectConnectionStrings();
89
+        myParser.nick = "nick2";
90
+        myParser.injectConnectionStrings();
91
+        myParser.injectLine(":nick2!ident@host NICK :nick");
92
+
93
+        verify(error, never()).onErrorInfo((IRCParser) anyObject(), (ParserError) anyObject());
94
+    }
95
+    
96
+    @Test
97
+    public void testProxyPortWithBindIP() {
98
+        final TestIConnectError tice = new TestIConnectError();
99
+        final ServerInfo si = new ServerInfo();
100
+        si.setProxyPort(155555);
101
+        si.setUseSocks(true);
102
+        
103
+        final IRCParser myParser = new IRCParser(si);
104
+        myParser.getCallbackManager().addCallback(ConnectErrorListener.class, tice);
105
+        myParser.setBindIP("0.0.0.0");
106
+        myParser.run();
107
+        
108
+        assertTrue("Using an invalid socks proxy port should raise a connect error event",
109
+                tice.error);
110
+    }
111
+
112
+    @Test
113
+    public void testTokeniser() {
114
+        final String line1 = "a b c d e";
115
+        final String line2 = "a b c :d e";
116
+        final String line3 = ":a b:c :d e";
117
+        final String line4 = null;
118
+
119
+        final String[] res1 = IRCParser.tokeniseLine(line1);
120
+        final String[] res2 = IRCParser.tokeniseLine(line2);
121
+        final String[] res3 = IRCParser.tokeniseLine(line3);
122
+        final String[] res4 = IRCParser.tokeniseLine(line4);
123
+
124
+        assertTrue(Arrays.equals(res1, new String[]{"a", "b", "c", "d", "e"}));
125
+        assertTrue(Arrays.equals(res2, new String[]{"a", "b", "c", "d e"}));
126
+        assertTrue(Arrays.equals(res3, new String[]{":a", "b:c", "d e"}));
127
+        assertTrue(Arrays.equals(res4, new String[]{""}));
128
+    }
129
+
130
+    @Test
131
+    public void testSendConnectionStrings1() {
132
+        final ServerInfo serverInfo = new ServerInfo("irc.testing.dmdirc", 6667, "");
133
+        final MyInfo myInfo = new MyInfo();
134
+        myInfo.setNickname("Nickname");
135
+        myInfo.setRealname("Real name");
136
+        myInfo.setUsername("Username");
137
+
138
+        final TestParser parser = new TestParser(myInfo, serverInfo);
139
+        parser.sendConnectionStrings();
140
+
141
+        assertEquals(2, parser.sentLines.size());
142
+
143
+        assertTrue("Should send nickname line",
144
+                Arrays.equals(parser.getLine(0), new String[]{"NICK", "Nickname"}));
145
+
146
+        final String[] userParts = parser.getLine(1);
147
+        assertEquals("First token should be USER", "USER", userParts[0]);
148
+        assertEquals("USER should contain username", myInfo.getUsername().toLowerCase(),
149
+                userParts[1].toLowerCase());
150
+        assertEquals("USER should contain server name", serverInfo.getHost(), userParts[3]);
151
+        assertEquals("USER should contain real name", "Real name", userParts[4]);
152
+    }
153
+
154
+    @Test
155
+    public void testSendConnectionStrings2() {
156
+        final ServerInfo serverInfo = new ServerInfo("irc.testing.dmdirc", 6667, "password");
157
+        final MyInfo myInfo = new MyInfo();
158
+        myInfo.setNickname("Nickname");
159
+        myInfo.setRealname("Real name");
160
+        myInfo.setUsername("Username");
161
+
162
+        final TestParser parser = new TestParser(myInfo, serverInfo);
163
+        parser.sendConnectionStrings();
164
+
165
+        assertEquals(3, parser.sentLines.size());
166
+
167
+        assertTrue("Should send password line",
168
+                Arrays.equals(parser.getLine(0), new String[]{"PASS", "password"}));
169
+    }
170
+
171
+    @Test
172
+    public void testPingPong() {
173
+        final TestParser parser = new TestParser();
174
+
175
+        parser.injectLine("PING :flubadee7291");
176
+
177
+        assertTrue("Should reply to PINGs with PONGs",
178
+                Arrays.equals(parser.getLine(0), new String[]{"PONG", "flubadee7291"}));
179
+    }
180
+
181
+    @Test
182
+    public void testError() throws CallbackNotFoundException {
183
+        final TestIServerError test = new TestIServerError();
184
+
185
+        final TestParser parser = new TestParser();
186
+        parser.getCallbackManager().addCallback(ServerErrorListener.class, test);
187
+        parser.injectLine("ERROR :You smell of cheese");
188
+
189
+        assertNotNull(test.message);
190
+        assertEquals("ERROR message should be passed to callback",
191
+                "You smell of cheese", test.message);
192
+    }
193
+
194
+    @Test
195
+    public void testAuthNotices() throws CallbackNotFoundException {
196
+        final TestINoticeAuth test = new TestINoticeAuth();
197
+        final TestParser parser = new TestParser();
198
+        parser.getCallbackManager().addCallback(AuthNoticeListener.class, test);
199
+        parser.sendConnectionStrings();
200
+        parser.injectLine("NOTICE AUTH :Random auth notice?");
201
+
202
+        assertNotNull(test.message);
203
+        assertEquals("Random auth notice?", test.message);
204
+
205
+        test.message = null;
206
+
207
+        parser.injectLine(":us.ircnet.org 020 * :Stupid notice");
208
+
209
+        assertNotNull(test.message);
210
+        assertEquals("Stupid notice", test.message);
211
+    }
212
+
213
+    @Test
214
+    public void testPre001NickChange() throws CallbackNotFoundException {
215
+        final TestINoticeAuth test = new TestINoticeAuth();
216
+        final TestParser parser = new TestParser();
217
+        parser.getCallbackManager().addCallback(AuthNoticeListener.class, test);
218
+        parser.sendConnectionStrings();
219
+        parser.injectLine(":chris!@ NICK :user2");
220
+
221
+        assertNull(test.message);
222
+    }
223
+
224
+    @Test
225
+    public void testNumeric() throws CallbackNotFoundException {
226
+        final TestINumeric test = new TestINumeric();
227
+        final TestParser parser = new TestParser();
228
+        parser.getCallbackManager().addCallback(NumericListener.class, test);
229
+
230
+        parser.injectLine(":server 001 nick :Hi there, nick");
231
+
232
+        assertEquals(1, test.numeric);
233
+        assertTrue(Arrays.equals(new String[]{":server", "001", "nick", "Hi there, nick"},
234
+                test.data));
235
+    }
236
+
237
+    @Test
238
+    public void testPost005() throws CallbackNotFoundException {
239
+        final TestIPost005 test = new TestIPost005();
240
+        final TestParser parser = new TestParser();
241
+        parser.getCallbackManager().addCallback(Post005Listener.class, test);
242
+
243
+        final String[] strings = {
244
+            "NOTICE AUTH :Blah, blah",
245
+            ":server 020 * :Blah! Blah!",
246
+            ":server 001 nick :Welcome to the Testing IRC Network, nick",
247
+            ":server 002 nick :Your host is server.net, running version foo",
248
+            "NOTICE AUTH :I'm a retarded server",
249
+            ":server 003 nick :This server was created Sun Jan 6 2008 at 17:34:54 CET",
250
+            ":server 004 nick server.net foo dioswkgxRXInP biklmnopstvrDcCNuMT bklov",
251
+            ":server 005 nick WHOX WALLCHOPS WALLVOICES USERIP :are supported by this server",
252
+            ":server 005 nick MAXNICKLEN=15 TOPICLEN=250 AWAYLEN=160 :are supported " +
253
+                    "by this server",
254
+            ":server 375 nick :zomg, motd!",
255
+        };
256
+
257
+        for (String string : strings) {
258
+            assertFalse("OnPost005 fired too early", test.done);
259
+            parser.injectLine(string);
260
+        }
261
+
262
+        assertTrue("OnPost005 not fired", test.done);
263
+    }
264
+
265
+    @Test
266
+    public void test005Parsing() {
267
+        final TestParser parser = new TestParser();
268
+
269
+        final String[] strings = {
270
+            ":server 001 nick :Welcome to the Testing IRC Network, nick",
271
+            ":server 002 nick :Your host is server.net, running version foo",
272
+            ":server 003 nick :This server was created Sun Jan 6 2008 at 17:34:54 CET",
273
+            ":server 004 nick server.net foo dioswkgxRXInP biklmnopstvrDcCNuMT bklov",
274
+            ":server 005 nick WHOX WALLCHOPS WALLVOICES NETWORK=moo :are supported by" +
275
+                    " this server",
276
+            ":server 005 nick MAXNICKLEN=15 MAXLIST=b:10,e:22,I:45 :are supported by" +
277
+                    " this server",
278
+            ":server 375 nick :zomg, motd!",
279
+        };
280
+
281
+        for (String string : strings) {
282
+            parser.injectLine(string);
283
+        }
284
+
285
+        assertEquals(10, parser.getMaxListModes('b'));
286
+        assertEquals(22, parser.getMaxListModes('e'));
287
+        assertEquals(45, parser.getMaxListModes('I'));
288
+        assertEquals("getMaxListModes should return 0 for unknowns;", 0,
289
+                parser.getMaxListModes('z'));
290
+        assertEquals("moo", parser.getNetworkName());
291
+        assertEquals("server", parser.getServerName());
292
+    }
293
+
294
+    @Test
295
+    public void testBindIP() {
296
+        final TestParser parser = new TestParser();
297
+
298
+        parser.setBindIP("abc.def.ghi.123");
299
+        assertEquals("abc.def.ghi.123", parser.getBindIP());
300
+    }
301
+
302
+    @Test
303
+    public void testCreateFake() {
304
+        final TestParser parser = new TestParser();
305
+
306
+        parser.setCreateFake(false);
307
+        assertFalse(parser.getCreateFake());
308
+        parser.setCreateFake(true);
309
+        assertTrue(parser.getCreateFake());
310
+    }
311
+
312
+    @Test
313
+    public void testAutoListMode() {
314
+        final TestParser parser = new TestParser();
315
+
316
+        parser.setAutoListMode(false);
317
+        assertFalse(parser.getAutoListMode());
318
+        parser.setAutoListMode(true);
319
+        assertTrue(parser.getAutoListMode());
320
+    }
321
+
322
+    @Test
323
+    public void testRemoveAfterCallback() {
324
+        final TestParser parser = new TestParser();
325
+
326
+        parser.setRemoveAfterCallback(false);
327
+        assertFalse(parser.getRemoveAfterCallback());
328
+        parser.setRemoveAfterCallback(true);
329
+        assertTrue(parser.getRemoveAfterCallback());
330
+    }
331
+
332
+    @Test
333
+    public void testAddLastLine() {
334
+        final TestParser parser = new TestParser();
335
+
336
+        parser.setAddLastLine(false);
337
+        assertFalse(parser.getAddLastLine());
338
+        parser.setAddLastLine(true);
339
+        assertTrue(parser.getAddLastLine());
340
+    }
341
+
342
+    @Test
343
+    public void testDisconnectOnFatal() {
344
+        final TestParser parser = new TestParser();
345
+
346
+        parser.setDisconnectOnFatal(false);
347
+        assertFalse(parser.getDisconnectOnFatal());
348
+        parser.setDisconnectOnFatal(true);
349
+        assertTrue(parser.getDisconnectOnFatal());
350
+    }
351
+
352
+    @Test
353
+    public void testTrustManager() {
354
+        final TestParser parser = new TestParser();
355
+
356
+        assertTrue(Arrays.equals(parser.getDefaultTrustManager(), parser.getTrustManager()));
357
+
358
+        parser.setTrustManagers(new TrustManager[0]);
359
+
360
+        assertTrue(Arrays.equals(new TrustManager[0], parser.getTrustManager()));
361
+    }
362
+
363
+    @Test
364
+    public void testPrivateMessages() throws CallbackNotFoundException {
365
+        final TestParser parser = new TestParser();
366
+        final TestIPrivateMessage ipmtest = new TestIPrivateMessage();
367
+        final TestIPrivateAction ipatest = new TestIPrivateAction();
368
+        final TestIPrivateCTCP ipctest = new TestIPrivateCTCP();
369
+
370
+        parser.injectConnectionStrings();
371
+
372
+        parser.getCallbackManager().addCallback(PrivateMessageListener.class, ipmtest);
373
+        parser.getCallbackManager().addCallback(PrivateActionListener.class, ipatest);
374
+        parser.getCallbackManager().addCallback(PrivateCtcpListener.class, ipctest);
375
+
376
+        parser.injectLine(":a!b@c PRIVMSG nick :Hello!");
377
+        assertNotNull(ipmtest.host);
378
+        assertNull(ipatest.host);
379
+        assertNull(ipctest.host);
380
+        assertEquals("a!b@c", ipmtest.host);
381
+        assertEquals("Hello!", ipmtest.message);
382
+        ipmtest.host = null;
383
+        ipmtest.message = null;
384
+
385
+        parser.injectLine(":a!b@c PRIVMSG nick :" + ((char) 1) + "ACTION meep" + ((char) 1));
386
+        assertNull(ipmtest.host);
387
+        assertNotNull(ipatest.host);
388
+        assertNull(ipctest.host);
389
+        assertEquals("a!b@c", ipatest.host);
390
+        assertEquals("meep", ipatest.message);
391
+        ipatest.host = null;
392
+        ipatest.message = null;
393
+
394
+        parser.injectLine(":a!b@c PRIVMSG nick :" + ((char) 1) + "FOO meep" + ((char) 1));
395
+        assertNull(ipmtest.host);
396
+        assertNull(ipatest.host);
397
+        assertNotNull(ipctest.host);
398
+        assertEquals("a!b@c", ipctest.host);
399
+        assertEquals("FOO", ipctest.type);
400
+        assertEquals("meep", ipctest.message);
401
+    }
402
+
403
+    private void testListModes(String numeric1, String numeric2, char mode) {
404
+        final TestParser parser = new TestParser();
405
+        parser.injectConnectionStrings();
406
+
407
+        parser.injectLine(":nick JOIN #D");
408
+        parser.injectLine(":server " + numeric1 + " nick #D ban1!ident@.host bansetter1 1001");
409
+        parser.injectLine(":server " + numeric1 + " nick #D ban2!*@.host bansetter2 1002");
410
+        parser.injectLine(":server " + numeric1 + " nick #D ban3!ident@* bansetter3 1003");
411
+        parser.injectLine(":server " + numeric2 + " nick #D :End of Channel Something List");
412
+
413
+        final Collection<ChannelListModeItem> items
414
+                = parser.getChannel("#D").getListMode(mode);
415
+
416
+        assertEquals(3, items.size());
417
+        boolean gotOne = false, gotTwo = false, gotThree = false;
418
+
419
+        for (ChannelListModeItem item : items) {
420
+            if (item.getItem().equals("ban1!ident@.host")) {
421
+                assertEquals("bansetter1", item.getOwner());
422
+                assertEquals(1001l, item.getTime());
423
+                assertFalse(gotOne);
424
+                gotOne = true;
425
+            } else if (item.getItem().equals("ban2!*@.host")) {
426
+                assertEquals("bansetter2", item.getOwner());
427
+                assertEquals(1002l, item.getTime());
428
+                assertFalse(gotTwo);
429
+                gotTwo = true;
430
+            } else if (item.toString().equals("ban3!ident@*")) {
431
+                assertEquals("bansetter3", item.getOwner());
432
+                assertEquals(1003l, item.getTime());
433
+                assertFalse(gotThree);
434
+                gotThree = true;
435
+            }
436
+        }
437
+
438
+        assertTrue(gotOne);
439
+        assertTrue(gotTwo);
440
+        assertTrue(gotThree);
441
+    }
442
+
443
+    @Test
444
+    public void testNormalBans() {
445
+        testListModes("367", "368", 'b');
446
+    }
447
+
448
+    @Test
449
+    public void testInvexList() {
450
+        testListModes("346", "347", 'I');
451
+    }
452
+
453
+    @Test
454
+    public void testExemptList() {
455
+        testListModes("348", "349", 'e');
456
+    }
457
+
458
+    @Test
459
+    public void testReopList() {
460
+        testListModes("344", "345", 'R');
461
+    }
462
+
463
+    @Test
464
+    public void testGetParam() {
465
+        assertEquals("abc def", TestParser.getParam("foo :abc def"));
466
+        assertEquals("bar :abc def", TestParser.getParam("foo :bar :abc def"));
467
+        assertEquals("abc def", TestParser.getParam("abc def"));
468
+    }
469
+    
470
+    @Test
471
+    public void testKick() throws CallbackNotFoundException {
472
+        final TestParser parser = new TestParser();
473
+        final ChannelKickListener ick = mock(ChannelKickListener.class);
474
+        parser.injectConnectionStrings();
475
+
476
+        parser.injectLine(":nick JOIN #D");
477
+        parser.getCallbackManager().addCallback(ChannelKickListener.class, ick, "#D");
478
+        parser.injectLine(":bar!me@moo KICK #D nick :Bye!");
479
+
480
+        verify(ick).onChannelKick(same(parser), (IRCChannelInfo) anyObject(),
481
+                (IRCChannelClientInfo) anyObject(), (IRCChannelClientInfo) anyObject(),
482
+                anyString(), anyString());
483
+    }
484
+
485
+    @Test
486
+    public void testIRCds() {
487
+        doIRCdTest("u2.10.12.10+snircd(1.3.4)", "snircd");
488
+        doIRCdTest("u2.10.12.12", "ircu");
489
+        doIRCdTest("hyperion-1.0.2b", "hyperion");
490
+        doIRCdTest("hybrid-7.2.3", "hybrid");
491
+        doIRCdTest("Unreal3.2.6", "unreal");
492
+        doIRCdTest("bahamut-1.8(04)", "bahamut");
493
+    }
494
+    
495
+    @Test
496
+    public void testIllegalPort1() {
497
+        final TestParser tp = new TestParser(new MyInfo(), new ServerInfo("127.0.0.1", 0, ""));
498
+        final TestIConnectError tiei = new TestIConnectError();
499
+        tp.getCallbackManager().addCallback(ConnectErrorListener.class, tiei);
500
+        tp.runSuper();
501
+        assertTrue(tiei.error);
502
+    }
503
+    
504
+    @Test
505
+    public void testIllegalPort2() {
506
+        final TestParser tp = new TestParser(new MyInfo(), new ServerInfo("127.0.0.1", 1, ""));
507
+        final TestIConnectError tiei = new TestIConnectError();
508
+        tp.getCallbackManager().addCallback(ConnectErrorListener.class, tiei);
509
+        tp.runSuper();
510
+        assertTrue(tiei.error);
511
+    }    
512
+    
513
+    @Test
514
+    public void testIllegalPort3() {
515
+        final TestParser tp = new TestParser(new MyInfo(), new ServerInfo("127.0.0.1", 65570, ""));
516
+        final TestIConnectError tiei = new TestIConnectError();
517
+        tp.getCallbackManager().addCallback(ConnectErrorListener.class, tiei);
518
+        tp.runSuper();
519
+        assertTrue(tiei.error);
520
+    }
521
+
522
+    private void doIRCdTest(final String ircd, final String expected) {
523
+        final TestParser parser = new TestParser();
524
+
525
+        String[] strings = {
526
+            ":server 001 nick :Welcome to the Testing IRC Network, nick",
527
+            ":server 002 nick :Your host is server.net, running version %s",
528
+            ":server 003 nick :This server was created Sun Jan 6 2008 at 17:34:54 CET",
529
+            ":server 004 nick server.net %s dioswkgxRXInP biklmnopstvrDcCNuMT bklov"
530
+        };
531
+
532
+        for (String line : strings) {
533
+            parser.injectLine(String.format(line, ircd));
534
+        }
535
+
536
+        assertEquals(ircd, parser.getServerSoftware());
537
+        assertEquals(expected.toLowerCase(), parser.getServerSoftwareType().toLowerCase());
538
+    }
539
+
540
+}

+ 86
- 0
test/com/dmdirc/parser/irc/IRCStringConverterTest.java Dosyayı Görüntüle

@@ -0,0 +1,86 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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 org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class IRCStringConverterTest {
28
+
29
+    @Test
30
+    public void testCaseConversion() {
31
+        final IRCParser asciiParser = new IRCParser();
32
+        asciiParser.updateCharArrays((byte) 0);
33
+
34
+        final IRCParser rfcParser = new IRCParser();
35
+        rfcParser.updateCharArrays((byte) 4);
36
+
37
+        final IRCParser strictParser = new IRCParser();
38
+        strictParser.updateCharArrays((byte) 3);
39
+
40
+        final String[][] testcases = {
41
+            {"12345", "12345", "12345", "12345"},
42
+            {"HELLO", "hello", "hello", "hello"},
43
+            {"^[[MOO]]^", "^[[moo]]^", "~{{moo}}~", "^{{moo}}^"},
44
+            {"«—»", "«—»", "«—»", "«—»"},
45
+        };
46
+
47
+        for (String[] testcase : testcases) {
48
+            final String asciiL = asciiParser.getStringConverter().toLowerCase(testcase[0]);
49
+            final String rfcL = rfcParser.getStringConverter().toLowerCase(testcase[0]);
50
+            final String strictL = strictParser.getStringConverter().toLowerCase(testcase[0]);
51
+
52
+            final String asciiU = asciiParser.getStringConverter().toUpperCase(testcase[1]);
53
+            final String rfcU = rfcParser.getStringConverter().toUpperCase(testcase[2]);
54
+            final String strictU = strictParser.getStringConverter().toUpperCase(testcase[3]);
55
+
56
+            assertEquals(testcase[1], asciiL);
57
+            assertEquals(testcase[2], rfcL);
58
+            assertEquals(testcase[3], strictL);
59
+
60
+            assertTrue(asciiParser.getStringConverter().equalsIgnoreCase(testcase[0], testcase[1]));
61
+            assertTrue(rfcParser.getStringConverter().equalsIgnoreCase(testcase[0], testcase[2]));
62
+            assertTrue(strictParser.getStringConverter().equalsIgnoreCase(testcase[0], testcase[3]));
63
+
64
+            assertEquals(testcase[0], asciiU);
65
+            assertEquals(testcase[0], rfcU);
66
+            assertEquals(testcase[0], strictU);
67
+        }
68
+    }
69
+    
70
+    @Test
71
+    public void testLimit() {
72
+        final IRCStringConverter ircsc = new IRCStringConverter((byte) 100);
73
+        
74
+        assertEquals(4, ircsc.getLimit());
75
+    }
76
+    
77
+    @Test
78
+    public void testEqualsNull() {
79
+        final IRCStringConverter ircsc = new IRCStringConverter((byte) 100);
80
+        
81
+        assertTrue(ircsc.equalsIgnoreCase(null, null));
82
+        assertFalse(ircsc.equalsIgnoreCase("null", null));
83
+        assertFalse(ircsc.equalsIgnoreCase(null, "null"));
84
+    }    
85
+
86
+}

+ 130
- 0
test/com/dmdirc/parser/irc/ParserErrorTest.java Dosyayı Görüntüle

@@ -0,0 +1,130 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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.parser.common.ParserError;
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class ParserErrorTest {
29
+
30
+    private final ParserError fatal = new ParserError(ParserError.ERROR_FATAL, "moo", "");
31
+    private final ParserError error = new ParserError(ParserError.ERROR_ERROR, "moo", "last line");
32
+    private final ParserError except = new ParserError(ParserError.ERROR_EXCEPTION, "moo", null);
33
+    private final ParserError warning = new ParserError(ParserError.ERROR_WARNING, "moo", "");
34
+    private final ParserError uwarning = new ParserError(ParserError.ERROR_WARNING
35
+            + ParserError.ERROR_USER, "moo", "");
36
+
37
+    @Test
38
+    public void testIsFatal() {
39
+        assertTrue(fatal.isFatal());
40
+        assertFalse(error.isFatal());
41
+        assertFalse(except.isFatal());
42
+        assertFalse(warning.isFatal());
43
+    }
44
+
45
+    @Test
46
+    public void testIsError() {
47
+        assertTrue(error.isError());
48
+        assertFalse(fatal.isError());
49
+        assertFalse(except.isError());
50
+        assertFalse(warning.isError());
51
+    }
52
+
53
+    @Test
54
+    public void testIsWarning() {
55
+        assertFalse(error.isWarning());
56
+        assertFalse(fatal.isWarning());
57
+        assertFalse(except.isWarning());
58
+        assertTrue(warning.isWarning());
59
+    }
60
+
61
+    @Test
62
+    public void testIsException() {
63
+        assertFalse(error.isException());
64
+        assertFalse(fatal.isException());
65
+        assertTrue(except.isException());
66
+        assertFalse(warning.isException());        
67
+    }
68
+
69
+    @Test
70
+    public void testHasLastLine() {
71
+        assertTrue(error.hasLastLine());
72
+        assertFalse(fatal.hasLastLine());
73
+        assertFalse(except.hasLastLine());
74
+        assertFalse(warning.hasLastLine());
75
+    }
76
+    
77
+    @Test
78
+    public void testGetLevel() {
79
+        assertEquals(ParserError.ERROR_ERROR, error.getLevel());
80
+        assertEquals(ParserError.ERROR_EXCEPTION, except.getLevel());
81
+        assertEquals(ParserError.ERROR_FATAL, fatal.getLevel());
82
+        assertEquals(ParserError.ERROR_WARNING, warning.getLevel());
83
+    }    
84
+    
85
+    @Test
86
+    public void testIsUser() {
87
+        assertTrue(uwarning.isUserError());
88
+        assertFalse(error.isUserError());
89
+        assertFalse(fatal.isUserError());
90
+        assertFalse(except.isUserError());
91
+        assertFalse(warning.isUserError());
92
+    }
93
+
94
+    @Test
95
+    public void testException() {
96
+        fatal.setException(new Exception("foo"));
97
+        
98
+        assertTrue(fatal.isException());
99
+        assertTrue(fatal.isFatal());
100
+        assertNotNull(fatal.getException());
101
+        assertEquals("foo", fatal.getException().getMessage());
102
+        
103
+        except.setException(new IllegalAccessException());
104
+        
105
+        assertTrue(except.isException());
106
+        assertFalse(except.isFatal());
107
+        assertFalse(except.isError());
108
+        assertFalse(except.isWarning());
109
+    }
110
+
111
+    @Test
112
+    public void testGetData() {
113
+        assertEquals("moo", except.getData());
114
+    }
115
+
116
+    @Test
117
+    public void testAppendData() {
118
+        final String origin = warning.getData();
119
+        warning.appendData("new data!");
120
+        
121
+        assertTrue(warning.getData().startsWith(origin));
122
+        assertTrue(warning.getData().indexOf("new data!") > -1);
123
+    }
124
+
125
+    @Test
126
+    public void testGetLastLine() {
127
+        assertEquals("last line", error.getLastLine());
128
+    }
129
+
130
+}

+ 48
- 0
test/com/dmdirc/parser/irc/Process001Test.java Dosyayı Görüntüle

@@ -0,0 +1,48 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import org.junit.Test;
27
+import static org.junit.Assert.*;
28
+
29
+public class Process001Test {
30
+       
31
+    @Test
32
+    public void testDuplicate001() {
33
+        final TestParser tp = new TestParser();
34
+        
35
+        assertTrue(tp.getLocalClient().isFake());
36
+        
37
+        tp.injectConnectionStrings();
38
+        
39
+        assertEquals("nick", tp.getLocalClient().getNickname());
40
+        assertFalse(tp.getLocalClient().isFake());
41
+        
42
+        tp.injectLine(":server 001 nick2 :Crazy second 001 for you, nick2");
43
+        
44
+        assertEquals("nick2", tp.getLocalClient().getNickname());
45
+        assertFalse(tp.getLocalClient().isFake());
46
+    }
47
+
48
+}

+ 74
- 0
test/com/dmdirc/parser/irc/Process004005Test.java Dosyayı Görüntüle

@@ -0,0 +1,74 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestIErrorInfo;
26
+import com.dmdirc.harness.parser.TestParser;
27
+import com.dmdirc.parser.interfaces.callbacks.ErrorInfoListener;
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class Process004005Test {
32
+    
33
+    private TestParser doCaseMappingTest(final String target, final int expected) {
34
+        final TestParser parser = new TestParser();
35
+        parser.injectConnectionStrings();
36
+        parser.injectLine(":server 005 nick CASEMAPPING=" + target
37
+                    + " :are supported by this server");
38
+        
39
+        assertEquals(expected, parser.getStringConverter().getLimit());
40
+        
41
+        return parser;
42
+    }
43
+    
44
+    @Test
45
+    public void testCaseMappingASCII() {
46
+        doCaseMappingTest("ascii", 0);
47
+        doCaseMappingTest("ASCII", 0);
48
+    }
49
+    
50
+    @Test
51
+    public void testCaseMappingRFC() {
52
+        doCaseMappingTest("rfc1459", 4);
53
+        doCaseMappingTest("RFC1459", 4);
54
+    }
55
+    
56
+    @Test
57
+    public void testCaseMappingStrict() {
58
+        doCaseMappingTest("strict-rfc1459", 3);
59
+        doCaseMappingTest("strict-RFC1459", 3);        
60
+    }
61
+    
62
+    @Test
63
+    public void testCaseMappingUnknown() {
64
+        final TestParser tp = doCaseMappingTest("rfc1459", 4);
65
+        final TestIErrorInfo tiei = new TestIErrorInfo();
66
+        
67
+        tp.getCallbackManager().addCallback(ErrorInfoListener.class, tiei);
68
+        
69
+        tp.injectLine(":server 005 nick CASEMAPPING=unknown :are supported by this server");
70
+        
71
+        assertTrue(tiei.error);
72
+    }
73
+
74
+}

+ 70
- 0
test/com/dmdirc/parser/irc/ProcessJoinTest.java Dosyayı Görüntüle

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestIChannelSelfJoin;
26
+import com.dmdirc.harness.parser.TestParser;
27
+import com.dmdirc.parser.common.CallbackNotFoundException;
28
+import com.dmdirc.parser.interfaces.callbacks.ChannelJoinListener;
29
+
30
+import com.dmdirc.parser.interfaces.callbacks.ChannelSelfJoinListener;
31
+import org.junit.Test;
32
+import static org.junit.Assert.*;
33
+import static org.mockito.Mockito.*;
34
+
35
+public class ProcessJoinTest {
36
+    
37
+    @Test
38
+    public void testSelfJoinChannel() throws CallbackNotFoundException {
39
+        final TestParser parser = new TestParser();
40
+        final TestIChannelSelfJoin test = new TestIChannelSelfJoin();
41
+
42
+        parser.injectConnectionStrings();
43
+        parser.getCallbackManager().addCallback(ChannelSelfJoinListener.class, test);
44
+        parser.injectLine(":nick JOIN #DMDirc_testing");
45
+
46
+        assertNotNull(test.channel);
47
+        assertEquals("#DMDirc_testing", test.channel.getName());
48
+        assertEquals("#DMDirc_testing", test.channel.toString());
49
+        assertSame(parser, test.channel.getParser());
50
+        assertEquals(1, parser.getChannels().size());
51
+        assertTrue(parser.getChannels().contains(test.channel));
52
+        assertEquals(test.channel, parser.getChannel("#DMDirc_testing"));
53
+    }
54
+    
55
+    @Test
56
+    public void testOtherJoinChannel() throws CallbackNotFoundException {
57
+        final TestParser parser = new TestParser();
58
+        final ChannelJoinListener test = mock(ChannelJoinListener.class);
59
+
60
+        parser.injectConnectionStrings();
61
+        parser.getCallbackManager().addCallback(ChannelJoinListener.class, test);
62
+        
63
+        parser.injectLine(":nick JOIN #DMDirc_testing");
64
+        parser.injectLine(":foo!bar@baz JOIN #DMDirc_testing");
65
+
66
+        verify(test).onChannelJoin(parser, parser.getChannel("#DMDirc_testing"),
67
+                parser.getClient("foo!bar@baz").getChannelClients().get(0));
68
+    }    
69
+
70
+}

+ 163
- 0
test/com/dmdirc/parser/irc/ProcessModeTest.java Dosyayı Görüntüle

@@ -0,0 +1,163 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.parser.common.CallbackNotFoundException;
27
+
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class ProcessModeTest {
32
+    
33
+    @Test
34
+    public void testBasicUmodes() throws CallbackNotFoundException {
35
+        final TestParser parser = new TestParser();
36
+
37
+        parser.injectConnectionStrings();
38
+
39
+        parser.injectLine(":server 221 nick iw");
40
+
41
+        assertTrue(parser.getLocalClient().getModes().indexOf('i') > -1);
42
+        assertTrue(parser.getLocalClient().getModes().indexOf('w') > -1);
43
+    }
44
+    
45
+    @Test
46
+    public void testAlteringUmodes() throws CallbackNotFoundException {
47
+        final TestParser parser = new TestParser();
48
+
49
+        parser.injectConnectionStrings();
50
+
51
+        parser.injectLine(":server 221 nick iw");
52
+        parser.injectLine(":server MODE nick :-iw+ox");
53
+
54
+        assertTrue(parser.getLocalClient().getModes().indexOf('o') > -1);
55
+        assertTrue(parser.getLocalClient().getModes().indexOf('x') > -1);
56
+        assertEquals(-1, parser.getLocalClient().getModes().indexOf('i'));
57
+        assertEquals(-1, parser.getLocalClient().getModes().indexOf('w'));
58
+    }
59
+    
60
+    @Test
61
+    public void testChannelUmodes() {
62
+        final TestParser parser = new TestParser();
63
+
64
+        parser.injectConnectionStrings();
65
+        parser.injectLine(":nick JOIN #DMDirc_testing");
66
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
67
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
68
+
69
+        final IRCChannelClientInfo cci = parser.getClient("luser").getChannelClients().get(0);
70
+
71
+        parser.injectLine(":server MODE #DMDirc_testing +v luser");
72
+        assertEquals("+", cci.getChanModeStr(true));
73
+
74
+        parser.injectLine(":server MODE #DMDirc_testing +o luser");
75
+        assertEquals("ov", cci.getChanModeStr(false));
76
+        assertEquals("@+", cci.getChanModeStr(true));
77
+
78
+        parser.injectLine(":server MODE #DMDirc_testing +bov moo luser luser");
79
+        assertEquals("ov", cci.getChanModeStr(false));
80
+
81
+        parser.injectLine(":server MODE #DMDirc_testing -bov moo luser luser");
82
+        assertEquals("", cci.getChanModeStr(false));
83
+        assertEquals("", cci.getChanModeStr(true));
84
+    }
85
+    
86
+    @Test
87
+    public void testUnknownUser1() {
88
+        final TestParser parser = new TestParser();
89
+
90
+        parser.injectConnectionStrings();
91
+        parser.injectLine(":nick JOIN #DMDirc_testing");
92
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
93
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
94
+
95
+        parser.injectLine(":luser!me@my MODE #DMDirc_testing +v :moo");
96
+        
97
+        assertNotNull(parser.getClient("moo"));
98
+        assertEquals(1, parser.getClient("moo").getChannelCount());
99
+        
100
+        final IRCChannelClientInfo cci = parser.getClient("moo").getChannelClients().get(0);
101
+        
102
+        assertEquals("+", cci.getChanModeStr(true));        
103
+        assertEquals("Parser should update ident when it sees a MODE line",
104
+                "me", parser.getClient("luser").getUsername());
105
+        assertEquals("Parser should update host when it sees a MODE line",
106
+                "my", parser.getClient("luser").getHostname());
107
+    }
108
+    
109
+    @Test
110
+    public void testUnknownUser2() {
111
+        final TestParser parser = new TestParser();
112
+
113
+        parser.injectConnectionStrings();
114
+        parser.injectLine(":nick JOIN #DMDirc_testing");
115
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
116
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
117
+        parser.injectLine(":nick JOIN #DMDirc_testing2");
118
+        parser.injectLine(":server 353 nick = #DMDirc_testing2 :@nick +moo");
119
+        parser.injectLine(":server 366 nick #DMDirc_testing2 :End of /NAMES list");        
120
+
121
+        parser.injectLine(":server MODE #DMDirc_testing +v moo");
122
+        
123
+        assertNotNull(parser.getClient("moo"));
124
+        assertEquals(2, parser.getClient("moo").getChannelCount());
125
+        
126
+        final IRCChannelClientInfo cci = parser.getClient("moo").getChannelClients().get(0);
127
+        
128
+        assertEquals("+", cci.getChanModeStr(true));        
129
+    }   
130
+    
131
+    @Test
132
+    public void testChannelModes() {
133
+        final TestParser parser = new TestParser();
134
+
135
+        parser.injectConnectionStrings();
136
+        parser.injectLine(":nick JOIN #DMDirc_testing");
137
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
138
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
139
+        parser.injectLine(":server 324 nick #DMDirc_testing +Zstnl 1234");
140
+
141
+        assertEquals("1234", parser.getChannel("#DMDirc_testing").getMode('l'));
142
+        
143
+        String modes = parser.getChannel("#DMDirc_testing").getModes().split(" ")[0];
144
+        assertEquals(6, modes.length());
145
+        assertEquals('+', modes.charAt(0));
146
+        assertTrue(modes.indexOf('Z') > -1);
147
+        assertTrue(modes.indexOf('s') > -1);
148
+        assertTrue(modes.indexOf('t') > -1);
149
+        assertTrue(modes.indexOf('n') > -1);
150
+        assertTrue(modes.indexOf('l') > -1);
151
+        
152
+        parser.injectLine(":server MODE #DMDirc_testing :-Z");
153
+        
154
+        modes = parser.getChannel("#DMDirc_testing").getModes().split(" ")[0];
155
+        assertEquals(5, modes.length());
156
+        assertEquals('+', modes.charAt(0));
157
+        assertTrue(modes.indexOf('s') > -1);
158
+        assertTrue(modes.indexOf('t') > -1);
159
+        assertTrue(modes.indexOf('n') > -1);
160
+        assertTrue(modes.indexOf('l') > -1);        
161
+    }
162
+
163
+}

+ 74
- 0
test/com/dmdirc/parser/irc/ProcessNamesTest.java Dosyayı Görüntüle

@@ -0,0 +1,74 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.harness.parser.TestIErrorInfo;
27
+import com.dmdirc.parser.common.CallbackNotFoundException;
28
+import com.dmdirc.parser.interfaces.callbacks.ErrorInfoListener;
29
+import org.junit.Test;
30
+import static org.junit.Assert.*;
31
+
32
+public class ProcessNamesTest {
33
+    
34
+    @Test
35
+    public void testExternalNames() throws CallbackNotFoundException {
36
+        final TestParser parser = new TestParser();
37
+        final TestIErrorInfo test = new TestIErrorInfo();
38
+        parser.injectConnectionStrings();
39
+        parser.getCallbackManager().addCallback(ErrorInfoListener.class, test);
40
+        
41
+        parser.injectLine(":server 366 nick #nonexistant :End of /NAMES list.");
42
+        
43
+        assertFalse("Should not error on unknown NAMES replies", test.error);
44
+    }
45
+    
46
+    @Test
47
+    public void testChannelUmodes() {
48
+        final TestParser parser = new TestParser();
49
+
50
+        parser.injectConnectionStrings();
51
+        parser.injectLine(":nick JOIN #DMDirc_testing");
52
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser @+nick2 nick3");
53
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
54
+
55
+        assertEquals(1, parser.getChannels().size());
56
+        assertNotNull(parser.getChannel("#DMDirc_testing"));
57
+        assertEquals(4, parser.getChannel("#DMDirc_testing").getChannelClients().size());
58
+        assertNotNull(parser.getClient("luser"));
59
+        assertEquals(1, parser.getClient("luser").getChannelClients().size());
60
+
61
+        IRCChannelClientInfo cci = parser.getClient("luser").getChannelClients().get(0);
62
+        assertEquals(parser.getChannel("#DMDirc_testing"), cci.getChannel());
63
+        assertEquals("+", cci.getChanModeStr(true));
64
+        
65
+        cci = parser.getChannel("#DMDirc_testing").getChannelClient("nick2");
66
+        assertNotNull(cci);
67
+        assertEquals("@+", cci.getChanModeStr(true));
68
+
69
+        cci = parser.getChannel("#DMDirc_testing").getChannelClient("nick3");
70
+        assertNotNull(cci);
71
+        assertEquals("", cci.getChanModeStr(true));
72
+    }
73
+
74
+}

+ 110
- 0
test/com/dmdirc/parser/irc/ProcessNickTest.java Dosyayı Görüntüle

@@ -0,0 +1,110 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.harness.parser.TestIErrorInfo;
27
+import com.dmdirc.harness.parser.TestINickChanged;
28
+import com.dmdirc.parser.interfaces.callbacks.ErrorInfoListener;
29
+import com.dmdirc.parser.interfaces.callbacks.NickChangeListener;
30
+import com.dmdirc.parser.common.CallbackNotFoundException;
31
+import org.junit.Test;
32
+import static org.junit.Assert.*;
33
+
34
+public class ProcessNickTest {
35
+    
36
+    @Test
37
+    public void testNickSameName() {
38
+        final TestParser parser = new TestParser();
39
+        final TestINickChanged tinc = new TestINickChanged();
40
+
41
+        parser.getCallbackManager().addCallback(NickChangeListener.class, tinc);
42
+        
43
+        parser.injectConnectionStrings();
44
+        parser.injectLine(":nick JOIN #DMDirc_testing");
45
+        parser.injectLine(":nick JOIN #DMDirc_testing2");
46
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser @+nick2 nick3");
47
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
48
+        parser.injectLine(":luser!lu@ser.com NICK LUSER");
49
+
50
+        assertNotNull(parser.getClient("LUSER"));
51
+        assertEquals(1, parser.getClient("LUSER").getChannelClients().size());
52
+
53
+        IRCChannelClientInfo cci = parser.getClient("LUSER").getChannelClients().get(0);
54
+        assertEquals(parser.getChannel("#DMDirc_testing"), cci.getChannel());
55
+        assertEquals("+", cci.getChanModeStr(true));
56
+        
57
+        assertSame(cci.getClient(), tinc.client);
58
+        assertEquals("luser", tinc.oldNick);
59
+    }
60
+    
61
+    @Test
62
+    public void testNickDifferent() {
63
+        final TestParser parser = new TestParser();
64
+
65
+        parser.injectConnectionStrings();
66
+        parser.injectLine(":nick JOIN #DMDirc_testing");
67
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser @+nick2 nick3");
68
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
69
+        parser.injectLine(":luser!lu@ser.com NICK foobar");
70
+
71
+        assertNotNull(parser.getClient("foobar"));
72
+        assertFalse(parser.isKnownClient("luser"));
73
+        assertEquals(1, parser.getClient("foobar").getChannelClients().size());
74
+
75
+        IRCChannelClientInfo cci = parser.getClient("foobar").getChannelClients().get(0);
76
+        assertEquals(parser.getChannel("#DMDirc_testing"), cci.getChannel());
77
+        assertEquals("+", cci.getChanModeStr(true));
78
+    }    
79
+    
80
+    @Test
81
+    public void testOverrideNick() throws CallbackNotFoundException {
82
+        final TestParser parser = new TestParser();
83
+        final TestIErrorInfo info = new TestIErrorInfo();
84
+        
85
+        parser.getCallbackManager().addCallback(ErrorInfoListener.class, info);
86
+        parser.injectConnectionStrings();
87
+        parser.injectLine(":nick JOIN #DMDirc_testing");
88
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser @+nick2 nick3");
89
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
90
+        parser.injectLine(":luser!lu@ser.com NICK nick3");
91
+
92
+        assertTrue("Parser should raise an error if a nick change overrides an "
93
+                + "existing client", info.error);
94
+    }
95
+    
96
+    @Test
97
+    public void testUnknownNick() {
98
+        final TestParser parser = new TestParser();
99
+        final TestINickChanged tinc = new TestINickChanged();
100
+        
101
+        parser.getCallbackManager().addCallback(NickChangeListener.class, tinc);
102
+        
103
+        parser.injectConnectionStrings();
104
+        parser.injectLine(":random!lu@ser NICK rand");
105
+        
106
+        assertNull(tinc.client);
107
+        assertNull(tinc.oldNick);
108
+    }
109
+
110
+}

+ 91
- 0
test/com/dmdirc/parser/irc/ProcessPartTest.java Dosyayı Görüntüle

@@ -0,0 +1,91 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.harness.parser.TestIChannelPart;
27
+import com.dmdirc.parser.common.CallbackNotFoundException;
28
+
29
+import com.dmdirc.parser.interfaces.callbacks.ChannelPartListener;
30
+import org.junit.Test;
31
+import static org.junit.Assert.*;
32
+
33
+public class ProcessPartTest {
34
+    
35
+    @Test
36
+    public void testNormalPart() throws CallbackNotFoundException {
37
+        final TestParser parser = new TestParser();
38
+
39
+        parser.injectConnectionStrings();
40
+
41
+        parser.injectLine(":nick JOIN #DMDirc_testing");
42
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
43
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list.");
44
+        
45
+        final TestIChannelPart test = new TestIChannelPart();
46
+        parser.getCallbackManager().addCallback(ChannelPartListener.class, test);
47
+        
48
+        assertEquals(2, parser.getChannel("#DMDirc_testing").getChannelClients().size());
49
+        
50
+        parser.injectLine(":luser!foo@barsville PART #DMDirc_testing :Bye bye, cruel world");
51
+        
52
+        assertEquals(1, parser.getChannel("#DMDirc_testing").getChannelClients().size());
53
+        
54
+        assertNotNull(test.channel);
55
+        assertNotNull(test.cclient);
56
+        assertNotNull(test.reason);
57
+        
58
+        assertEquals("#DMDirc_testing", test.channel.getName());
59
+        assertEquals("luser", test.cclient.getClient().getNickname());
60
+        assertEquals("Bye bye, cruel world", test.reason);
61
+    }
62
+    
63
+    @Test
64
+    public void testEmptyPart() throws CallbackNotFoundException {
65
+        final TestParser parser = new TestParser();
66
+
67
+        parser.injectConnectionStrings();
68
+
69
+        parser.injectLine(":nick JOIN #DMDirc_testing");
70
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
71
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list.");
72
+        
73
+        final TestIChannelPart test = new TestIChannelPart();
74
+        parser.getCallbackManager().addCallback(ChannelPartListener.class, test);
75
+        
76
+        assertEquals(2, parser.getChannel("#DMDirc_testing").getChannelClients().size());
77
+        
78
+        parser.injectLine(":luser!foo@barsville PART #DMDirc_testing");
79
+        
80
+        assertEquals(1, parser.getChannel("#DMDirc_testing").getChannelClients().size());
81
+        
82
+        assertNotNull(test.channel);
83
+        assertNotNull(test.cclient);
84
+        assertNotNull(test.reason);
85
+        
86
+        assertEquals("#DMDirc_testing", test.channel.getName());
87
+        assertEquals("luser", test.cclient.getClient().getNickname());
88
+        assertEquals("", test.reason);
89
+    }    
90
+
91
+}

+ 127
- 0
test/com/dmdirc/parser/irc/ProcessQuitTest.java Dosyayı Görüntüle

@@ -0,0 +1,127 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.harness.parser.TestIQuit;
27
+import com.dmdirc.parser.interfaces.callbacks.ChannelQuitListener;
28
+import com.dmdirc.parser.interfaces.callbacks.QuitListener;
29
+import com.dmdirc.parser.common.CallbackNotFoundException;
30
+
31
+import org.junit.Test;
32
+import static org.junit.Assert.*;
33
+
34
+public class ProcessQuitTest {
35
+    
36
+    @Test
37
+    public void testChannelQuit() throws CallbackNotFoundException {
38
+        final TestParser parser = new TestParser();
39
+
40
+        parser.injectConnectionStrings();
41
+
42
+        parser.injectLine(":nick JOIN #DMDirc_testing");
43
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
44
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list.");
45
+        parser.injectLine(":nick JOIN #DMDirc_testing2");
46
+        parser.injectLine(":server 353 nick = #DMDirc_testing2 :@nick +luser2");
47
+        parser.injectLine(":server 366 nick #DMDirc_testing2 :End of /NAMES list.");        
48
+        
49
+        final TestIQuit test = new TestIQuit();
50
+        parser.getCallbackManager().addCallback(ChannelQuitListener.class, test);
51
+        
52
+        assertEquals(2, parser.getChannel("#DMDirc_testing").getChannelClients().size());
53
+        
54
+        parser.injectLine(":luser!foo@barsville QUIT :Bye bye, cruel world");
55
+        
56
+        assertEquals(1, parser.getChannel("#DMDirc_testing").getChannelClients().size());
57
+        assertEquals(2, parser.getChannel("#DMDirc_testing2").getChannelClients().size());
58
+        
59
+        assertNotNull(test.channel);
60
+        assertNotNull(test.cclient);
61
+        assertNotNull(test.reason);
62
+        
63
+        assertEquals(1, test.count);
64
+        assertEquals("#DMDirc_testing", test.channel.getName());
65
+        assertEquals("luser", test.cclient.getClient().getNickname());
66
+        assertEquals("Bye bye, cruel world", test.reason);
67
+    }
68
+    
69
+    @Test
70
+    public void testGlobalQuit() throws CallbackNotFoundException {
71
+        final TestParser parser = new TestParser();
72
+
73
+        parser.injectConnectionStrings();
74
+
75
+        parser.injectLine(":nick JOIN #DMDirc_testing");
76
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
77
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list.");
78
+        parser.injectLine(":nick JOIN #DMDirc_testing2");
79
+        parser.injectLine(":server 353 nick = #DMDirc_testing2 :@nick +luser2");
80
+        parser.injectLine(":server 366 nick #DMDirc_testing2 :End of /NAMES list.");
81
+        
82
+        final TestIQuit test = new TestIQuit();
83
+        parser.getCallbackManager().addCallback(QuitListener.class, test);
84
+        
85
+        assertEquals(2, parser.getChannel("#DMDirc_testing").getChannelClients().size());
86
+        
87
+        parser.injectLine(":luser!foo@barsville QUIT :Bye bye, cruel world");
88
+        
89
+        assertEquals(1, parser.getChannel("#DMDirc_testing").getChannelClients().size());
90
+        assertEquals(2, parser.getChannel("#DMDirc_testing2").getChannelClients().size());
91
+        
92
+        assertNotNull(test.client);
93
+        assertNotNull(test.reason);
94
+        
95
+        assertEquals(1, test.count);
96
+        assertEquals("luser", test.client.getNickname());
97
+        assertEquals("Bye bye, cruel world", test.reason);
98
+    }
99
+    
100
+    @Test
101
+    public void testEmptyQuit() throws CallbackNotFoundException {
102
+        final TestParser parser = new TestParser();
103
+
104
+        parser.injectConnectionStrings();
105
+
106
+        parser.injectLine(":nick JOIN #DMDirc_testing");
107
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
108
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list.");
109
+        
110
+        final TestIQuit test = new TestIQuit();
111
+        parser.getCallbackManager().addCallback(QuitListener.class, test);
112
+        
113
+        assertEquals(2, parser.getChannel("#DMDirc_testing").getChannelClients().size());
114
+        
115
+        parser.injectLine(":luser!foo@barsville QUIT");
116
+        
117
+        assertEquals(1, parser.getChannel("#DMDirc_testing").getChannelClients().size());
118
+        
119
+        assertNotNull(test.client);
120
+        assertNotNull(test.reason);
121
+        
122
+        assertEquals(1, test.count);
123
+        assertEquals("luser", test.client.getNickname());
124
+        assertEquals("", test.reason);
125
+    }    
126
+
127
+}

+ 75
- 0
test/com/dmdirc/parser/irc/ProcessTopicTest.java Dosyayı Görüntüle

@@ -0,0 +1,75 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.harness.parser.TestIChannelTopic;
27
+import com.dmdirc.parser.common.CallbackNotFoundException;
28
+import com.dmdirc.parser.interfaces.callbacks.ChannelTopicListener;
29
+import org.junit.Test;
30
+import static org.junit.Assert.*;
31
+
32
+public class ProcessTopicTest {
33
+    
34
+    @Test
35
+    public void testBasicTopic() throws CallbackNotFoundException {
36
+        final TestParser parser = new TestParser();
37
+        final TestIChannelTopic test = new TestIChannelTopic();
38
+        parser.injectConnectionStrings();
39
+        parser.getCallbackManager().addCallback(ChannelTopicListener.class, test);
40
+        
41
+        parser.injectLine(":nick JOIN #DMDirc_testing");
42
+        parser.injectLine(":server 332 nick #DMDirc_testing :This be a topic");
43
+        parser.injectLine(":server 333 nick #DMDirc_testing Q 1207350306");
44
+        
45
+        assertTrue(test.triggered);
46
+        assertTrue(test.isJoin);
47
+        assertEquals("#DMDirc_testing", test.channel.getName());
48
+        assertEquals("This be a topic", test.channel.getTopic());
49
+        assertEquals("Q", test.channel.getTopicSetter());
50
+        assertEquals(1207350306l, test.channel.getTopicTime());
51
+    }
52
+    
53
+    @Test
54
+    public void testTopicChange() throws CallbackNotFoundException {
55
+        final TestParser parser = new TestParser();
56
+        final TestIChannelTopic test = new TestIChannelTopic();
57
+        parser.injectConnectionStrings();
58
+        
59
+        parser.injectLine(":nick JOIN #DMDirc_testing");
60
+        parser.injectLine(":server 332 nick #DMDirc_testing :This be a topic");
61
+        parser.injectLine(":server 333 nick #DMDirc_testing Q 1207350306");
62
+        
63
+        parser.getCallbackManager().addCallback(ChannelTopicListener.class, test);
64
+        
65
+        parser.injectLine(":foobar TOPIC #DMDirc_testing :New topic here");
66
+        
67
+        assertTrue(test.triggered);
68
+        assertFalse(test.isJoin);
69
+        assertEquals("#DMDirc_testing", test.channel.getName());
70
+        assertEquals("New topic here", test.channel.getTopic());
71
+        assertEquals("foobar", test.channel.getTopicSetter());
72
+        assertTrue(1207350306l < test.channel.getTopicTime());
73
+    }    
74
+
75
+}

+ 51
- 0
test/com/dmdirc/parser/irc/ProcessWhoTest.java Dosyayı Görüntüle

@@ -0,0 +1,51 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.parser.common.CallbackNotFoundException;
27
+import com.dmdirc.parser.interfaces.callbacks.AwayStateListener;
28
+import org.junit.Test;
29
+import static org.mockito.Mockito.*;
30
+
31
+public class ProcessWhoTest {
32
+
33
+    @Test
34
+    public void testSelfAway() throws CallbackNotFoundException {
35
+        final TestParser parser = new TestParser();
36
+        final AwayStateListener test = mock(AwayStateListener.class);
37
+        parser.injectConnectionStrings();
38
+        parser.getCallbackManager().addCallback(AwayStateListener.class, test);
39
+
40
+        parser.injectLine(":nick JOIN #DMDirc_testing");
41
+
42
+        parser.injectLine(":server 352 nick #DMDirc_testing nick2 host2 server nick2 G@ :0 rn");
43
+
44
+        verify(test, never()).onAwayState((IRCParser) anyObject(),anyBoolean(), anyString());
45
+
46
+        parser.injectLine(":server 352 nick #DMDirc_testing nick host server nick G@ :0 rn");
47
+
48
+        verify(test).onAwayState(parser, true, "");
49
+    }
50
+
51
+}

+ 117
- 0
test/com/dmdirc/parser/irc/RegexStringListTest.java Dosyayı Görüntüle

@@ -0,0 +1,117 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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.parser.common.IgnoreList;
25
+import java.util.ArrayList;
26
+import java.util.List;
27
+import org.junit.Test;
28
+import static org.junit.Assert.*;
29
+
30
+public class RegexStringListTest {
31
+
32
+    @Test
33
+    public void testAdd() {
34
+        final IgnoreList list = new IgnoreList();
35
+        list.add("a!b@c");
36
+        list.add("a!b@c");
37
+        list.add("A!B@c");
38
+
39
+        assertEquals(1, list.count());
40
+        assertEquals("a!b@c", list.get(0));
41
+    }
42
+
43
+    @Test
44
+    public void testAddAll() {
45
+        final List<String> tempList = new ArrayList<String>();
46
+        tempList.add("a!b@c");
47
+        tempList.add("a!b@c");
48
+        tempList.add("A!B@C");
49
+        tempList.add("Data.*");
50
+
51
+        final IgnoreList list = new IgnoreList(tempList);
52
+
53
+        assertEquals(2, list.count());
54
+        assertEquals("a!b@c", list.get(0));
55
+        assertEquals("Data.*", list.get(1));
56
+    }
57
+
58
+    @Test
59
+    public void testRmove() {
60
+        final List<String> tempList = new ArrayList<String>();
61
+        tempList.add("a!b@c");
62
+        tempList.add("Data.*");
63
+
64
+        final IgnoreList list = new IgnoreList(tempList);
65
+        list.remove(0);
66
+        list.remove(17);
67
+
68
+        assertEquals(1, list.count());
69
+        assertEquals("Data.*", list.get(0));
70
+    }
71
+
72
+    @Test
73
+    public void testClear() {
74
+        final List<String> tempList = new ArrayList<String>();
75
+        tempList.add("a!b@c");
76
+        tempList.add("Data.*");
77
+
78
+        final IgnoreList list = new IgnoreList(tempList);
79
+        list.clear();
80
+
81
+        assertEquals(0, list.count());
82
+    }
83
+
84
+    @Test
85
+    public void testMatches() {
86
+        final List<String> tempList = new ArrayList<String>();
87
+        tempList.add("a!b@c");
88
+        tempList.add("Data.*");
89
+
90
+        final IgnoreList list = new IgnoreList(tempList);
91
+
92
+        assertTrue(list.matches("a!b@c") == 0);
93
+        assertTrue(list.matches("foo") == -1);
94
+        assertTrue(list.matches("Dataforce") == 1);
95
+        assertFalse(list.matches(100, "Dataforce"));
96
+        assertTrue(list.matches(1, "Dataforce"));
97
+    }
98
+    
99
+    @Test
100
+    public void testGet() {
101
+        final IgnoreList list = new IgnoreList();
102
+        list.add("a!b@c");
103
+        assertEquals("a!b@c", list.get(0));
104
+        assertEquals("", list.get(7));
105
+    }
106
+
107
+    @Test
108
+    public void testSet() {
109
+        final IgnoreList list = new IgnoreList();
110
+        list.add("a!b@c");
111
+        list.set(0, "moo");
112
+        list.set(1, "bar");
113
+        assertEquals(1, list.count());
114
+        assertEquals("moo", list.get(0));
115
+    }
116
+
117
+}

+ 84
- 0
test/com/dmdirc/parser/irc/ServerInfoTest.java Dosyayı Görüntüle

@@ -0,0 +1,84 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class ServerInfoTest {
29
+    
30
+    @Test
31
+    public void testHost() {
32
+        final ServerInfo si = new ServerInfo("host0", 5, "");
33
+        assertEquals("host0", si.getHost());
34
+        si.setHost("host1");
35
+        assertEquals("host1", si.getHost());
36
+    }
37
+    
38
+    @Test
39
+    public void testPort() {
40
+        final ServerInfo si = new ServerInfo("host0", 5, "");
41
+        assertEquals(5, si.getPort());
42
+        si.setPort(65530);
43
+        assertEquals(65530, si.getPort());
44
+    }
45
+    
46
+    @Test
47
+    public void testPassword() {
48
+        final ServerInfo si = new ServerInfo("host0", 5, "pass1");
49
+        assertEquals("pass1", si.getPassword());
50
+        si.setPassword("pass2");
51
+        assertEquals("pass2", si.getPassword());
52
+    }
53
+    
54
+    @Test
55
+    public void testSSL() {
56
+        final ServerInfo si = new ServerInfo("host0", 5, "pass1");
57
+        assertFalse(si.getSSL());
58
+        si.setSSL(true);
59
+        assertTrue(si.getSSL());
60
+    }
61
+    
62
+    @Test
63
+    public void testUseSocks() {
64
+        final ServerInfo si = new ServerInfo("host0", 5, "pass1");
65
+        assertFalse(si.getUseSocks());
66
+        si.setUseSocks(true);
67
+        assertTrue(si.getUseSocks());
68
+    }
69
+    
70
+    @Test
71
+    public void testProxyHost() {
72
+        final ServerInfo si = new ServerInfo("host0", 5, "pass1");
73
+        si.setProxyHost("foo");
74
+        assertEquals("foo", si.getProxyHost());
75
+    }
76
+    
77
+    @Test
78
+    public void testProxyPort() {
79
+        final ServerInfo si = new ServerInfo("host0", 5, "pass1");
80
+        si.setProxyPort(1024);
81
+        assertEquals(1024, si.getProxyPort());
82
+    }
83
+    
84
+}

Loading…
İptal
Kaydet