ソースを参照

Unit tests (ServerManager, Process004005, ProcessJoin)

Tidied up some logic in ConditionTree, and removed unneccesary asserts
Issue 1106

git-svn-id: http://svn.dmdirc.com/trunk@3949 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16年前
コミット
c8400c2a53

+ 7
- 18
src/com/dmdirc/actions/ConditionTree.java ファイルの表示

@@ -68,11 +68,6 @@ public class ConditionTree {
68 68
      */
69 69
     private ConditionTree(final OPERATION op, final ConditionTree leftArg,
70 70
             final ConditionTree rightArg) {
71
-        assert(op != OPERATION.VAR);
72
-        assert(op != OPERATION.NOT);
73
-        assert(leftArg != null);
74
-        assert(rightArg != null);
75
-
76 71
         this.op = op;
77 72
         this.leftArg = leftArg;
78 73
         this.rightArg = rightArg;
@@ -85,8 +80,6 @@ public class ConditionTree {
85 80
      * @param argument
86 81
      */
87 82
     private ConditionTree(final OPERATION op, final ConditionTree argument) {
88
-        assert(op == OPERATION.NOT);
89
-
90 83
         this.op = op;
91 84
         this.leftArg = argument;
92 85
     }
@@ -160,8 +153,6 @@ public class ConditionTree {
160 153
     @Override
161 154
     public String toString() {
162 155
         switch (op) {
163
-        case NOOP:
164
-            return "";
165 156
         case VAR:
166 157
             return String.valueOf(argument);
167 158
         case NOT:
@@ -171,7 +162,7 @@ public class ConditionTree {
171 162
         case OR:
172 163
             return "(" + leftArg + "|" + rightArg + ")";
173 164
         default:
174
-            return "<unknown>";
165
+            return "";
175 166
         }
176 167
     }
177 168
 
@@ -213,7 +204,6 @@ public class ConditionTree {
213 204
      * @return The corresponding condition tree, or null if there was an error
214 205
      * while parsing the data.
215 206
      */
216
-    @SuppressWarnings("fallthrough")
217 207
     private static ConditionTree parseStack(final Deque<Object> stack) {
218 208
         final Deque<Object> myStack = new ArrayDeque<Object>();
219 209
 
@@ -234,14 +224,13 @@ public class ConditionTree {
234 224
         }
235 225
 
236 226
         while (!myStack.isEmpty()) {
237
-            switch (myStack.size()) {
238
-                case 1:
239
-                    final Object first = myStack.pollFirst();
240
-                    if (first instanceof ConditionTree) {
241
-                        return (ConditionTree) first;
242
-                    }
243
-                case 0:
227
+            if (myStack.size() == 1) {
228
+                final Object first = myStack.pollFirst();
229
+                if (first instanceof ConditionTree) {
230
+                    return (ConditionTree) first;
231
+                } else {
244 232
                     return null;
233
+                }
245 234
             }
246 235
 
247 236
             final ConditionTree first = readTerm(myStack);

+ 29
- 5
test/com/dmdirc/ServerManagerTest.java ファイルの表示

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.config.IdentityManager;
26 26
 import com.dmdirc.ui.dummy.DummyController;
27 27
 
28
+import com.dmdirc.ui.dummy.DummyQueryWindow;
28 29
 import org.junit.Before;
29 30
 import org.junit.Test;
30 31
 import static org.junit.Assert.*;
@@ -49,7 +50,8 @@ public class ServerManagerTest extends junit.framework.TestCase {
49 50
     
50 51
     @Test
51 52
     public void testRegisterServer() {
52
-        final Server server = new Server("255.255.255.255", 6667, "", false, IdentityManager.getProfiles().get(0));
53
+        final Server server = new Server("255.255.255.255", 6667, "", false,
54
+                IdentityManager.getProfiles().get(0));
53 55
         
54 56
         final ServerManager instance = ServerManager.getServerManager();
55 57
         
@@ -60,7 +62,8 @@ public class ServerManagerTest extends junit.framework.TestCase {
60 62
     
61 63
     @Test
62 64
     public void testUnregisterServer() {
63
-        final Server server = new Server("255.255.255.255", 6667, "", false, IdentityManager.getProfiles().get(0));
65
+        final Server server = new Server("255.255.255.255", 6667, "", false,
66
+                IdentityManager.getProfiles().get(0));
64 67
         
65 68
         server.close();
66 69
         
@@ -75,7 +78,8 @@ public class ServerManagerTest extends junit.framework.TestCase {
75 78
         
76 79
         assertEquals(instance.getServers().size(), instance.numServers());
77 80
         
78
-        final Server server = new Server("255.255.255.255", 6667, "", false, IdentityManager.getProfiles().get(0));
81
+        final Server server = new Server("255.255.255.255", 6667, "", false,
82
+                IdentityManager.getProfiles().get(0));
79 83
         
80 84
         assertEquals(instance.getServers().size(), instance.numServers());
81 85
         
@@ -86,16 +90,36 @@ public class ServerManagerTest extends junit.framework.TestCase {
86 90
     
87 91
     @Test
88 92
     public void testGetServerFromFrame() {
89
-        final Server serverA = new Server("255.255.255.255", 6667, "", false, IdentityManager.getProfiles().get(0));
90
-        final Server serverB = new Server("255.255.255.254", 6667, "", false, IdentityManager.getProfiles().get(0));
93
+        final Server serverA = new Server("255.255.255.255", 6667, "", false,
94
+                IdentityManager.getProfiles().get(0));
95
+        final Server serverB = new Server("255.255.255.254", 6667, "", false,
96
+                IdentityManager.getProfiles().get(0));
91 97
         
92 98
         final ServerManager sm = ServerManager.getServerManager();
93 99
         
94 100
         assertEquals(serverA, sm.getServerFromFrame(serverA.getFrame()));
95 101
         assertEquals(serverB, sm.getServerFromFrame(serverB.getFrame()));
102
+        assertNull(sm.getServerFromFrame(new DummyQueryWindow(serverB)));
96 103
         
97 104
         serverA.close();
98 105
         serverB.close();
99 106
     }
100 107
     
108
+    @Test
109
+    public void testGetServerByAddress() {
110
+        final Server serverA = new Server("255.255.255.255", 6667, "", false,
111
+                IdentityManager.getProfiles().get(0));
112
+        final Server serverB = new Server("255.255.255.254", 6667, "", false,
113
+                IdentityManager.getProfiles().get(0));
114
+        
115
+        final ServerManager sm = ServerManager.getServerManager();
116
+        
117
+        assertEquals(serverA, sm.getServersByAddress("255.255.255.255").get(0));
118
+        assertEquals(serverB, sm.getServersByAddress("255.255.255.254").get(0));
119
+        assertEquals(0, sm.getServersByAddress("255.255.255.253").size());
120
+        
121
+        serverA.close();
122
+        serverB.close();
123
+    }    
124
+    
101 125
 }

+ 39
- 0
test/com/dmdirc/harness/parser/TestIChannelJoin.java ファイルの表示

@@ -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.IChannelJoin;
27
+
28
+public class TestIChannelJoin implements IChannelJoin {
29
+
30
+    public ChannelInfo channel = null;
31
+    
32
+    public ChannelClientInfo client = null;
33
+
34
+    public void onChannelJoin(IRCParser tParser, ChannelInfo cChannel,
35
+            ChannelClientInfo cChannelClient) {
36
+        channel = cChannel;
37
+        client = cChannelClient;
38
+    }
39
+}

+ 0
- 18
test/com/dmdirc/parser/IRCParserTest.java ファイルの表示

@@ -312,24 +312,6 @@ public class IRCParserTest extends junit.framework.TestCase {
312 312
         assertTrue(Arrays.equals(new TrustManager[0], parser.getTrustManager()));
313 313
     }
314 314
 
315
-    @Test
316
-    public void testJoinChannel() throws CallbackNotFoundException {
317
-        final TestParser parser = new TestParser();
318
-        final TestIChannelSelfJoin test = new TestIChannelSelfJoin();
319
-
320
-        parser.injectConnectionStrings();
321
-        parser.getCallbackManager().addCallback("onChannelSelfJoin", test);
322
-        parser.injectLine(":nick JOIN #DMDirc_testing");
323
-
324
-        assertNotNull(test.channel);
325
-        assertEquals("#DMDirc_testing", test.channel.getName());
326
-        assertEquals("#DMDirc_testing", test.channel.toString());
327
-        assertEquals(parser, test.channel.getParser());
328
-        assertEquals(1, parser.getChannels().size());
329
-        assertTrue(parser.getChannels().contains(test.channel));
330
-        assertEquals(test.channel, parser.getChannelInfo("#DMDirc_testing"));
331
-    }
332
-
333 315
     @Test
334 316
     public void testPrivateMessages() throws CallbackNotFoundException {
335 317
         final TestParser parser = new TestParser();

+ 73
- 0
test/com/dmdirc/parser/Process004005Test.java ファイルの表示

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

+ 73
- 0
test/com/dmdirc/parser/ProcessJoinTest.java ファイルの表示

@@ -0,0 +1,73 @@
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.parser;
24
+
25
+import com.dmdirc.harness.parser.TestIChannelJoin;
26
+import com.dmdirc.harness.parser.TestIChannelSelfJoin;
27
+import com.dmdirc.harness.parser.TestParser;
28
+import com.dmdirc.parser.callbacks.CallbackNotFoundException;
29
+
30
+import org.junit.Test;
31
+import static org.junit.Assert.*;
32
+
33
+public class ProcessJoinTest extends junit.framework.TestCase {
34
+    
35
+    @Test
36
+    public void testSelfJoinChannel() throws CallbackNotFoundException {
37
+        final TestParser parser = new TestParser();
38
+        final TestIChannelSelfJoin test = new TestIChannelSelfJoin();
39
+
40
+        parser.injectConnectionStrings();
41
+        parser.getCallbackManager().addCallback("onChannelSelfJoin", test);
42
+        parser.injectLine(":nick JOIN #DMDirc_testing");
43
+
44
+        assertNotNull(test.channel);
45
+        assertEquals("#DMDirc_testing", test.channel.getName());
46
+        assertEquals("#DMDirc_testing", test.channel.toString());
47
+        assertSame(parser, test.channel.getParser());
48
+        assertEquals(1, parser.getChannels().size());
49
+        assertTrue(parser.getChannels().contains(test.channel));
50
+        assertEquals(test.channel, parser.getChannelInfo("#DMDirc_testing"));
51
+    }
52
+    
53
+    @Test
54
+    public void testOtherJoinChannel() throws CallbackNotFoundException {
55
+        final TestParser parser = new TestParser();
56
+        final TestIChannelJoin test = new TestIChannelJoin();
57
+
58
+        parser.injectConnectionStrings();
59
+        parser.getCallbackManager().addCallback("onChannelJoin", test);
60
+        
61
+        parser.injectLine(":nick JOIN #DMDirc_testing");
62
+        parser.injectLine(":foo!bar@baz JOIN #DMDirc_testing");
63
+
64
+        assertNotNull(test.channel);
65
+        assertEquals("#DMDirc_testing", test.channel.getName());
66
+        assertEquals("#DMDirc_testing", test.channel.toString());
67
+        assertSame(parser, test.channel.getParser());
68
+        assertNotNull(parser.getClientInfo("foo"));
69
+        assertSame(test.client.getClient(), parser.getClientInfo("foo"));
70
+        assertTrue(parser.getClientInfo("foo").getChannelClients().contains(test.client));
71
+    }    
72
+
73
+}

読み込み中…
キャンセル
保存