Browse Source

Added unit tests for invites, topics, and server's handling of invites.

Fixed invites not being removed on disconnect - fixes issue 637

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

+ 13
- 0
src/com/dmdirc/Server.java View File

@@ -326,6 +326,7 @@ public final class Server extends WritableFrameContainer implements Serializable
326 326
             myState = ServerState.DISCONNECTED;
327 327
         }
328 328
 
329
+        removeInvites();
329 330
         updateIcon();
330 331
 
331 332
         if (parser != null && parser.getSocketState() == IRCParser.STATE_OPEN) {
@@ -826,6 +827,7 @@ public final class Server extends WritableFrameContainer implements Serializable
826 827
         myState = ServerState.CLOSING;
827 828
         closeChannels();
828 829
         closeQueries();
830
+        removeInvites();
829 831
 
830 832
         if (raw != null) {
831 833
             raw.close();
@@ -1082,6 +1084,8 @@ public final class Server extends WritableFrameContainer implements Serializable
1082 1084
         if (configManager.getOptionBool(DOMAIN_GENERAL, "closequeriesondisconnect", false)) {
1083 1085
             closeQueries();
1084 1086
         }
1087
+        
1088
+        removeInvites();
1085 1089
 
1086 1090
         if (configManager.getOptionBool(DOMAIN_GENERAL, "reconnectondisconnect", false)) {
1087 1091
             doDelayedReconnect();
@@ -1326,6 +1330,15 @@ public final class Server extends WritableFrameContainer implements Serializable
1326 1330
             }
1327 1331
         }
1328 1332
     }
1333
+    
1334
+    /**
1335
+     * Removes all invites for all channels.
1336
+     */
1337
+    private void removeInvites() {
1338
+        for (Invite invite : new ArrayList<Invite>(invites)) {
1339
+            removeInvite(invite);
1340
+        }
1341
+    }    
1329 1342
 
