Pārlūkot izejas kodu

Random parsery unit tests

git-svn-id: http://svn.dmdirc.com/trunk@3974 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 gadus atpakaļ
vecāks
revīzija
c0704ef0c2

+ 39
- 0
test/com/dmdirc/harness/parser/TestINickChanged.java Parādīt failu

@@ -0,0 +1,39 @@
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.INickChanged;
27
+
28
+public class TestINickChanged implements INickChanged {
29
+
30
+    public String oldNick = null;
31
+    public ClientInfo client;
32
+
33
+    @Override
34
+    public void onNickChanged(IRCParser tParser, ClientInfo cClient,
35
+                              String sOldNick) {
36
+        oldNick = sOldNick;
37
+        client = cClient;
38
+    }
39
+}

+ 19
- 4
test/com/dmdirc/parser/ProcessModeTest.java Parādīt failu

@@ -92,7 +92,7 @@ public class ProcessModeTest extends junit.framework.TestCase {
92 92
         parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
93 93
         parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
94 94
 
95
-        parser.injectLine(":server MODE #DMDirc_testing +v moo");
95
+        parser.injectLine(":luser!me@my MODE #DMDirc_testing +v :moo");
96 96
         
97 97
         assertNotNull(parser.getClientInfo("moo"));
98 98
         assertEquals(1, parser.getClientInfo("moo").channelCount());
@@ -100,6 +100,10 @@ public class ProcessModeTest extends junit.framework.TestCase {
100 100
         final ChannelClientInfo cci = parser.getClientInfo("moo").getChannelClients().get(0);
101 101
         
102 102
         assertEquals("+", cci.getChanModeStr(true));        
103
+        assertEquals("Parser should update ident when it sees a MODE line",
104
+                "me", parser.getClientInfo("luser").getIdent());
105
+        assertEquals("Parser should update host when it sees a MODE line",
106
+                "my", parser.getClientInfo("luser").getHost());
103 107
     }
104 108
     
105 109
     @Test
@@ -132,17 +136,28 @@ public class ProcessModeTest extends junit.framework.TestCase {
132 136
         parser.injectLine(":nick JOIN #DMDirc_testing");
133 137
         parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
134 138
         parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
135
-        parser.injectLine(":server 324 nick #DMDirc_testing +stnl 1234");
139
+        parser.injectLine(":server 324 nick #DMDirc_testing +Zstnl 1234");
136 140
 
137 141
         assertEquals("1234", parser.getChannelInfo("#DMDirc_testing").getModeParam('l'));
138 142
         
139
-        final String modes = parser.getChannelInfo("#DMDirc_testing").getModeStr().split(" ")[0];
140
-        assertEquals(5, modes.length());
143
+        String modes = parser.getChannelInfo("#DMDirc_testing").getModeStr().split(" ")[0];
144
+        assertEquals(6, modes.length());
141 145
         assertEquals('+', modes.charAt(0));
146
+        assertTrue(modes.indexOf('Z') > -1);
142 147
         assertTrue(modes.indexOf('s') > -1);
143 148
         assertTrue(modes.indexOf('t') > -1);
144 149
         assertTrue(modes.indexOf('n') > -1);
145 150
         assertTrue(modes.indexOf('l') > -1);
151
+        
152
+        parser.injectLine(":server MODE #DMDirc_testing :-Z");
153
+        
154
+        modes = parser.getChannelInfo("#DMDirc_testing").getModeStr().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);        
146 161
     }
147 162
 
148 163
 }

+ 23
- 2
test/com/dmdirc/parser/ProcessNickTest.java Parādīt failu

@@ -24,8 +24,8 @@ package com.dmdirc.parser;
24 24
 
25 25
 import com.dmdirc.harness.parser.TestParser;
26 26
 import com.dmdirc.harness.parser.TestIErrorInfo;
27
+import com.dmdirc.harness.parser.TestINickChanged;
27 28
 import com.dmdirc.parser.callbacks.CallbackNotFoundException;
28
-import org.junit.Ignore;
29 29
 import org.junit.Test;
30 30
 import static org.junit.Assert.*;
31 31
 
@@ -34,9 +34,13 @@ public class ProcessNickTest {
34 34
     @Test
35 35
     public void testNickSameName() {
36 36
         final TestParser parser = new TestParser();
37
+        final TestINickChanged tinc = new TestINickChanged();
37 38
 
39
+        parser.getCallbackManager().addCallback("OnNickChanged", tinc);
40
+        
38 41
         parser.injectConnectionStrings();
39 42
         parser.injectLine(":nick JOIN #DMDirc_testing");
43
+        parser.injectLine(":nick JOIN #DMDirc_testing2");
40 44
         parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser @+nick2 nick3");
41 45
         parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
42 46
         parser.injectLine(":luser!lu@ser.com NICK LUSER");
@@ -47,6 +51,9 @@ public class ProcessNickTest {
47 51
         ChannelClientInfo cci = parser.getClientInfo("LUSER").getChannelClients().get(0);
48 52
         assertEquals(parser.getChannelInfo("#DMDirc_testing"), cci.getChannel());
49 53
         assertEquals("+", cci.getChanModeStr(true));
54
+        
55
+        assertSame(cci.getClient(), tinc.client);
56
+        assertEquals("luser", tinc.oldNick);
50 57
     }
51 58
     
52 59
     @Test
@@ -82,7 +89,21 @@ public class ProcessNickTest {
82 89
 
83 90
         assertTrue("Parser should raise an error if a nick change overrides an "
84 91
                 + "existing client", info.error);
85
-    }    
92
+    }
93
+    
94
+    @Test
95
+    public void testUnknownNick() {
96
+        final TestParser parser = new TestParser();
97
+        final TestINickChanged tinc = new TestINickChanged();
98
+        
99
+        parser.getCallbackManager().addCallback("OnNickChanged", tinc);
100
+        
101
+        parser.injectConnectionStrings();
102
+        parser.injectLine(":random!lu@ser NICK rand");
103
+        
104
+        assertNull(tinc.client);
105
+        assertNull(tinc.oldNick);
106
+    }
86 107
     
87 108
     public static junit.framework.Test suite() {
88 109
         return new junit.framework.JUnit4TestAdapter(ProcessNickTest.class);

Notiek ielāde…
Atcelt
Saglabāt