Browse Source

Unit test for parser port range checking

Issue 1171, issue 1106

git-svn-id: http://svn.dmdirc.com/trunk@3973 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
56e7336994

+ 36
- 0
test/com/dmdirc/harness/parser/TestIConnectError.java View File

@@ -0,0 +1,36 @@
1
+/*
2
+ * Copyright (c) 2006-2008 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.harness.parser;
24
+
25
+import com.dmdirc.parser.*;
26
+import com.dmdirc.parser.callbacks.interfaces.IConnectError;
27
+
28
+public class TestIConnectError implements IConnectError {
29
+
30
+    public boolean error = false;
31
+
32
+    @Override
33
+    public void onConnectError(IRCParser tParser, ParserError errorInfo) {
34
+        error = true;
35
+    }
36
+}

+ 38
- 14
test/com/dmdirc/parser/IRCParserTest.java View File

@@ -25,25 +25,18 @@ package com.dmdirc.parser;
25 25
 import com.dmdirc.harness.parser.TestIPrivateCTCP;
26 26
 import com.dmdirc.harness.parser.TestParser;
27 27
 import com.dmdirc.harness.parser.TestIChannelKick;
28
+import com.dmdirc.harness.parser.TestIConnectError;
29
+import com.dmdirc.harness.parser.TestIErrorInfo;
28 30
 import com.dmdirc.harness.parser.TestINoticeAuth;
29 31
 import com.dmdirc.harness.parser.TestINumeric;
30 32
 import com.dmdirc.harness.parser.TestIServerError;
31
-import com.dmdirc.harness.parser.TestIChannelSelfJoin;
32 33
 import com.dmdirc.harness.parser.TestIPost005;
33 34
 import com.dmdirc.harness.parser.TestIPrivateMessage;
34 35
 import com.dmdirc.harness.parser.TestIPrivateAction;
35 36
 import com.dmdirc.parser.callbacks.CallbackNotFoundException;
36 37
 import com.dmdirc.parser.callbacks.interfaces.IAwayState;
37
-import com.dmdirc.parser.callbacks.interfaces.IChannelKick;
38
-import com.dmdirc.parser.callbacks.interfaces.IChannelSelfJoin;
39
-import com.dmdirc.parser.callbacks.interfaces.INoticeAuth;
40
-import com.dmdirc.parser.callbacks.interfaces.INumeric;
41
-import com.dmdirc.parser.callbacks.interfaces.IPost005;
42
-import com.dmdirc.parser.callbacks.interfaces.IPrivateAction;
43
-import com.dmdirc.parser.callbacks.interfaces.IPrivateCTCP;
44
-import com.dmdirc.parser.callbacks.interfaces.IPrivateMessage;
45
-import com.dmdirc.parser.callbacks.interfaces.IServerError;
46 38
 
39
+import java.io.IOException;
47 40
 import java.util.Arrays;
48 41
 
49 42
 import java.util.List;
@@ -52,7 +45,7 @@ import javax.net.ssl.TrustManager;
52 45
 import org.junit.Test;
53 46
 import static org.junit.Assert.*;
54 47
 
55
-public class IRCParserTest extends junit.framework.TestCase {
48
+public class IRCParserTest {
56 49
 
57 50
     @Test
58 51
     public void testIssue042() {
@@ -371,17 +364,17 @@ public class IRCParserTest extends junit.framework.TestCase {
371 364
         for (ChannelListModeItem item : items) {
372 365
             if (item.getItem().equals("ban1!ident@.host")) {
373 366
                 assertEquals("bansetter1", item.getOwner());
374
-                assertEquals(1001, item.getTime());
367
+                assertEquals(1001l, item.getTime());
375 368
                 assertFalse(gotOne);
376 369
                 gotOne = true;
377 370
             } else if (item.getItem().equals("ban2!*@.host")) {
378 371
                 assertEquals("bansetter2", item.getOwner());
379
-                assertEquals(1002, item.getTime());
372
+                assertEquals(1002l, item.getTime());
380 373
                 assertFalse(gotTwo);
381 374
                 gotTwo = true;
382 375
             } else if (item.toString().equals("ban3!ident@*")) {
383 376
                 assertEquals("bansetter3", item.getOwner());
384
-                assertEquals(1003, item.getTime());
377
+                assertEquals(1003l, item.getTime());
385 378
                 assertFalse(gotThree);
386 379
                 gotThree = true;
387 380
             }
@@ -442,6 +435,33 @@ public class IRCParserTest extends junit.framework.TestCase {
442 435
         doIRCdTest("Unreal3.2.6", "unreal");
443 436
         doIRCdTest("bahamut-1.8(04)", "bahamut");
444 437
     }
438
+    
439
+    @Test
440
+    public void testIllegalPort1() {
441
+        final TestParser tp = new TestParser(new MyInfo(), new ServerInfo("127.0.0.1", 0, ""));
442
+        final TestIConnectError tiei = new TestIConnectError();
443
+        tp.getCallbackManager().addCallback("OnConnectError", tiei);
444
+        tp.run();
445
+        assertTrue(tiei.error);
446
+    }
447
+    
448
+    @Test
449
+    public void testIllegalPort2() {
450
+        final TestParser tp = new TestParser(new MyInfo(), new ServerInfo("127.0.0.1", 1, ""));
451
+        final TestIConnectError tiei = new TestIConnectError();
452
+        tp.getCallbackManager().addCallback("OnConnectError", tiei);
453
+        tp.run();
454
+        assertTrue(tiei.error);
455
+    }    
456
+    
457
+    @Test
458
+    public void testIllegalPort3() {
459
+        final TestParser tp = new TestParser(new MyInfo(), new ServerInfo("127.0.0.1", 65570, ""));
460
+        final TestIConnectError tiei = new TestIConnectError();
461
+        tp.getCallbackManager().addCallback("OnConnectError", tiei);
462
+        tp.run();
463
+        assertTrue(tiei.error);
464
+    }
445 465
 
446 466
     private void doIRCdTest(final String ircd, final String expected) {
447 467
         final TestParser parser = new TestParser();
@@ -460,5 +480,9 @@ public class IRCParserTest extends junit.framework.TestCase {
460 480
         assertEquals(ircd, parser.getIRCD(false));
461 481
         assertEquals(expected.toLowerCase(), parser.getIRCD(true).toLowerCase());
462 482
     }
483
+    
484
+    public static junit.framework.Test suite() {
485
+        return new junit.framework.JUnit4TestAdapter(IRCParserTest.class);
486
+    }
463 487
 
464 488
 }

+ 1
- 1
test/com/dmdirc/parser/ProcessModeTest.java View File

@@ -133,7 +133,7 @@ public class ProcessModeTest extends junit.framework.TestCase {
133 133
         parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
134 134
         parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
135 135
         parser.injectLine(":server 324 nick #DMDirc_testing +stnl 1234");
136
-    
136
+
137 137
         assertEquals("1234", parser.getChannelInfo("#DMDirc_testing").getModeParam('l'));
138 138
         
139 139
         final String modes = parser.getChannelInfo("#DMDirc_testing").getModeStr().split(" ")[0];

Loading…
Cancel
Save