1330 1343
     /**
1331 1344
      * Removes an invite from this server, and fires the appropriate listeners.

+ 79
- 0
test/com/dmdirc/InviteTest.java View File

@@ -0,0 +1,79 @@
1
+/*
2
+ * Copyright (c) 2006-2007 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;
24
+
25
+import com.dmdirc.config.IdentityManager;
26
+import com.dmdirc.ui.dummy.DummyController;
27
+import java.util.Date;
28
+import org.junit.Before;
29
+import org.junit.Test;
30
+import static org.junit.Assert.*;
31
+
32
+public class InviteTest extends junit.framework.TestCase {
33
+    
34
+    private Server server;
35
+    private Invite test;
36
+    private long ts;
37
+    
38
+    @Before
39
+    public void setUp() throws Exception {
40
+        Main.setUI(new DummyController());
41
+        IdentityManager.load();
42
+        
43
+        server = new Server("255.255.255.255", 6667, "", false, IdentityManager.getProfiles().get(0));
44
+        test = new Invite(server, "#channel", "nick!ident@host");
45
+        server.addInvite(test);
46
+        ts = new Date().getTime();
47
+    }    
48
+
49
+    @Test
50
+    public void testGetServer() {
51
+        assertEquals(server, test.getServer());
52
+    }
53
+
54
+    @Test
55
+    public void testGetChannel() {
56
+        assertEquals("#channel", test.getChannel());
57
+    }
58
+
59
+    @Test
60
+    public void testGetTimestamp() {
61
+        assertTrue(test.getTimestamp() - ts < 10000);
62
+        assertTrue(test.getTimestamp() - ts > -10000);
63
+    }
64
+
65
+    @Test
66
+    public void testGetSource() {
67
+        assertEquals(3, test.getSource().length);
68
+        assertEquals("nick", test.getSource()[0]);
69
+        assertEquals("ident", test.getSource()[1]);
70
+        assertEquals("host", test.getSource()[2]);
71
+    }
72
+
73
+    @Test
74
+    public void testAccept() {
75
+        test.accept();
76
+        assertEquals(0, server.getInvites().size());
77
+    }
78
+
79
+}

+ 48
- 2
test/com/dmdirc/ServerTest.java View File

@@ -22,11 +22,23 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
+import com.dmdirc.config.IdentityManager;
26
+import com.dmdirc.ui.dummy.DummyController;
27
+import org.junit.Before;
25 28
 import org.junit.Test;
26 29
 import static org.junit.Assert.*;
27 30
 
28 31
 public class ServerTest extends junit.framework.TestCase {
29 32
 
33
+    private Server server;
34
+
35
+    @Before
36
+    public void setUp() throws Exception {
37
+        Main.setUI(new DummyController());
38
+        IdentityManager.load();
39
+        server = new Server("255.255.255.255", 6667, "", false, IdentityManager.getProfiles().get(0));
40
+    }
41
+
30 42
     @Test
31 43
     public void testGetNetworkFromServerName() {
32 44
         final String[][] tests = {
@@ -38,10 +50,44 @@ public class ServerTest extends junit.framework.TestCase {
38 50
             {"localhost", "localhost"},
39 51
             {"foo.de", "foo.de"}
40 52
         };
41
-        
53
+
42 54
         for (String[] test : tests) {
43 55
             assertEquals(test[1], Server.getNetworkFromServerName(test[0]));
44 56
         }
45 57
     }
46
-    
58
+
59
+    @Test
60
+    public void testDuplicateInviteRemoval() {
61
+        server.disconnect();
62
+        
63
+        server.addInvite(new Invite(server, "#chan1", "a!b@c"));
64
+        server.addInvite(new Invite(server, "#chan1", "d!e@f"));
65
+
66
+        assertEquals(1, server.getInvites().size());
67
+        assertEquals("d", server.getInvites().get(0).getSource()[0]);
68
+        server.removeInvites("#chan1");
69
+    }
70
+
71
+    @Test
72
+    public void testRemoveInvites() {
73
+        server.disconnect();
74
+        
75
+        server.addInvite(new Invite(server, "#chan1", "a!b@c"));
76
+        server.addInvite(new Invite(server, "#chan2", "d!e@f"));
77
+
78
+        server.removeInvites("#chan1");
79
+        assertEquals(1, server.getInvites().size());
80
+
81
+        server.removeInvites("#chan2");
82
+        assertEquals(0, server.getInvites().size());
83
+    }
84
+
85
+    @Test
86
+    public void testRemoveInvitesOnDisconnect() {
87
+        server.reconnect();
88
+        server.addInvite(new Invite(server, "#chan1", "a!b@c"));
89
+        server.disconnect();
90
+        assertEquals(0, server.getInvites().size());
91
+    }
92
+
47 93
 }

+ 63
- 0
test/com/dmdirc/TopicTest.java View File

@@ -0,0 +1,63 @@
1
+/*
2
+ * Copyright (c) 2006-2007 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;
24
+
25
+import com.dmdirc.config.IdentityManager;
26
+import com.dmdirc.ui.dummy.DummyController;
27
+import org.junit.Before;
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class TopicTest extends junit.framework.TestCase {
32
+    
33
+    @Before
34
+    public void setUp() throws Exception {
35
+        Main.setUI(new DummyController());
36
+        IdentityManager.load();
37
+    }
38
+
39
+    @Test
40
+    public void testGetClient() {
41
+        final Topic test = new Topic("abc", "123!456@789", 1);
42
+        assertEquals("123!456@789", test.getClient());
43
+    }
44
+
45
+    @Test
46
+    public void testGetTime() {
47
+        final Topic test = new Topic("abc", "123!456@789", 1);
48
+        assertEquals(1, test.getTime());        
49
+    }
50
+
51
+    @Test
52
+    public void testGetTopic() {
53
+        final Topic test = new Topic("abc", "123!456@789", 1);
54
+        assertEquals("abc", test.getTopic());        
55
+    }
56
+
57
+    @Test
58
+    public void testToString() {
59
+        final Topic test = new Topic("abc", "123!456@789", 1);
60
+        assertEquals("abc", test.toString());        
61
+    }
62
+
63
+}

Loading…
Cancel
Save