Procházet zdrojové kódy

Add tests!

Change-Id: Ie8fe55536d320ab50472d8090b63c701cc4b12ba
Reviewed-on: http://gerrit.dmdirc.com/230
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
Tested-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3
Shane Mc Cormack před 14 roky
rodič
revize
353ea08a27
21 změnil soubory, kde provedl 2544 přidání a 1 odebrání
  1. 0
    1
      README
  2. 67
    0
      test/com/dmdirc/addons/dcc/IpToLongTest.java
  3. 192
    0
      test/com/dmdirc/addons/identd/IdentClientTest.java
  4. 124
    0
      test/com/dmdirc/addons/logging/LoggingPluginTest.java
  5. 163
    0
      test/com/dmdirc/addons/logging/ReverseFileReaderTest.java
  6. 7
    0
      test/com/dmdirc/addons/logging/test1.txt
  7. 2
    0
      test/com/dmdirc/addons/logging/test2.txt
  8. 55
    0
      test/com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePluginTest.java
  9. 261
    0
      test/com/dmdirc/addons/mediasource_vlc/index-1.html
  10. 56
    0
      test/com/dmdirc/addons/mediasource_vlc/info-1.html
  11. 60
    0
      test/com/dmdirc/addons/redirect/RedirectCommandTest.java
  12. 160
    0
      test/com/dmdirc/addons/ui_swing/MainFrameTest.java
  13. 68
    0
      test/com/dmdirc/addons/ui_swing/UIUtilitiesTest.java
  14. 169
    0
      test/com/dmdirc/addons/ui_swing/components/frames/InputTextFrameTest.java
  15. 211
    0
      test/com/dmdirc/addons/ui_swing/components/reorderablelist/ArrayListTransferHandlerTest.java
  16. 70
    0
      test/com/dmdirc/addons/ui_swing/components/reorderablelist/ArrayListTransferableTest.java
  17. 333
    0
      test/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialogTest.java
  18. 239
    0
      test/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialogTest.java
  19. 102
    0
      test/com/dmdirc/addons/ui_swing/dialogs/profiles/ProfileManagerDialogTest.java
  20. 138
    0
      test/com/dmdirc/addons/ui_swing/dialogs/sslcertificate/SSLCertificateDialogTest.java
  21. 67
    0
      test/com/dmdirc/addons/urlcatcher/UrlCatcherPluginTest.java

+ 0
- 1
README Zobrazit soubor

@@ -1 +0,0 @@
1
-This repository is for non-core plugins of DMDirc.

+ 67
- 0
test/com/dmdirc/addons/dcc/IpToLongTest.java Zobrazit soubor

@@ -0,0 +1,67 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.dcc;
24
+
25
+import java.util.Arrays;
26
+import java.util.List;
27
+
28
+import org.junit.Test;
29
+import org.junit.runner.RunWith;
30
+import org.junit.runners.Parameterized;
31
+import static org.junit.Assert.*;
32
+
33
+@RunWith(Parameterized.class)
34
+public class IpToLongTest {
35
+    
36
+    private String stringip;
37
+    private long longip;
38
+
39
+    public IpToLongTest(String stringip, Long longip) {
40
+        this.stringip = stringip;
41
+        this.longip = longip;
42
+    }
43
+    
44
+    @Test
45
+    public void testToLong() {
46
+        assertEquals(longip, DCC.ipToLong(stringip));
47
+    }
48
+    
49
+    @Test
50
+    public void testToString() {
51
+        assertEquals(stringip, DCC.longToIP(longip));
52
+    }
53
+    
54
+    @Parameterized.Parameters
55
+    public static List<Object[]> data() {
56
+        final Object[][] tests = {
57
+            {"0.0.0.0", 0L},
58
+            {"0.0.0.255", 255L},
59
+            {"127.0.0.1", 2130706433L},
60
+            {"255.0.0.0", 4278190080L},
61
+            {"255.255.255.255", 4294967295L},
62
+        };
63
+
64
+        return Arrays.asList(tests);
65
+    }
66
+
67
+}

+ 192
- 0
test/com/dmdirc/addons/identd/IdentClientTest.java Zobrazit soubor

@@ -0,0 +1,192 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.identd;
24
+
25
+import com.dmdirc.harness.TestConfigManagerMap;
26
+import com.dmdirc.config.IdentityManager;
27
+
28
+import org.junit.BeforeClass;
29
+import org.junit.Test;
30
+import static org.junit.Assert.*;
31
+import static org.mockito.Mockito.*;
32
+
33
+public class IdentClientTest {
34
+
35
+    @BeforeClass
36
+    public static void setUpClass() throws Exception {
37
+        IdentityManager.load();
38
+    }
39
+
40
+    protected IdentClient getClient() {
41
+        IdentdPlugin plugin = mock(IdentdPlugin.class);
42
+        
43
+        when(plugin.getDomain()).thenReturn("plugin-Identd");
44
+        
45
+        return new IdentClient(null, null, plugin);
46
+    }
47
+
48
+    @Test
49
+    public void testInvalidIdent() {
50
+        final String response = getClient().getIdentResponse("invalid request!",
51
+                IdentityManager.getGlobalConfig());
52
+        
53
+        assertContains("Illegal requests must result in an ERROR response",
54
+                response, "ERROR");
55
+    }
56
+    
57
+    @Test
58
+    public void testQuoting() {
59
+        final String response = getClient().getIdentResponse("in\\valid:invalid",
60
+                IdentityManager.getGlobalConfig());
61
+        
62
+        assertStartsWith("Special chars in illegal requests must be quoted",
63
+                response, "in\\\\valid\\:invalid");
64
+    }
65
+    
66
+    @Test
67
+    public void testQuoting2() {
68
+        final String response = getClient().getIdentResponse("in\\\\valid\\ inv\\:alid",
69
+                IdentityManager.getGlobalConfig());
70
+        
71
+        assertStartsWith("Escaped characters in illegal requests shouldn't be doubly-escaped",
72
+                response, "in\\\\valid\\ inv\\:alid");
73
+    }    
74
+    
75
+    @Test
76
+    public void testNonNumericPort() {
77
+        final String response = getClient().getIdentResponse("abc, def",
78
+                IdentityManager.getGlobalConfig());
79
+        
80
+        assertContains("Non-numeric ports must result in an ERROR response",
81
+                response, "ERROR");
82
+        assertStartsWith("Specified ports must be returned in the response",
83
+                response.replaceAll("\\s+", ""), "abc,def:");
84
+    }
85
+    
86
+    private void doPortTest(final String ports) {
87
+        final String response = getClient().getIdentResponse(ports,
88
+                IdentityManager.getGlobalConfig());
89
+        
90
+        assertContains("Illegal ports must result in an ERROR response",
91
+                response, "ERROR");
92
+        assertContains("Illegal ports must result in an INVALID-PORT response",
93
+                response, "INVALID-PORT");
94
+        assertStartsWith("Port numbers must be returned as part of the response",
95
+                response.replaceAll("\\s+", ""), ports.replaceAll("\\s+", ""));
96
+    }
97
+    
98
+    @Test
99
+    public void testOutOfRangePorts() {
100
+        doPortTest("0, 50");
101
+        doPortTest("65536, 50");
102
+        doPortTest("50, 0");
103
+        doPortTest("50, 65536");
104
+    }
105
+    
106
+    @Test
107
+    public void testAlwaysOn() {
108
+        final TestConfigManagerMap tcm = new TestConfigManagerMap();
109
+        tcm.settings.put("plugin-Identd.advanced.alwaysOn", "false");
110
+        
111
+        final String response = getClient().getIdentResponse("50, 50", tcm);
112
+        assertContains("Unknown port requests must return an ERROR response",
113
+                response, "ERROR");
114
+        assertContains("Unknown port requests must return a NO-USER response",
115
+                response, "NO-USER");
116
+    }
117
+    
118
+    @Test
119
+    public void testHidden() {
120
+        final TestConfigManagerMap tcm = new TestConfigManagerMap();
121
+        tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
122
+        tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "true");
123
+        
124
+        final String response = getClient().getIdentResponse("50, 50", tcm);
125
+        assertContains("Hidden requests must return an ERROR response",
126
+                response, "ERROR");
127
+        assertContains("Hidden requests must return a HIDDEN-USER response",
128
+                response, "HIDDEN-USER");
129
+    }
130
+    
131
+    @Test
132
+    public void testSystemNameQuoting() {
133
+        final TestConfigManagerMap tcm = new TestConfigManagerMap();
134
+        tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
135
+        tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "false");
136
+        tcm.settings.put("plugin-Identd.advanced.useCustomSystem", "true");
137
+        tcm.settings.put("plugin-Identd.advanced.customSystem", "a:b\\c,d");
138
+        tcm.settings.put("plugin-Identd.general.useCustomName", "false");
139
+        tcm.settings.put("plugin-Identd.general.customName", "");
140
+        
141
+        final String response = getClient().getIdentResponse("50, 50", tcm);
142
+        assertContains("Special characters must be quoted in system names",
143
+                response, "a\\:b\\\\c\\,d");        
144
+    }
145
+    
146
+    @Test
147
+    public void testCustomNameQuoting() {
148
+        final TestConfigManagerMap tcm = new TestConfigManagerMap();
149
+        tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
150
+        tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "false");
151
+        tcm.settings.put("plugin-Identd.advanced.useCustomSystem", "false");
152
+        tcm.settings.put("plugin-Identd.advanced.customSystem", "");
153
+        tcm.settings.put("plugin-Identd.general.useCustomName", "true");
154
+        tcm.settings.put("plugin-Identd.general.customName", "a:b\\c,d");
155
+        
156
+        final String response = getClient().getIdentResponse("50, 50", tcm);
157
+        assertContains("Special characters must be quoted in custom names",
158
+                response, "a\\:b\\\\c\\,d");        
159
+    }
160
+    
161
+    @Test
162
+    public void testCustomNames() {
163
+        final TestConfigManagerMap tcm = new TestConfigManagerMap();
164
+        tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
165
+        tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "false");
166
+        tcm.settings.put("plugin-Identd.advanced.useCustomSystem", "true");
167
+        tcm.settings.put("plugin-Identd.advanced.customSystem", "system");
168
+        tcm.settings.put("plugin-Identd.general.useCustomName", "true");
169
+        tcm.settings.put("plugin-Identd.general.customName", "name");
170
+        
171
+        final String response = getClient().getIdentResponse("50, 60", tcm);
172
+        final String[] bits = response.split(":");
173
+        
174
+        assertTrue("Responses must include port pair",
175
+                bits[0].matches("\\s*50\\s*,\\s*60\\s*"));
176
+        assertEquals("Positive response must include USERID",
177
+                "USERID", bits[1].trim());
178
+        assertEquals("Must use custom system name", "system", bits[2].trim());
179
+        assertEquals("Must use custom name", "name", bits[3].trim());
180
+    }    
181
+    
182
+    private static void assertContains(final String msg, final String haystack,
183
+            final String needle) {
184
+        assertTrue(msg, haystack.indexOf(needle) > -1);
185
+    }
186
+    
187
+    private static void assertStartsWith(final String msg, final String haystack,
188
+            final String needle) {
189
+        assertTrue(msg, haystack.startsWith(needle));
190
+    }    
191
+
192
+}

+ 124
- 0
test/com/dmdirc/addons/logging/LoggingPluginTest.java Zobrazit soubor

@@ -0,0 +1,124 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.logging;
24
+
25
+import com.dmdirc.Channel;
26
+import com.dmdirc.Main;
27
+import com.dmdirc.Server;
28
+import com.dmdirc.Query;
29
+import com.dmdirc.actions.CoreActionType;
30
+import com.dmdirc.config.IdentityManager;
31
+import com.dmdirc.harness.TestLoggingPlugin;
32
+import com.dmdirc.parser.irc.IRCChannelInfo;
33
+import com.dmdirc.addons.ui_dummy.DummyController;
34
+import com.dmdirc.parser.irc.IRCParser;
35
+import com.dmdirc.util.ConfigFile;
36
+
37
+import java.net.URI;
38
+import java.util.Map;
39
+
40
+import org.junit.BeforeClass;
41
+import org.junit.Test;
42
+import static org.junit.Assert.*;
43
+
44
+public class LoggingPluginTest {
45
+    
46
+    private static Server server;
47
+    private static Channel channel;
48
+    private static Query query;
49
+    private static TestLoggingPlugin lp;
50
+
51
+    @BeforeClass
52
+    public static void setUp() throws Exception {
53
+        Main.setUI(new DummyController());
54
+        IdentityManager.load();
55
+        server = new Server(new URI("irc-test://255.255.255.255"),
56
+                IdentityManager.getProfiles().get(0));
57
+        server.connect();
58
+        
59
+        channel = new Channel(server, new IRCChannelInfo((IRCParser) server.getParser(), "#test"));
60
+        query = new Query(server, "foo!bar@baz");
61
+
62
+        final ConfigFile file = new ConfigFile(LoggingPlugin.class
63
+                .getResourceAsStream("plugin.config"));
64
+        file.read();
65
+
66
+        for (Map.Entry<String, String> entry : file.getKeyDomain("defaults").entrySet()) {
67
+            IdentityManager.getAddonIdentity().setOption("temp-plugin-logging",
68
+                    entry.getKey(), entry.getValue());
69
+        }
70
+
71
+        lp = new TestLoggingPlugin();
72
+        lp.setDomain("temp-plugin-logging");
73
+        lp.domainUpdated();
74
+        lp.onLoad();
75
+    }
76
+    
77
+    @Test
78
+    public void testChannelOpened() {
79
+        lp.processEvent(CoreActionType.CHANNEL_OPENED, new StringBuffer(),
80
+                channel);
81
+        
82
+        assertTrue(lp.lines.containsKey("#test"));
83
+        assertEquals(2, lp.lines.get("#test").size());
84
+        assertTrue(lp.lines.get("#test").get(1).isEmpty());
85
+        assertTrue(lp.lines.get("#test").get(0).indexOf("opened") > -1);
86
+        lp.lines.clear();
87
+    }
88
+    
89
+    @Test
90
+    public void testChannelClosed() {
91
+        lp.processEvent(CoreActionType.CHANNEL_CLOSED, new StringBuffer(),
92
+                channel);
93
+        
94
+        assertTrue(lp.lines.containsKey("#test"));
95
+        assertEquals(1, lp.lines.get("#test").size());
96
+        assertTrue(lp.lines.get("#test").get(0).indexOf("closed") > -1);
97
+        lp.lines.clear();
98
+    }
99
+    
100
+    @Test
101
+    public void testQueryOpened() {
102
+        lp.processEvent(CoreActionType.QUERY_OPENED, new StringBuffer(),
103
+                query);
104
+        
105
+        assertTrue(lp.lines.containsKey("foo!bar@baz"));
106
+        assertEquals(3, lp.lines.get("foo!bar@baz").size());
107
+        assertTrue(lp.lines.get("foo!bar@baz").get(2).isEmpty());
108
+        assertTrue(lp.lines.get("foo!bar@baz").get(1).indexOf("foo!bar@baz") > -1);
109
+        assertTrue(lp.lines.get("foo!bar@baz").get(0).indexOf("opened") > -1);
110
+        lp.lines.clear();
111
+    }
112
+    
113
+    @Test
114
+    public void testQueryClosed() {
115
+        lp.processEvent(CoreActionType.QUERY_CLOSED, new StringBuffer(),
116
+                query);
117
+        
118
+        assertTrue(lp.lines.containsKey("foo!bar@baz"));
119
+        assertEquals(1, lp.lines.get("foo!bar@baz").size());
120
+        assertTrue(lp.lines.get("foo!bar@baz").get(0).indexOf("closed") > -1);
121
+        lp.lines.clear();
122
+    }
123
+
124
+}

+ 163
- 0
test/com/dmdirc/addons/logging/ReverseFileReaderTest.java Zobrazit soubor

@@ -0,0 +1,163 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.logging;
24
+
25
+import java.io.File;
26
+import java.io.IOException;
27
+import java.net.URISyntaxException;
28
+
29
+import java.util.Stack;
30
+import org.junit.Test;
31
+import static org.junit.Assert.*;
32
+
33
+public class ReverseFileReaderTest {
34
+
35
+    @Test
36
+    public void testIndividual() throws IOException, URISyntaxException {
37
+        final ReverseFileReader reader =
38
+                new ReverseFileReader(new File(getClass().getClassLoader().
39
+                getResource("com/dmdirc/addons/logging/test1.txt").
40
+                toURI()));
41
+        assertEquals("Line 7", reader.getNextLine());
42
+        assertEquals("Line 6", reader.getNextLine());
43
+        assertEquals("Line 5", reader.getNextLine());
44
+        assertEquals("Line 4", reader.getNextLine());
45
+        assertEquals("Line 3", reader.getNextLine());
46
+        assertEquals("Line 2", reader.getNextLine());
47
+        assertEquals("Line 1", reader.getNextLine());
48
+        reader.close();
49
+    }
50
+    
51
+    @Test
52
+    public void testCarriageReturn() throws IOException, URISyntaxException {
53
+        final ReverseFileReader reader =
54
+                new ReverseFileReader(new File(getClass().getClassLoader().
55
+                getResource("com/dmdirc/addons/logging/test2.txt").
56
+                toURI()));
57
+        reader.getNextLine();
58
+        assertEquals("Normal line", reader.getNextLine());
59
+        reader.close();        
60
+    }
61
+    
62
+    @Test
63
+    public void testLongLine() throws IOException, URISyntaxException {
64
+        final ReverseFileReader reader =
65
+                new ReverseFileReader(new File(getClass().getClassLoader().
66
+                getResource("com/dmdirc/addons/logging/test2.txt").
67
+                toURI()));
68
+        assertEquals("This is a line that is longer than 50 characters, so " +
69
+                "should cause the reader to have to scan back multiple times.",
70
+                reader.getNextLine());
71
+        reader.close();        
72
+    }    
73
+    
74
+    @Test
75
+    public void testStack() throws IOException, URISyntaxException {
76
+        final ReverseFileReader reader =
77
+                new ReverseFileReader(new File(getClass().getClassLoader().
78
+                getResource("com/dmdirc/addons/logging/test1.txt").
79
+                toURI()));
80
+        final Stack<String> lines = reader.getLines(10);
81
+
82
+        assertEquals(7, lines.size());
83
+        assertEquals("Line 1", lines.pop());
84
+        assertEquals("Line 2", lines.pop());
85
+        assertEquals("Line 3", lines.pop());
86
+        assertEquals("Line 4", lines.pop());
87
+        assertEquals("Line 5", lines.pop());
88
+        assertEquals("Line 6", lines.pop());
89
+        assertEquals("Line 7", lines.pop());
90
+        reader.close();
91
+    }
92
+    
93
+    @Test
94
+    public void testSmallStack() throws IOException, URISyntaxException {
95
+        final ReverseFileReader reader =
96
+                new ReverseFileReader(new File(getClass().getClassLoader().
97
+                getResource("com/dmdirc/addons/logging/test1.txt").
98
+                toURI()));
99
+        final Stack<String> lines = reader.getLines(3);
100
+
101
+        assertEquals(3, lines.size());
102
+        assertEquals("Line 5", lines.pop());
103
+        assertEquals("Line 6", lines.pop());
104
+        assertEquals("Line 7", lines.pop());
105
+        reader.close();
106
+    }
107
+    
108
+    @Test
109
+    public void testReset() throws IOException, URISyntaxException {
110
+        final ReverseFileReader reader =
111
+                new ReverseFileReader(new File(getClass().getClassLoader().
112
+                getResource("com/dmdirc/addons/logging/test1.txt").
113
+                toURI()));
114
+        assertEquals("Line 7", reader.getNextLine());
115
+        assertEquals("Line 6", reader.getNextLine());
116
+        reader.reset();
117
+        assertEquals("Line 7", reader.getNextLine());
118
+        assertEquals("Line 6", reader.getNextLine());
119
+        assertEquals("Line 5", reader.getNextLine());
120
+        reader.close();
121
+    }
122
+    
123
+    @Test(expected=IOException.class)
124
+    public void testIllegalClose() throws URISyntaxException, IOException {
125
+        final ReverseFileReader reader =
126
+                new ReverseFileReader(new File(getClass().getClassLoader().
127
+                getResource("com/dmdirc/addons/logging/test1.txt").
128
+                toURI()));        
129
+        reader.close();
130
+        reader.close();
131
+    }
132
+    
133
+    @Test(expected=IOException.class)
134
+    public void testIllegalReset() throws URISyntaxException, IOException {
135
+        final ReverseFileReader reader =
136
+                new ReverseFileReader(new File(getClass().getClassLoader().
137
+                getResource("com/dmdirc/addons/logging/test1.txt").
138
+                toURI()));        
139
+        reader.close();
140
+        reader.reset();
141
+    }
142
+    
143
+    @Test(expected=IOException.class)
144
+    public void testIllegalGetNextLine() throws URISyntaxException, IOException {
145
+        final ReverseFileReader reader =
146
+                new ReverseFileReader(new File(getClass().getClassLoader().
147
+                getResource("com/dmdirc/addons/logging/test1.txt").
148
+                toURI()));        
149
+        reader.close();
150
+        reader.getNextLine();
151
+    }
152
+    
153
+    @Test
154
+    public void testSeekLength() throws IOException, URISyntaxException {
155
+        final ReverseFileReader reader =
156
+                new ReverseFileReader(new File(getClass().getClassLoader().
157
+                getResource("com/dmdirc/addons/logging/test1.txt").
158
+                toURI()));
159
+        reader.setSeekLength((byte) 100);
160
+        assertEquals((byte) 100, reader.getSeekLength());
161
+    }
162
+
163
+}

+ 7
- 0
test/com/dmdirc/addons/logging/test1.txt Zobrazit soubor

@@ -0,0 +1,7 @@
1
+Line 1
2
+Line 2
3
+Line 3
4
+Line 4
5
+Line 5
6
+Line 6
7
+Line 7

+ 2
- 0
test/com/dmdirc/addons/logging/test2.txt Zobrazit soubor

@@ -0,0 +1,2 @@
1
+Normal line
2
+This is a line that is longer than 50 characters, so should cause the reader to have to scan back multiple times.

+ 55
- 0
test/com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePluginTest.java Zobrazit soubor

@@ -0,0 +1,55 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.mediasource_vlc;
24
+
25
+import com.dmdirc.addons.nowplaying.MediaSourceState;
26
+import com.dmdirc.util.TextFile;
27
+import java.io.IOException;
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class VlcMediaSourcePluginTest {
32
+
33
+    @Test
34
+    public void testProcessInformation1() throws IOException {
35
+        final VlcMediaSourcePlugin plugin = new VlcMediaSourcePlugin();
36
+        final TextFile index = new TextFile(getClass().getResourceAsStream("index-1.html"));
37
+        final TextFile info = new TextFile(getClass().getResourceAsStream("info-1.html"));
38
+        
39
+        plugin.parseInformation(info.getLines(), index.getLines());
40
+        
41
+        // This doesn't work anymore because getState() calls fetchInformation()
42
+        // which overwrites the stuff set by the parseInformation() call.
43
+        // assertTrue(plugin.getState() == MediaSourceState.PLAYING);
44
+        
45
+        assertEquals("Manic Street Preachers", plugin.getArtist());
46
+        assertEquals("Send Away The Tigers", plugin.getAlbum());
47
+        assertEquals("The Second Great Depression", plugin.getTitle());
48
+        assertEquals("128 kb/s", plugin.getBitrate());
49
+        assertEquals("VLC", plugin.getAppName());
50
+        assertEquals("mpga", plugin.getFormat());
51
+        assertEquals("249", plugin.getLength());
52
+        assertEquals("38", plugin.getTime());
53
+    }
54
+
55
+}

+ 261
- 0
test/com/dmdirc/addons/mediasource_vlc/index-1.html Zobrazit soubor

@@ -0,0 +1,261 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD  XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml10/DTD/xhtml10transitional.dtd">
2
+<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><head>
3
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
4
+<!-- $Id: index.html 14777 2006-03-17 14:40:59Z jpsaman $-->
5
+
6
+
7
+
8
+
9
+
10
+ 
11
+    <title>VLC media player</title>
12
+    <link href="index-1_files/style.css" title="Default" rel="stylesheet" type="text/css">
13
+    <!-- Work around. should be done in the code -->
14
+    
15
+        <meta http-equiv="Refresh" content="60;url=/old/">
16
+    
17
+    
18
+    
19
+    
20
+<script type="text/javascript">
21
+
22
+function changeMe(item)
23
+{
24
+  if (item.parentNode.lastChild.style.display=="none")
25
+  {
26
+    item.parentNode.lastChild.style.display="block";
27
+    item.alt="[-]";
28
+    item.src="cone_minus.png";
29
+  }
30
+  else
31
+  {
32
+    item.parentNode.lastChild.style.display="none";
33
+    item.alt="[+]";
34
+    item.src="cone_plus.png";
35
+  }
36
+}
37
+</script>
38
+
39
+</head><body>
40
+
41
+    <!-- left menu -->
42
+    <div class="left">
43
+      <div class="sectitle">Playback control</div>
44
+      <div class="section-controls">
45
+        <p>
46
+          </p><form method="get" action="" style="display: inline;">
47
+            <input name="control" value="stop" type="submit">
48
+          </form>
49
+          <form method="get" action="" style="display: inline;">
50
+            <input name="control" value="pause" type="submit">
51
+          </form>
52
+        
53
+        <p>
54
+          </p><form method="get" action="" style="display: inline;">
55
+            <input name="control" value="previous" type="submit">
56
+          </form>
57
+          <form method="get" action="" style="display: inline;">
58
+            <input name="control" value="next" type="submit">
59
+          </form>
60
+        
61
+        <p>
62
+          </p><form method="get" action="" style="display: inline;">
63
+            <input name="seek_value" value="-1min" type="submit"><input name="control" value="seek" type="hidden">
64
+          </form>
65
+          <form method="get" action="" style="display: inline;">
66
+            <input name="seek_value" value="+1min" type="submit"><input name="control" value="seek" type="hidden">
67
+          </form>
68
+        
69
+        <p>
70
+          </p><form method="get" action="">
71
+            <input name="seek_value" size="14" type="text"><input name="control" value="seek" type="hidden">
72
+            <input value="Seek" type="submit">
73
+          </form>
74
+        
75
+        <p>
76
+          <span class="small">( Seek Textbox: for example "+12min 42sec", "01:13:43", "-12%" etc... )</span>
77
+        </p>
78
+      </div> <!-- End section -->
79
+
80
+      <div class="sectitle">Misc controls</div>
81
+      <div class="section-controls">
82
+        <form method="get" action="">
83
+               <input name="control" value="volume" type="hidden">
84
+          Vol: <input name="value" size="5" type="text">
85
+               <input value="Set" type="submit"><br> (0 - 1024)<br><span class="small">(for example: "536", "-12", "+42", "36%")</span>
86
+        </form>
87
+        <br>
88
+        <form method="get" action="">
89
+          <input name="control" value="fullscreen" type="submit">
90
+        </form>
91
+      </div>
92
+
93
+      <div class="sectitle">Status</div>
94
+      <div class="section">
95
+        State: playing<br>
96
+        Length: <span id="length">249 s
97
+                </span><br>
98
+        Time: <span id="time">38 s</span><br>
99
+        Volume: <span id="volume">56</span>
100
+        <br><a href="http://127.0.0.1:8082/old/info.html">Information</a>  
101
+      </div>
102
+
103
+      <div class="section"><a href="http://127.0.0.1:8082/old/admin/">Administration Page</a></div>
104
+
105
+    </div>
106
+    <!-- end left -->
107
+
108
+    <!-- main content -->
109
+    <div class="right">
110
+      <h2 class="title"><a href="http://www.videolan.org/">VLC media player
111
+        0.8.6c Janus</a> (http interface)
112
+      </h2>
113
+
114
+      <div class="sectitle">Add</div>
115
+      <div class="section">
116
+        <table class="add">
117
+          <tbody><tr>
118
+	    <form method="get" action="?" enctype="text/plain"></form>
119
+              <td>Add a MRL (Media Resource Locator) to the playlist</td>
120
+              <td>
121
+               <input name="control" value="add" type="hidden">
122
+	       <input name="mrl" size="40" type="text">
123
+	       <input value="Add" type="submit">
124
+	      </td>
125
+              
126
+          </tr>
127
+	  <tr>
128
+            <form method="get" action="" enctype="text/plain"></form>
129
+              <td>Stream Output:</td>
130
+              <td>
131
+	       <input name="sout" size="40" value="" type="text">
132
+	       <input value="Sout" type="submit">
133
+	      </td>
134
+             
135
+           </tr>
136
+          </tbody></table>
137
+      </div>
138
+<!-- Playlist -->
139
+      <div class="section">
140
+       <form method="get" action="">
141
+         <ul id="playlist">
142
+           
143
+           
144
+           
145
+                 
146
+
147
+               
148
+                 <li>
149
+                   
150
+                   <img alt="Cone" src="index-1_files/cone_plus.png">
151
+                     Playlist
152
+                     
153
+                   
154
+
155
+                   
156
+                       <ul>
157
+                   
158
+
159
+               
160
+
161
+               
162
+
163
+           
164
+                 
165
+
166
+               
167
+                 <li>
168
+                   
169
+                   <img alt="[-]" src="index-1_files/cone_minus.png" onclick="changeMe(this)">
170
+                   
171
+                     <input name="item" value="3" type="checkbox">
172
+		     <a href="http://127.0.0.1:8082/old/?control=play&amp;item=3">
173
+                   
174
+		   General
175
+                   
176
+		      </a>
177
+                   
178
+		   (1
179
+		    item)
180
+                   
181
+
182
+                   
183
+                       <ul>
184
+                   
185
+
186
+               
187
+
188
+               
189
+
190
+           
191
+                 
192
+
193
+               
194
+                 
195
+                 <li>
196
+                   <input name="item" value="4" type="checkbox">
197
+                   
198
+                     <strong>
199
+                   
200
+                   <a href="http://127.0.0.1:8082/old/?control=play&amp;item=4">
201
+The Second Great Depression (/mnt/drive1/Music/aMule/Manic Street
202
+Preachers - Send Away The Tigers
203
+(2007)/05-manic_street_preachers-the_second_great_depression.mp3)</a>
204
+                   
205
+                     </strong>
206
+                   
207
+                 </li>
208
+               
209
+
210
+               
211
+
212
+           
213
+     
214
+     
215
+         </ul></li>
216
+     
217
+         </ul></li>
218
+     
219
+
220
+         </ul>
221
+         <input name="control" value="delete" type="submit">
222
+         <input name="control" value="empty" type="submit">
223
+         <input name="control" value="keep" type="submit">
224
+	              <input name="control" value="sort" type="submit"> by
225
+                     <select name="type">
226
+                       <option value="title">title</option>
227
+                       <option value="shuffle">shuffle</option>
228
+                     </select> with
229
+                     <select name="order">
230
+                       <option value="0">normal order</option>
231
+                       <option value="1">reverse order</option>
232
+                     </select>
233
+        
234
+       </form>
235
+      </div>
236
+    </div>
237
+    <!-- end main content -->
238
+    
239
+    <p style="text-align: center; font-size: 1.2em;"> VLC media player - version 0.8.6c Janus - (c) 1996-2007 the VideoLAN team </p>
240
+
241
+    <script type="text/javascript">
242
+      got_time = 38;
243
+      hours = Math.floor(got_time/ 3600);
244
+      minutes = Math.floor((got_time/60) % 60);
245
+      seconds = got_time % 60;
246
+      if ( hours < 10 ) hours = "0" + hours;
247
+      if ( minutes < 10 ) minutes = "0" + minutes;
248
+      if ( seconds < 10 ) seconds = "0" + seconds;
249
+      document.getElementById('time').innerHTML = hours+":"+minutes+":"+seconds;
250
+      got_length = 249;
251
+      hours = Math.floor(got_length/ 3600);
252
+      minutes = Math.floor((got_length/60) % 60);
253
+      seconds = got_length % 60;
254
+      if ( hours < 10 ) hours = "0" + hours;
255
+      if ( minutes < 10 ) minutes = "0" + minutes;
256
+      if ( seconds < 10 ) seconds = "0" + seconds;
257
+      document.getElementById('length').innerHTML = hours+":"+minutes+":"+seconds;
258
+      got_volume = 56;
259
+      document.getElementById( 'volume').innerHTML = Math.ceil(got_volume * 400/1024) + " %";
260
+    </script>
261
+</body></html>

+ 56
- 0
test/com/dmdirc/addons/mediasource_vlc/info-1.html Zobrazit soubor

@@ -0,0 +1,56 @@
1
+<html><head>
2
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
3
+
4
+    <title>VLC media player - Information</title>
5
+</head><body>
6
+    <h2><center><a href="http://127.0.0.1:8082/old/">VLC media player 0.8.6c Janus</a></center></h2>
7
+    <hr>
8
+    
9
+        <p> Stream 0
10
+        </p><ul>
11
+        
12
+            <li> Codec: mpga </li>
13
+        
14
+            <li> Language:  </li>
15
+        
16
+            <li> Type: Audio </li>
17
+        
18
+            <li> Channels: 2 </li>
19
+        
20
+            <li> Sample rate: 44100 Hz </li>
21
+        
22
+            <li> Bitrate: 128 kb/s </li>
23
+        
24
+        </ul>
25
+    
26
+        <p> General
27
+        </p><ul>
28
+        
29
+            <li> Duration: 0:04:09 </li>
30
+        
31
+        </ul>
32
+    
33
+        <p> Meta-information
34
+        </p><ul>
35
+        
36
+            <li> Title: The Second Great Depression </li>
37
+        
38
+            <li> Artist: Manic Street Preachers </li>
39
+        
40
+            <li> Album/movie/show title: Send Away The Tigers </li>
41
+        
42
+            <li> Date: 2007 </li>
43
+        
44
+            <li> Track number/position in set: 5 </li>
45
+        
46
+            <li> Genre: Rock </li>
47
+        
48
+            <li> Encoded by: LAME 3.90.3 Modified </li>
49
+        
50
+            <li> Language(s): English </li>
51
+        
52
+        </ul>
53
+    
54
+    <hr>
55
+    <p>VLC media player - version 0.8.6c Janus - (c) 1996-2007 the VideoLAN team </p>
56
+</body></html>

+ 60
- 0
test/com/dmdirc/addons/redirect/RedirectCommandTest.java Zobrazit soubor

@@ -0,0 +1,60 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.redirect;
24
+
25
+import com.dmdirc.MessageTarget;
26
+import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.commandparser.parsers.CommandParser;
29
+import com.dmdirc.commandparser.parsers.ServerCommandParser;
30
+import com.dmdirc.config.IdentityManager;
31
+import com.dmdirc.config.InvalidIdentityFileException;
32
+import com.dmdirc.ui.interfaces.InputWindow;
33
+import org.junit.BeforeClass;
34
+import org.junit.Test;
35
+import static org.mockito.Mockito.*;
36
+
37
+public class RedirectCommandTest {
38
+
39
+    @BeforeClass
40
+    public static void setupClass() throws InvalidIdentityFileException {
41
+        IdentityManager.load();
42
+        CommandManager.initCommands();
43
+    }
44
+
45
+    @Test
46
+    public void testExecute() {
47
+        final RedirectCommand command = new RedirectCommand();
48
+        final MessageTarget target = mock(MessageTarget.class);
49
+        final InputWindow window = mock(InputWindow.class);
50
+        when(target.getFrame()).thenReturn(window);
51
+        final CommandParser parser = new ServerCommandParser(null);
52
+        when(window.getCommandParser()).thenReturn(parser);
53
+        when(window.getConfigManager()).thenReturn(IdentityManager.getGlobalConfig());
54
+
55
+        command.execute(window, null, target, false, new CommandArguments("/redirect /echo test"));
56
+        
57
+        verify(target).sendLine("test");
58
+    }
59
+
60
+}

+ 160
- 0
test/com/dmdirc/addons/ui_swing/MainFrameTest.java Zobrazit soubor

@@ -0,0 +1,160 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing;
24
+
25
+import com.dmdirc.Main;
26
+import com.dmdirc.config.IdentityManager;
27
+import com.dmdirc.config.InvalidIdentityFileException;
28
+import com.dmdirc.harness.ui.UIClassTestRunner;
29
+import com.dmdirc.harness.ui.UITestIface;
30
+
31
+import com.dmdirc.addons.ui_swing.dialogs.FeedbackDialog;
32
+import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
33
+import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
34
+import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
35
+import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
36
+import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
37
+import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
38
+import java.lang.reflect.InvocationTargetException;
39
+import javax.swing.SwingUtilities;
40
+import org.fest.swing.finder.WindowFinder;
41
+import org.fest.swing.fixture.DialogFixture;
42
+import org.fest.swing.fixture.FrameFixture;
43
+import org.junit.After;
44
+import org.junit.Before;
45
+import org.junit.BeforeClass;
46
+import org.junit.Test;
47
+import org.junit.runner.RunWith;
48
+
49
+@RunWith(UIClassTestRunner.class)
50
+public class MainFrameTest implements UITestIface {
51
+    
52
+    private static FrameFixture window;
53
+    private DialogFixture newwin;
54
+    private static SwingController controller;
55
+
56
+    @BeforeClass
57
+    public static void setUpClass() throws InvalidIdentityFileException {
58
+        IdentityManager.load();
59
+        controller = new SwingController();
60
+        controller.onLoad();
61
+
62
+        Main.setUI(controller);
63
+        
64
+    }
65
+
66
+    @Before
67
+    public void setUp() {
68
+        if (window == null) {
69
+            window = new FrameFixture(controller.getMainWindow());
70
+            window.show();
71
+        }
72
+    }
73
+    
74
+    @Test
75
+    public void testNewServerDialog() {
76
+        window.menuItemWithPath("Server", "New Server...").click();
77
+        newwin = WindowFinder.findDialog(NewServerDialog.class)
78
+                .withTimeout(5000).using(window.robot);
79
+        newwin.requireVisible();
80
+    }
81
+    
82
+    @Test
83
+    public void testAboutDialog() {
84
+        window.menuItemWithPath("Help", "About").click();
85
+        newwin = WindowFinder.findDialog(AboutDialog.class)
86
+                .withTimeout(5000).using(window.robot);
87
+        newwin.requireVisible();
88
+    }
89
+    
90
+    @Test
91
+    public void testFeedbackDialog() {
92
+        window.menuItemWithPath("Help", "Send Feedback").click();
93
+        newwin = WindowFinder.findDialog(FeedbackDialog.class)
94
+                .withTimeout(5000).using(window.robot);
95
+        newwin.requireVisible();
96
+    }
97
+    
98
+    @Test
99
+    public void testPreferencesDialog() {
100
+        window.menuItemWithPath("Settings", "Preferences").click();
101
+        newwin = WindowFinder.findDialog(SwingPreferencesDialog.class)
102
+                .withTimeout(5000).using(window.robot);
103
+        newwin.requireVisible();
104
+    }
105
+    
106
+    @Test
107
+    public void testProfileManagerDialog() {
108
+        window.menuItemWithPath("Settings", "Profile Manager").click();
109
+        newwin = WindowFinder.findDialog(ProfileManagerDialog.class)
110
+                .withTimeout(5000).using(window.robot);
111
+        newwin.requireVisible();
112
+    }
113
+    
114
+    @Test
115
+    public void testActionsManagerDialog() {
116
+        window.menuItemWithPath("Settings", "Actions Manager").click();
117
+        newwin = WindowFinder.findDialog(ActionsManagerDialog.class)
118
+                .withTimeout(5000).using(window.robot);
119
+        newwin.requireVisible();
120
+    }
121
+    
122
+    @Test
123
+    public void testAliasManagerDialog() {
124
+        window.menuItemWithPath("Settings", "Alias Manager").click();
125
+        newwin = WindowFinder.findDialog(AliasManagerDialog.class)
126
+                .withTimeout(5000).using(window.robot);
127
+        newwin.requireVisible();
128
+    }
129
+    
130
+    @Test
131
+    public void testChannelServerSettings() {
132
+        window.menuItemWithPath("Channel", "Channel Settings").requireDisabled();
133
+    }
134
+    
135
+    @Test
136
+    public void testServerServerSettings() {
137
+        window.menuItemWithPath("Server", "Server settings").requireDisabled();
138
+    }
139
+
140
+    @Override @After
141
+    public void tearDown() throws InterruptedException, InvocationTargetException {
142
+        SwingUtilities.invokeAndWait(new Runnable() {
143
+            @Override
144
+            public void run() {
145
+                close();
146
+            }
147
+        });
148
+    }
149
+
150
+    protected void close() {
151
+        if (newwin != null && newwin.target != null) {
152
+            try {
153
+                newwin.target.dispose();
154
+            } catch (Throwable ex) {
155
+                ex.printStackTrace();
156
+            }
157
+        }
158
+    }
159
+
160
+}

+ 68
- 0
test/com/dmdirc/addons/ui_swing/UIUtilitiesTest.java Zobrazit soubor

@@ -0,0 +1,68 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing;
24
+
25
+
26
+import com.dmdirc.addons.ui_swing.UIUtilities;
27
+import com.dmdirc.addons.ui_swing.actions.RedoAction;
28
+import com.dmdirc.addons.ui_swing.actions.UndoAction;
29
+import javax.swing.JTextField;
30
+import javax.swing.KeyStroke;
31
+import javax.swing.UIManager;
32
+import javax.swing.UIManager.LookAndFeelInfo;
33
+import javax.swing.text.JTextComponent;
34
+
35
+import org.junit.Test;
36
+import static org.junit.Assert.*;
37
+
38
+public class UIUtilitiesTest {
39
+    
40
+    @Test
41
+    public void testAddUndoManager() {
42
+        final JTextComponent comp = new JTextField();
43
+        UIUtilities.addUndoManager(comp);
44
+        //check actions
45
+        assertTrue(comp.getActionMap().get("Undo") instanceof UndoAction);
46
+        assertTrue(comp.getActionMap().get("Redo") instanceof RedoAction);
47
+        //check key bindings
48
+        assertEquals("Undo", comp.getInputMap().get(KeyStroke.getKeyStroke("control Z")));
49
+        assertEquals("Redo", comp.getInputMap().get(KeyStroke.getKeyStroke("control Y")));
50
+    }
51
+
52
+    @Test
53
+    public void testGetLookAndFeel() {
54
+        final String sysLAF = UIManager.getSystemLookAndFeelClassName();
55
+        //null look and feel name = system
56
+        assertEquals(sysLAF, UIUtilities.getLookAndFeel(null));
57
+        //blank look and feel name = system
58
+        assertEquals(sysLAF, UIUtilities.getLookAndFeel(""));
59
+        //incorrect look and feel name = system
60
+        assertEquals(sysLAF, UIUtilities.getLookAndFeel("incorrectName"));
61
+        //Look and feel name -> class name
62
+        final LookAndFeelInfo[] LAFs = UIManager.getInstalledLookAndFeels();
63
+        for (LookAndFeelInfo lookAndFeel : LAFs) {
64
+            assertEquals(lookAndFeel.getClassName(), UIUtilities.getLookAndFeel(lookAndFeel.getName()));
65
+        }
66
+    }
67
+
68
+}

+ 169
- 0
test/com/dmdirc/addons/ui_swing/components/frames/InputTextFrameTest.java Zobrazit soubor

@@ -0,0 +1,169 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing.components.frames;
24
+
25
+import com.dmdirc.addons.ui_swing.components.*;
26
+import com.dmdirc.Main;
27
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
28
+import com.dmdirc.config.ConfigManager;
29
+import com.dmdirc.config.IdentityManager;
30
+import com.dmdirc.config.InvalidIdentityFileException;
31
+import com.dmdirc.harness.TestConfigManagerMap;
32
+import com.dmdirc.harness.TestWritableFrameContainer;
33
+import com.dmdirc.harness.ui.ClassFinder;
34
+import com.dmdirc.harness.ui.UIClassTestRunner;
35
+import com.dmdirc.harness.ui.UITestIface;
36
+import com.dmdirc.ui.WindowManager;
37
+import com.dmdirc.addons.ui_swing.SwingController;
38
+import com.dmdirc.addons.ui_swing.UIUtilities;
39
+import com.dmdirc.plugins.PluginManager;
40
+
41
+import java.awt.event.KeyEvent;
42
+
43
+import org.fest.swing.core.EventMode;
44
+import org.fest.swing.core.KeyPressInfo;
45
+import org.fest.swing.core.matcher.DialogByTitleMatcher;
46
+import org.fest.swing.core.matcher.JButtonByTextMatcher;
47
+import org.fest.swing.fixture.DialogFixture;
48
+import org.fest.swing.fixture.FrameFixture;
49
+import org.fest.swing.fixture.JInternalFrameFixture;
50
+import org.junit.After;
51
+import org.junit.Before;
52
+import org.junit.BeforeClass;
53
+import org.junit.Ignore;
54
+import org.junit.Test;
55
+import org.junit.runner.RunWith;
56
+
57
+
58
+@RunWith(UIClassTestRunner.class)
59
+public class InputTextFrameTest implements UITestIface {
60
+
61
+    static FrameFixture mainframe;
62
+    static JInternalFrameFixture window;
63
+    static TestConfigManagerMap cmmap;
64
+    static TestWritableFrameContainer owner;
65
+    static SwingController controller;
66
+
67
+    @BeforeClass
68
+    public static void setUpClass() throws InvalidIdentityFileException {
69
+        IdentityManager.load();
70
+        controller = new SwingController();
71
+        controller.onLoad();
72
+        Main.setUI(controller);
73
+        Main.ensureExists(PluginManager.getPluginManager(), "tabcompletion");
74
+    }
75
+
76
+    @Before
77
+    public void setUp() {
78
+        cmmap = new TestConfigManagerMap();
79
+        cmmap.settings.put("ui.pasteProtectionLimit", "1");
80
+
81
+        if (window == null) {
82
+            owner = new TestWritableFrameContainer(512, cmmap);
83
+
84
+            setupWindow(cmmap);
85
+        }
86
+    }
87
+
88
+    @After
89
+    public void tearDown() {
90
+        // ??
91
+    }
92
+
93
+    @Test
94
+    public void testPasteDialogContents() throws InterruptedException {
95
+        ((InputTextFrame) window.target).doPaste("line1\nline2");
96
+
97
+        final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
98
+                .withTitleAndShowing("Multi-line paste"));
99
+
100
+        dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
101
+        dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
102
+                .requireText("line1\nline2");
103
+        dlg.target.dispose();
104
+    }
105
+
106
+    @Test @Ignore
107
+    public void testPasteDialogWithTextBefore() throws InterruptedException {
108
+        window.textBox().enterText("testing:");
109
+        ((InputTextFrame) window.target).doPaste("line1\nline2");
110
+
111
+        final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
112
+                .withTitleAndShowing("Multi-line paste"));
113
+
114
+        dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
115
+        dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
116
+                .requireText("testing:line1\nline2");
117
+        dlg.target.dispose();
118
+    }
119
+
120
+    @Test @Ignore
121
+    public void testPasteDialogWithTextAfter() throws InterruptedException {
122
+        window.textBox().enterText("<- testing").pressAndReleaseKey(
123
+                KeyPressInfo.keyCode(KeyEvent.VK_HOME));
124
+        ((InputTextFrame) window.target).doPaste("line1\nline2");
125
+
126
+        final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
127
+                .withTitleAndShowing("Multi-line paste"));
128
+
129
+        dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
130
+        dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
131
+                .requireText("line1\nline2<- testing");
132
+        dlg.target.dispose();
133
+    }
134
+
135
+    @Test @Ignore
136
+    public void testPasteDialogWithTextAround() throws InterruptedException {
137
+        window.textBox().enterText("testing:<- testing").selectText(8, 8);
138
+        ((InputTextFrame) window.target).doPaste("line1\nline2");
139
+
140
+        final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
141
+                .withTitleAndShowing("Multi-line paste"));
142
+
143
+        dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
144
+        dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
145
+                .requireText("testing:line1\nline2<- testing");
146
+        dlg.target.dispose();
147
+    }
148
+
149
+    protected void setupWindow(final ConfigManager configManager) {
150
+        UIUtilities.initUISettings();
151
+
152
+        mainframe = new FrameFixture(controller.getMainWindow());
153
+        mainframe.robot.settings().eventMode(EventMode.AWT);
154
+
155
+        final CustomInputFrame titf = new CustomInputFrame(owner,
156
+                GlobalCommandParser.getGlobalCommandParser(), controller);
157
+
158
+        titf.setTitle("testing123");
159
+
160
+        owner.window = titf;
161
+
162
+        WindowManager.addWindow(titf);
163
+
164
+        titf.open();
165
+
166
+        window = new JInternalFrameFixture(mainframe.robot, titf);
167
+    }
168
+
169
+}

+ 211
- 0
test/com/dmdirc/addons/ui_swing/components/reorderablelist/ArrayListTransferHandlerTest.java Zobrazit soubor

@@ -0,0 +1,211 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing.components.reorderablelist;
23
+
24
+import com.dmdirc.addons.ui_swing.components.reorderablelist.ArrayListTransferHandler;
25
+import com.dmdirc.addons.ui_swing.components.reorderablelist.ArrayListTransferable;
26
+import java.awt.datatransfer.DataFlavor;
27
+import java.awt.datatransfer.Transferable;
28
+import java.awt.datatransfer.UnsupportedFlavorException;
29
+import java.io.IOException;
30
+import java.util.ArrayList;
31
+import javax.swing.DefaultListModel;
32
+import javax.swing.JList;
33
+import javax.swing.TransferHandler;
34
+import org.junit.AfterClass;
35
+import org.junit.BeforeClass;
36
+import org.junit.Test;
37
+import static org.junit.Assert.*;
38
+
39
+public class ArrayListTransferHandlerTest {
40
+
41
+
42
+    @Test
43
+    public void testCreateTransferrable() throws IOException, UnsupportedFlavorException {
44
+        final ArrayList<String> test = new ArrayList<String>();
45
+        test.add("abc");
46
+        test.add("def");
47
+        test.add(null);
48
+        
49
+        final JList list = new JList(test.toArray());
50
+        list.setSelectedIndex(0);
51
+        
52
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
53
+        final Transferable transferable = handler.createTransferable(list);
54
+        
55
+        assertNotNull(transferable);
56
+        final Object data = transferable.getTransferData(transferable.getTransferDataFlavors()[0]);
57
+        
58
+        assertTrue(data instanceof ArrayList);
59
+        assertEquals(1, ((ArrayList) data).size());
60
+        assertEquals("abc", ((ArrayList) data).get(0));
61
+    }
62
+    
63
+    @Test
64
+    public void testCreateTransferrable2() throws IOException, UnsupportedFlavorException {
65
+        final ArrayList<String> test = new ArrayList<String>();
66
+        test.add("abc");
67
+        test.add("def");
68
+        test.add(null);
69
+        
70
+        final JList list = new JList(test.toArray());
71
+        
72
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
73
+        final Transferable transferable = handler.createTransferable(list);
74
+        
75
+        assertNull(transferable);
76
+    }    
77
+    
78
+    @Test
79
+    public void testCreateTransferrable3() throws IOException, UnsupportedFlavorException {
80
+        final ArrayList<Object> test = new ArrayList<Object>();
81
+        test.add(new Object() {
82
+
83
+            @Override
84
+            public String toString() {
85
+                return null;
86
+            }
87
+            
88
+        });
89
+        test.add("def");
90
+        test.add(null);
91
+        
92
+        final JList list = new JList(test.toArray());
93
+        list.setSelectedIndex(0);
94
+        
95
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
96
+        final Transferable transferable = handler.createTransferable(list);
97
+        
98
+        assertNotNull(transferable);
99
+        final Object data = transferable.getTransferData(transferable.getTransferDataFlavors()[0]);
100
+        
101
+        assertTrue(data instanceof ArrayList);
102
+        assertEquals(1, ((ArrayList) data).size());
103
+        assertEquals("", ((ArrayList) data).get(0));
104
+    }    
105
+    
106
+    @Test
107
+    public void testCreateTransferrable4() throws IOException, UnsupportedFlavorException {
108
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
109
+        final Transferable transferable = handler.createTransferable(null);
110
+        
111
+        assertNull(transferable);
112
+    }
113
+    
114
+    @Test
115
+    public void testCanImport() {
116
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
117
+        final ArrayListTransferable transferable = new ArrayListTransferable(null);
118
+        final JList list = new JList(new DefaultListModel());
119
+        
120
+        for (DataFlavor df : transferable.getTransferDataFlavors()) {
121
+            assertTrue(handler.canImport(list, new DataFlavor[]{df}));
122
+            assertFalse(handler.canImport(null, new DataFlavor[]{df}));
123
+        }
124
+        
125
+        assertFalse(handler.canImport(list, new DataFlavor[]{}));
126
+    }
127
+    
128
+    @Test
129
+    public void testImportData() {
130
+        final ArrayList<String> test = new ArrayList<String>();
131
+        test.add("abc");
132
+        test.add("def");
133
+        test.add(null);
134
+        
135
+        final JList list = new JList(new DefaultListModel());
136
+        ((DefaultListModel) list.getModel()).addElement("123");
137
+        ((DefaultListModel) list.getModel()).addElement("456");
138
+        list.setSelectedIndex(0);
139
+        
140
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
141
+        final ArrayListTransferable alt = new ArrayListTransferable(test);
142
+        
143
+        handler.createTransferable(new JList(new DefaultListModel()));
144
+        
145
+        assertTrue(handler.importData(list, alt));
146
+        assertEquals(5, list.getModel().getSize());
147
+        assertEquals("123", list.getModel().getElementAt(0));
148
+        assertEquals("abc", list.getModel().getElementAt(1));
149
+        assertEquals(null, list.getModel().getElementAt(3));
150
+        assertEquals("456", list.getModel().getElementAt(4));
151
+    }
152
+    
153
+    @Test
154
+    public void testImportData2() {
155
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
156
+        final ArrayListTransferable alt = new ArrayListTransferable(null);
157
+        assertFalse(handler.importData(null, alt));
158
+    }
159
+    
160
+    @Test
161
+    public void testExportDone() {
162
+        final ArrayList<String> test = new ArrayList<String>();
163
+        test.add("123");
164
+        test.add("456");
165
+        
166
+        final JList list = new JList(new DefaultListModel());
167
+        ((DefaultListModel) list.getModel()).addElement("123");
168
+        ((DefaultListModel) list.getModel()).addElement("456");
169
+        list.setSelectedIndex(0);
170
+        
171
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
172
+        final ArrayListTransferable alt = new ArrayListTransferable(test);
173
+        
174
+        handler.createTransferable(list);
175
+        
176
+        final JList list2 = new JList(new DefaultListModel());
177
+        list2.setSelectedIndex(0);
178
+        assertTrue(handler.importData(list2, alt));
179
+        
180
+        handler.exportDone(list, alt, TransferHandler.MOVE);
181
+        assertEquals(1, list.getModel().getSize());
182
+        assertEquals("456", list.getModel().getElementAt(0));
183
+    }
184
+    
185
+    @Test
186
+    public void testExportDone2() {
187
+        final ArrayList<String> test = new ArrayList<String>();
188
+        test.add("123");
189
+        test.add("456");
190
+        
191
+        final JList list = new JList(new DefaultListModel());
192
+        ((DefaultListModel) list.getModel()).addElement("123");
193
+        ((DefaultListModel) list.getModel()).addElement("456");
194
+        list.setSelectedIndex(0);
195
+        
196
+        final ArrayListTransferHandler handler = new ArrayListTransferHandler();
197
+        final ArrayListTransferable alt = new ArrayListTransferable(test);
198
+        
199
+        handler.createTransferable(list);
200
+        
201
+        final JList list2 = new JList(new DefaultListModel());
202
+        list2.setSelectedIndex(0);
203
+        assertTrue(handler.importData(list2, alt));
204
+        
205
+        handler.exportDone(list, alt, TransferHandler.COPY);
206
+        assertEquals(2, list.getModel().getSize());
207
+        assertEquals("123", list.getModel().getElementAt(0));
208
+        assertEquals("456", list.getModel().getElementAt(1));
209
+    }        
210
+
211
+}

+ 70
- 0
test/com/dmdirc/addons/ui_swing/components/reorderablelist/ArrayListTransferableTest.java Zobrazit soubor

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing.components.reorderablelist;
23
+
24
+import com.dmdirc.addons.ui_swing.components.reorderablelist.ArrayListTransferable;
25
+import java.awt.datatransfer.UnsupportedFlavorException;
26
+import java.util.ArrayList;
27
+
28
+import org.junit.Before;
29
+import org.junit.Test;
30
+import static org.junit.Assert.*;
31
+
32
+public class ArrayListTransferableTest {
33
+    
34
+    ArrayList<String> testData;
35
+    
36
+    @Before
37
+    public void setUp() {
38
+        testData = new ArrayList<String>();
39
+        testData.add("abc");
40
+        testData.add("def");
41
+    }
42
+
43
+    @Test(expected=UnsupportedFlavorException.class)
44
+    public void getTransferDataInvalid() throws Exception {
45
+        final ArrayListTransferable alt = new ArrayListTransferable(testData);
46
+        alt.getTransferData(null);
47
+    }
48
+    
49
+    @Test
50
+    public void getTransferData() throws Exception {
51
+        final ArrayListTransferable alt = new ArrayListTransferable(testData);
52
+        
53
+        assertSame(testData, alt.getTransferData(alt.getTransferDataFlavors()[0]));
54
+    }    
55
+
56
+    @Test
57
+    public void isDataFlavorSupported1() {
58
+        final ArrayListTransferable alt = new ArrayListTransferable(testData);
59
+        
60
+        assertTrue(alt.isDataFlavorSupported(alt.getTransferDataFlavors()[0]));
61
+    }
62
+    
63
+    @Test
64
+    public void isDataFlavorSupported2() {
65
+        final ArrayListTransferable alt = new ArrayListTransferable(testData);
66
+        
67
+        assertFalse(alt.isDataFlavorSupported(null));
68
+    }
69
+
70
+}

+ 333
- 0
test/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialogTest.java Zobrazit soubor

@@ -0,0 +1,333 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing.dialogs.actioneditor;
24
+
25
+import com.dmdirc.Main;
26
+import com.dmdirc.actions.Action;
27
+import com.dmdirc.actions.ActionManager;
28
+import com.dmdirc.addons.ui_swing.SwingController;
29
+import com.dmdirc.config.IdentityManager;
30
+import com.dmdirc.config.InvalidIdentityFileException;
31
+import com.dmdirc.harness.ui.UIClassTestRunner;
32
+import com.dmdirc.harness.ui.ClassFinder;
33
+import com.dmdirc.harness.ui.UITestIface;
34
+import com.dmdirc.harness.ui.JRadioButtonByTextMatcher;
35
+
36
+import com.dmdirc.addons.ui_swing.components.ImageButton;
37
+import com.dmdirc.addons.ui_swing.components.text.TextLabel;
38
+import com.dmdirc.logger.ErrorLevel;
39
+import com.dmdirc.logger.Logger;
40
+import java.awt.Component;
41
+
42
+import java.util.regex.Matcher;
43
+import java.util.regex.Pattern;
44
+import javax.swing.JButton;
45
+import javax.swing.JPanel;
46
+import javax.swing.JTextField;
47
+import javax.swing.text.JTextComponent;
48
+
49
+import org.fest.swing.core.EventMode;
50
+import org.fest.swing.core.matcher.JButtonByTextMatcher;
51
+import org.fest.swing.core.matcher.JLabelByTextMatcher;
52
+import org.fest.swing.fixture.DialogFixture;
53
+import org.fest.swing.fixture.JLabelFixture;
54
+import org.fest.swing.fixture.JPanelFixture;
55
+import org.junit.After;
56
+import org.junit.Before;
57
+import org.junit.BeforeClass;
58
+import org.junit.Test;
59
+import org.junit.runner.RunWith;
60
+import static org.junit.Assert.*;
61
+
62
+@RunWith(UIClassTestRunner.class)
63
+public class ActionEditorDialogTest implements UITestIface {
64
+
65
+    private DialogFixture window;
66
+
67
+    @BeforeClass
68
+    public static void setUpClass() throws InvalidIdentityFileException {
69
+        Main.setUI(new SwingController());
70
+    }
71
+
72
+    @Before
73
+    @Override
74
+    public void setUp() throws InvalidIdentityFileException {
75
+        IdentityManager.load();
76
+        ActionManager.init();
77
+
78
+        if (!ActionManager.getGroups().containsKey("amd-ui-test1")) {
79
+            ActionManager.makeGroup("amd-ui-test1");
80
+        }
81
+    }
82
+
83
+    @After
84
+    @Override
85
+    public void tearDown() {
86
+        if (window != null) {
87
+            window.cleanUp();
88
+        }
89
+
90
+        if (ActionManager.getGroups().containsKey("amd-ui-test1")) {
91
+            ActionManager.removeGroup("amd-ui-test1");
92
+        }
93
+    }
94
+
95
+    @Test
96
+    public void testName() {
97
+        setupWindow(null);
98
+
99
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
100
+                textBox().requireEnabled().requireEditable().requireEmpty();
101
+        window.button(JButtonByTextMatcher.withText("OK")).requireDisabled();
102
+    }
103
+
104
+    @Test
105
+    public void testIssue1785() {
106
+        // Invalidating+validating name allows enables OK button despite invalid conditions
107
+        // 'Fix' was disabling the add trigger button when name was invalid
108
+        setupWindow(null);
109
+
110
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
111
+                textBox().requireEnabled().requireEditable().requireEmpty();
112
+        window.panel(new ClassFinder<JPanel>(ActionTriggersPanel.class, null)).
113
+                button(JButtonByTextMatcher.withText("Add")).requireDisabled();
114
+    }
115
+
116
+    @Test
117
+    public void testTriggerWithNoArgs() {
118
+        setupWindow(null);
119
+
120
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
121
+                textBox().enterText("test1");
122
+        final JPanelFixture triggers = window.panel(
123
+                new ClassFinder<JPanel>(ActionTriggersPanel.class, null));
124
+
125
+        triggers.comboBox().selectItem("Client closed");
126
+        triggers.button(JButtonByTextMatcher.withText("Add")).requireEnabled().
127
+                click();
128
+
129
+        window.panel(new ClassFinder<JPanel>(ActionConditionsPanel.class, null)).
130
+                button(JButtonByTextMatcher.withText("Add")).requireDisabled();
131
+    }
132
+
133
+    @Test
134
+    public void testBasicTriggers() {
135
+        setupWindow(null);
136
+
137
+        final JPanelFixture triggers = window.panel(
138
+                new ClassFinder<JPanel>(ActionTriggersPanel.class, null));
139
+        triggers.comboBox().requireDisabled();
140
+
141
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
142
+                textBox().enterText("test1");
143
+
144
+        final int items = triggers.comboBox().target.getItemCount();
145
+        triggers.comboBox().requireEnabled().selectItem("Channel message received");
146
+        triggers.button(JButtonByTextMatcher.withText("Add")).requireEnabled().
147
+                click();
148
+
149
+        final JLabelFixture label =
150
+                triggers.label(JLabelByTextMatcher.withText("Channel message received"));
151
+        label.requireVisible();
152
+
153
+        assertTrue(items > triggers.comboBox().target.getItemCount());
154
+        window.button(JButtonByTextMatcher.withText("OK")).requireEnabled();
155
+
156
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
157
+                textBox().deleteText();
158
+        triggers.button(new ClassFinder<JButton>(ImageButton.class, null)).
159
+                requireDisabled();
160
+        triggers.comboBox().requireDisabled();
161
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
162
+                textBox().enterText("test1");
163
+
164
+        triggers.button(new ClassFinder<JButton>(ImageButton.class, null)).
165
+                requireEnabled().click();
166
+
167
+        for (Component comp : triggers.panel(new ClassFinder<JPanel>(ActionTriggersListPanel.class,
168
+                null)).target.getComponents()) {
169
+            assertNotSame(label.target, comp);
170
+        }
171
+
172
+        assertEquals(items, triggers.comboBox().target.getItemCount());
173
+        window.button(JButtonByTextMatcher.withText("OK")).requireDisabled();
174
+    }
175
+
176
+    @Test
177
+    public void testBasicConditionTrees() {
178
+        setupWindow(null);
179
+
180
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
181
+                textBox().enterText("test1");
182
+        final JPanelFixture triggers = window.panel(
183
+                new ClassFinder<JPanel>(ActionTriggersPanel.class, null));
184
+
185
+        triggers.comboBox().selectItem("Channel message received");
186
+        triggers.button(JButtonByTextMatcher.withText("Add")).requireEnabled().
187
+                click();
188
+
189
+        window.radioButton(new JRadioButtonByTextMatcher("All of the conditions are true")).
190
+                requireEnabled().requireSelected();
191
+        window.radioButton(new JRadioButtonByTextMatcher("At least one of the conditions is true")).
192
+                requireEnabled();
193
+        window.radioButton(new JRadioButtonByTextMatcher("The conditions match a custom rule")).
194
+                requireEnabled();
195
+        window.panel(new ClassFinder<JPanel>(ActionConditionsTreePanel.class,
196
+                null)).textBox(new ClassFinder<JTextComponent>(JTextField.class,
197
+                null)).requireDisabled();
198
+
199
+        window.button(JButtonByTextMatcher.withText("OK")).requireEnabled();
200
+
201
+        window.radioButton(new JRadioButtonByTextMatcher("The conditions match a custom rule")).
202
+                click().requireSelected();
203
+        window.panel(new ClassFinder<JPanel>(ActionConditionsTreePanel.class,
204
+                null)).textBox(new ClassFinder<JTextComponent>(JTextField.class,
205
+                null)).requireEnabled().enterText("invalid");
206
+
207
+        window.button(JButtonByTextMatcher.withText("OK")).requireDisabled();
208
+    }
209
+
210
+    @Test
211
+    public void testConditionText() {        
212
+        setupWindow(null);
213
+
214
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
215
+                textBox().enterText("test1");
216
+        final JPanelFixture triggers = window.panel(
217
+                new ClassFinder<JPanel>(ActionTriggersPanel.class, null));
218
+
219
+        triggers.comboBox().selectItem("Channel message received");
220
+        triggers.button(JButtonByTextMatcher.withText("Add")).requireEnabled().
221
+                click();
222
+
223
+        window.panel(new ClassFinder<JPanel>(ActionConditionsPanel.class, null)).
224
+                button(JButtonByTextMatcher.withText("Add")).requireEnabled().
225
+                click();
226
+        
227
+        Pattern pattern = Pattern.compile(".+<body>(.+)</body>.+", Pattern.DOTALL);
228
+        
229
+        Matcher matcher = pattern.matcher(window.panel(new ClassFinder<JPanel>(ActionConditionDisplayPanel.class,
230
+                null)).textBox(new ClassFinder<JTextComponent>(TextLabel.class,
231
+                null)).target.getText());
232
+        matcher.find();
233
+        assertEquals("<p style=\"margin-top: 0\">\n      \n    </p>", matcher.group(1).trim());
234
+
235
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
236
+                null)).comboBox("argument").selectItem("message");
237
+        
238
+        matcher = pattern.matcher(window.panel(new ClassFinder<JPanel>(ActionConditionDisplayPanel.class,
239
+                null)).textBox(new ClassFinder<JTextComponent>(TextLabel.class,
240
+                null)).target.getText());
241
+        matcher.find();
242
+        assertEquals("The message's ...", matcher.group(1).trim());
243
+
244
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
245
+                null)).comboBox("component").selectItem("content");
246
+        
247
+        matcher = pattern.matcher(window.panel(new ClassFinder<JPanel>(ActionConditionDisplayPanel.class,
248
+                null)).textBox(new ClassFinder<JTextComponent>(TextLabel.class,
249
+                null)).target.getText());
250
+        matcher.find();
251
+        assertEquals("The message's content ...", matcher.group(1).trim());
252
+
253
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
254
+                null)).comboBox("comparison").selectItem("contains");
255
+        
256
+        matcher = pattern.matcher(window.panel(new ClassFinder<JPanel>(ActionConditionDisplayPanel.class,
257
+                null)).textBox(new ClassFinder<JTextComponent>(TextLabel.class,
258
+                null)).target.getText());
259
+        matcher.find();
260
+        assertEquals("The message's content contains ''", matcher.group(1).trim());
261
+
262
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
263
+                null)).textBox().enterText("foo");
264
+        
265
+        matcher = pattern.matcher(window.panel(new ClassFinder<JPanel>(ActionConditionDisplayPanel.class,
266
+                null)).textBox(new ClassFinder<JTextComponent>(TextLabel.class,
267
+                null)).target.getText());
268
+        matcher.find();
269
+        assertEquals("The message's content contains 'foo'", matcher.group(1).trim());
270
+    }
271
+
272
+    @Test
273
+    public void testIllegalCondition() {
274
+        setupWindow(null);
275
+
276
+        window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).
277
+                textBox().enterText("test1");
278
+        final JPanelFixture triggers = window.panel(
279
+                new ClassFinder<JPanel>(ActionTriggersPanel.class, null));
280
+
281
+        triggers.comboBox().selectItem("Channel message received");
282
+        triggers.button(JButtonByTextMatcher.withText("Add")).requireEnabled().
283
+                click();
284
+
285
+        window.button(JButtonByTextMatcher.withText("OK")).requireEnabled();
286
+
287
+        window.panel(new ClassFinder<JPanel>(ActionConditionsPanel.class, null)).
288
+                button(JButtonByTextMatcher.withText("Add")).requireEnabled().
289
+                click();
290
+
291
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
292
+                null)).comboBox("argument").requireEnabled();
293
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
294
+                null)).comboBox("component").requireDisabled();
295
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
296
+                null)).comboBox("comparison").requireDisabled();
297
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
298
+                null)).textBox().requireDisabled();
299
+        window.button(JButtonByTextMatcher.withText("OK")).requireDisabled();
300
+
301
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
302
+                null)).comboBox("argument").selectItem("message");
303
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
304
+                null)).comboBox("component").requireEnabled();
305
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
306
+                null)).comboBox("comparison").requireDisabled();
307
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
308
+                null)).textBox().requireDisabled();
309
+        window.button(JButtonByTextMatcher.withText("OK")).requireDisabled();
310
+
311
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
312
+                null)).comboBox("component").selectItem("content");
313
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
314
+                null)).comboBox("comparison").requireEnabled();
315
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
316
+                null)).textBox().requireDisabled();
317
+        window.button(JButtonByTextMatcher.withText("OK")).requireDisabled();
318
+
319
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
320
+                null)).comboBox("comparison").selectItem("contains");
321
+        window.panel(new ClassFinder<JPanel>(ActionConditionEditorPanel.class,
322
+                null)).textBox().requireEnabled();
323
+        window.button(JButtonByTextMatcher.withText("OK")).requireEnabled();
324
+    }
325
+
326
+    protected void setupWindow(final Action action) {
327
+        window = new DialogFixture(ActionEditorDialog.getActionEditorDialog(null,
328
+                "amd-ui-test1", action));
329
+        window.robot.settings().eventMode(EventMode.AWT);
330
+        window.show();
331
+    }
332
+
333
+}

+ 239
- 0
test/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialogTest.java Zobrazit soubor

@@ -0,0 +1,239 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing.dialogs.actionsmanager;
24
+
25
+import com.dmdirc.Main;
26
+import com.dmdirc.actions.ActionManager;
27
+import com.dmdirc.addons.ui_swing.SwingController;
28
+import com.dmdirc.config.IdentityManager;
29
+import com.dmdirc.config.InvalidIdentityFileException;
30
+import com.dmdirc.harness.ui.UIClassTestRunner;
31
+import com.dmdirc.harness.ui.ClassFinder;
32
+import com.dmdirc.harness.ui.UITestIface;
33
+
34
+import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
35
+import com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionEditorDialog;
36
+import java.lang.reflect.InvocationTargetException;
37
+import javax.swing.JPanel;
38
+import javax.swing.SwingUtilities;
39
+import javax.swing.text.JTextComponent;
40
+
41
+import org.fest.swing.core.EventMode;
42
+import org.fest.swing.core.matcher.JButtonByTextMatcher;
43
+import org.fest.swing.finder.JOptionPaneFinder;
44
+import org.fest.swing.finder.WindowFinder;
45
+import org.fest.swing.fixture.DialogFixture;
46
+import org.fest.swing.fixture.JOptionPaneFixture;
47
+import org.junit.After;
48
+import org.junit.Before;
49
+import org.junit.BeforeClass;
50
+import org.junit.Test;
51
+import org.junit.runner.RunWith;
52
+import static org.junit.Assert.*;
53
+
54
+@RunWith(UIClassTestRunner.class)
55
+public class ActionsManagerDialogTest implements UITestIface {
56
+    
57
+    private DialogFixture window;
58
+
59
+    @BeforeClass
60
+    public static void setUpClass() throws InvalidIdentityFileException {
61
+        Main.setUI(new SwingController());
62
+        IdentityManager.load();
63
+        ActionManager.init();
64
+    }
65
+    
66
+    @Before
67
+    public void setUp() {
68
+        removeGroups();
69
+    }
70
+    
71
+    @After
72
+    public void tearDown() throws InterruptedException, InvocationTargetException {
73
+        SwingUtilities.invokeAndWait(new Runnable() {
74
+            @Override
75
+            public void run() {
76
+                close();
77
+            }
78
+        });
79
+
80
+        removeGroups();
81
+    }
82
+
83
+    protected void close() {
84
+        if (window != null) {
85
+            window.cleanUp();
86
+        }
87
+    }
88
+    
89
+    protected void removeGroups() {
90
+        if (ActionManager.getGroups().containsKey("amd-ui-test1")) {
91
+            ActionManager.removeGroup("amd-ui-test1");
92
+        }
93
+        
94
+        if (ActionManager.getGroups().containsKey("amd-ui-test2")) {
95
+            ActionManager.removeGroup("amd-ui-test2");
96
+        }
97
+    }
98
+    
99
+    @Test
100
+    public void testAddGroup() throws InterruptedException {
101
+        setupWindow();
102
+        
103
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
104
+                .button(JButtonByTextMatcher.withText("Add")).click();
105
+        
106
+        DialogFixture newwin = WindowFinder.findDialog(StandardInputDialog.class)
107
+                .withTimeout(5000).using(window.robot);
108
+                
109
+        newwin.requireVisible();
110
+        assertEquals("New action group", newwin.target.getTitle());
111
+        
112
+        newwin.button(JButtonByTextMatcher.withText("Cancel")).click();
113
+        
114
+        newwin.requireNotVisible();
115
+        
116
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
117
+                .button(JButtonByTextMatcher.withText("Add")).click();
118
+        
119
+        newwin = WindowFinder.findDialog(StandardInputDialog.class)
120
+                .withTimeout(5000).using(window.robot);
121
+        
122
+        newwin.requireVisible();
123
+        newwin.button(JButtonByTextMatcher.withText("OK")).requireDisabled();
124
+        
125
+        newwin.textBox(new ClassFinder<JTextComponent>(javax.swing.JTextField.class,
126
+                null)).enterText("amd-ui-test1");
127
+        
128
+        newwin.button(JButtonByTextMatcher.withText("OK")).requireEnabled().click();
129
+        
130
+        window.list().requireSelectedItems("amd-ui-test1");
131
+
132
+        assertTrue(ActionManager.getGroups().containsKey("amd-ui-test1"));
133
+    }
134
+    
135
+    @Test
136
+    public void testDeleteGroup() {
137
+        ActionManager.makeGroup("amd-ui-test1");
138
+        setupWindow();
139
+               
140
+        window.list().selectItem("amd-ui-test1").requireSelectedItems("amd-ui-test1");
141
+        
142
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
143
+                .button(JButtonByTextMatcher.withText("Delete")).requireEnabled().click();
144
+        
145
+        JOptionPaneFixture newwin = JOptionPaneFinder.findOptionPane()
146
+                .withTimeout(5000).using(window.robot);
147
+        newwin.buttonWithText("No").click();
148
+        
149
+        assertTrue(ActionManager.getGroups().containsKey("amd-ui-test1"));
150
+        window.list().selectItem("amd-ui-test1").requireSelectedItems("amd-ui-test1");
151
+        
152
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
153
+                .button(JButtonByTextMatcher.withText("Delete")).click();
154
+        
155
+        newwin = JOptionPaneFinder.findOptionPane()
156
+                .withTimeout(5000).using(window.robot);
157
+        newwin.buttonWithText("Yes").click();
158
+        
159
+        assertTrue(window.list().selection().length != 1 ||   
160
+                !window.list().selection()[0].equals("amd-ui-test1"));
161
+                
162
+        assertFalse(ActionManager.getGroups().containsKey("amd-ui-test1"));
163
+    }
164
+    
165
+    @Test
166
+    public void testEnablingGroupButtons() {
167
+        ActionManager.makeGroup("amd-ui-test1");
168
+        setupWindow();
169
+        
170
+        window.list().selectItem("performs").requireSelectedItems("performs");
171
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
172
+                .button(JButtonByTextMatcher.withText("Delete")).requireDisabled();
173
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
174
+                .button(JButtonByTextMatcher.withText("Edit")).requireDisabled();
175
+        
176
+        window.list().selectItem("amd-ui-test1").requireSelectedItems("amd-ui-test1");
177
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
178
+                .button(JButtonByTextMatcher.withText("Delete")).requireEnabled();
179
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
180
+                .button(JButtonByTextMatcher.withText("Edit")).requireEnabled();
181
+    }
182
+
183
+    @Test
184
+    public void testAddAction() {
185
+        ActionManager.makeGroup("amd-ui-test1");
186
+        setupWindow();
187
+        window.list().selectItem("amd-ui-test1").requireSelectedItems("amd-ui-test1");
188
+        window.panel(new ClassFinder<JPanel>(ActionsGroupPanel.class, null))
189
+                .button(JButtonByTextMatcher.withText("Add")).click();
190
+
191
+        DialogFixture newwin = WindowFinder.findDialog(ActionEditorDialog.class)
192
+                .withTimeout(5000).using(window.robot);
193
+        newwin.requireVisible();
194
+    }
195
+    
196
+    public void editGroupCheck(final String button) {
197
+        ActionManager.makeGroup("amd-ui-test1");
198
+        setupWindow();
199
+        
200
+        window.list().selectItem("amd-ui-test1").requireSelectedItems("amd-ui-test1");
201
+        window.panel(new ClassFinder<JPanel>(JPanel.class, "Groups"))
202
+                .button(JButtonByTextMatcher.withText("Edit")).requireEnabled().click();
203
+        
204
+        DialogFixture newwin = WindowFinder.findDialog(StandardInputDialog.class)
205
+                .withTimeout(5000).using(window.robot);
206
+                
207
+        newwin.requireVisible();
208
+        assertEquals("Edit action group", newwin.target.getTitle());
209
+        
210
+        assertEquals("amd-ui-test1", 
211
+                newwin.textBox(new ClassFinder<JTextComponent>(javax.swing.JTextField.class,
212
+                null)).target.getText());
213
+        
214
+        newwin.textBox(new ClassFinder<JTextComponent>(javax.swing.JTextField.class,
215
+                null)).deleteText().enterText("amd-ui-test2");
216
+        newwin.button(JButtonByTextMatcher.withText(button)).requireEnabled().click();
217
+    }
218
+    
219
+    @Test
220
+    public void testEditGroupCancel() {
221
+        editGroupCheck("Cancel");
222
+        assertTrue(ActionManager.getGroups().containsKey("amd-ui-test1"));
223
+        assertFalse(ActionManager.getGroups().containsKey("amd-ui-test2"));
224
+    }
225
+    
226
+    @Test
227
+    public void testEditGroupOK() {
228
+        editGroupCheck("OK");
229
+        assertFalse(ActionManager.getGroups().containsKey("amd-ui-test1"));
230
+        assertTrue(ActionManager.getGroups().containsKey("amd-ui-test2"));
231
+    }
232
+    
233
+    protected void setupWindow() {
234
+        window = new DialogFixture(ActionsManagerDialog.getActionsManagerDialog(null, null));
235
+        window.robot.settings().eventMode(EventMode.AWT);
236
+        window.show();
237
+    }
238
+
239
+}

+ 102
- 0
test/com/dmdirc/addons/ui_swing/dialogs/profiles/ProfileManagerDialogTest.java Zobrazit soubor

@@ -0,0 +1,102 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing.dialogs.profiles;
24
+
25
+import com.dmdirc.Main;
26
+import com.dmdirc.addons.ui_swing.SwingController;
27
+import com.dmdirc.addons.ui_swing.UIUtilities;
28
+import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
29
+import com.dmdirc.config.prefs.validator.FileNameValidator;
30
+import com.dmdirc.config.prefs.validator.IdentValidator;
31
+import com.dmdirc.config.prefs.validator.NotEmptyValidator;
32
+import com.dmdirc.harness.ui.UIClassTestRunner;
33
+import com.dmdirc.harness.ui.UITestIface;
34
+import com.dmdirc.harness.ui.ClassFinder;
35
+import com.dmdirc.harness.ui.ValidatingJTextFieldFinder;
36
+
37
+import javax.swing.JList;
38
+
39
+import javax.swing.JPanel;
40
+import org.fest.swing.core.EventMode;
41
+import org.fest.swing.fixture.DialogFixture;
42
+
43
+import org.junit.After;
44
+import org.junit.Before;
45
+import org.junit.BeforeClass;
46
+import org.junit.Test;
47
+import org.junit.runner.RunWith;
48
+import static org.junit.Assert.*;
49
+
50
+@RunWith(UIClassTestRunner.class)
51
+public class ProfileManagerDialogTest implements UITestIface {
52
+
53
+    private DialogFixture window;
54
+    private Profile profile;
55
+
56
+    @BeforeClass
57
+    public static void setUpClass() {
58
+        Main.setUI(new SwingController());
59
+    }
60
+
61
+    @Before
62
+    public void setUp() {
63
+        UIUtilities.initUISettings();
64
+        profile = new Profile("unit-test1", "nick1", "real name", "ident");
65
+        profile.save();
66
+    }
67
+
68
+    @After
69
+    public void tearDown() {
70
+        if (window != null) {
71
+            window.cleanUp();
72
+        }
73
+
74
+        profile.delete();
75
+    }
76
+
77
+    @Test
78
+    public void testDetails() {
79
+        setupWindow();
80
+
81
+        window.list(new ClassFinder<JList>(JList.class, null))
82
+                .selectItem("unit-test1").requireSelection("unit-test1");
83
+        window.textBox(new ValidatingJTextFieldFinder(FileNameValidator.class))
84
+                .requireText("unit-test1"); // Profile name
85
+        window.textBox(new ValidatingJTextFieldFinder(NotEmptyValidator.class))
86
+                .requireText("real name"); // Real name
87
+        window.textBox(new ValidatingJTextFieldFinder(IdentValidator.class))
88
+                .requireText("ident"); // Ident
89
+
90
+        assertEquals(1,
91
+                window.list(new ClassFinder<ReorderableJList>(ReorderableJList.class, null))
92
+                .selectItem("nick1").requireSelection("nick1").contents().length);
93
+    }
94
+
95
+    protected void setupWindow() {
96
+        window = new DialogFixture(ProfileManagerDialog.getProfileManagerDialog(null));
97
+
98
+        window.robot.settings().eventMode(EventMode.AWT);
99
+        window.show();
100
+    }
101
+
102
+}

+ 138
- 0
test/com/dmdirc/addons/ui_swing/dialogs/sslcertificate/SSLCertificateDialogTest.java Zobrazit soubor

@@ -0,0 +1,138 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.ui_swing.dialogs.sslcertificate;
24
+
25
+import com.dmdirc.Main;
26
+import com.dmdirc.addons.ui_swing.SwingController;
27
+import com.dmdirc.harness.ui.ClassFinder;
28
+import com.dmdirc.harness.ui.TestSSLCertificateDialogModel;
29
+import com.dmdirc.harness.ui.UIClassTestRunner;
30
+import com.dmdirc.harness.ui.UITestIface;
31
+import com.dmdirc.ui.IconManager;
32
+import com.dmdirc.addons.ui_swing.UIUtilities;
33
+
34
+import java.awt.Component;
35
+import java.util.Arrays;
36
+
37
+import javax.swing.Icon;
38
+import javax.swing.JLabel;
39
+import javax.swing.JList;
40
+import javax.swing.JScrollPane;
41
+import javax.swing.border.TitledBorder;
42
+
43
+import org.fest.swing.core.EventMode;
44
+import org.fest.swing.driver.BasicJListCellReader;
45
+import org.fest.swing.fixture.DialogFixture;
46
+
47
+import org.junit.After;
48
+import org.junit.Before;
49
+import org.junit.BeforeClass;
50
+import org.junit.Test;
51
+import org.junit.runner.RunWith;
52
+import static org.junit.Assert.*;
53
+
54
+@RunWith(UIClassTestRunner.class)
55
+public class SSLCertificateDialogTest implements UITestIface {
56
+
57
+    private DialogFixture window;
58
+
59
+    @BeforeClass
60
+    public static void setUpClass() {
61
+        Main.setUI(new SwingController());
62
+    }
63
+
64
+    @Before
65
+    public void setUp() {
66
+        UIUtilities.initUISettings();
67
+    }
68
+
69
+    @After
70
+    public void tearDown() {
71
+        if (window != null) {
72
+            window.cleanUp();
73
+        }
74
+    }
75
+
76
+    @Test
77
+    public void testTicksAndCrosses() {
78
+        setupWindow();
79
+
80
+        assertTrue(Arrays.equals(new String[]{
81
+            "first cert",
82
+            "second cert",
83
+            "invalid cert",
84
+            "trusted cert",
85
+            "invalid+trusted"
86
+        }, window.list().contents()));
87
+
88
+        assertTrue(Arrays.equals(new String[]{
89
+            "nothing",
90
+            "nothing",
91
+            "cross",
92
+            "tick",
93
+            "cross"
94
+        },window.list().cellReader(new CertificateListCellReader()).contents()));
95
+    }
96
+
97
+    @Test
98
+    public void testSelection() {
99
+        setupWindow();
100
+
101
+        window.list().requireSelection("first cert");
102
+        
103
+        for (String cert : window.list().contents()) {
104
+            window.list().selectItem(cert).requireSelection(cert);
105
+
106
+            assertEquals("Information for " + cert, ((TitledBorder) window
107
+                    .scrollPane(new ClassFinder<JScrollPane>(CertificateInfoPanel.class, null))
108
+                    .target.getBorder()).getTitle());
109
+        }
110
+    }
111
+
112
+    protected void setupWindow() {
113
+        window = new DialogFixture(new SSLCertificateDialog(null,
114
+                new TestSSLCertificateDialogModel()));
115
+
116
+        window.robot.settings().eventMode(EventMode.AWT);
117
+        window.show();
118
+    }
119
+
120
+    private static class CertificateListCellReader extends BasicJListCellReader {
121
+
122
+        public String valueAt(JList arg0, int arg1) {
123
+            final Component c = cellRendererComponent(arg0, arg1);
124
+
125
+            final Icon target = ((JLabel) c).getIcon();
126
+            
127
+            for (String icon : new String[]{"tick", "cross", "nothing"}) {
128
+                if (target == IconManager.getIconManager().getIcon(icon)) {
129
+                    return icon;
130
+                }
131
+            }
132
+
133
+            return "?";
134
+        }
135
+
136
+    }
137
+
138
+}

+ 67
- 0
test/com/dmdirc/addons/urlcatcher/UrlCatcherPluginTest.java Zobrazit soubor

@@ -0,0 +1,67 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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.addons.urlcatcher;
24
+
25
+import com.dmdirc.actions.CoreActionType;
26
+import com.dmdirc.config.IdentityManager;
27
+import com.dmdirc.config.InvalidIdentityFileException;
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class UrlCatcherPluginTest {
32
+
33
+    @Test
34
+    public void testURLCounting() throws InvalidIdentityFileException {
35
+        IdentityManager.load();
36
+        
37
+        final UrlCatcherPlugin plugin = new UrlCatcherPlugin();
38
+
39
+        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
40
+                null, "This is a message - http://www.google.com/ foo");
41
+        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
42
+                null, "This is a message - http://www.google.com/ foo");
43
+        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
44
+                null, "This is a message - http://www.google.com/ foo");
45
+        
46
+        assertEquals(1, plugin.getURLS().size());
47
+        assertEquals(3, (int) plugin.getURLS().get("http://www.google.com/"));
48
+    }
49
+    
50
+    @Test
51
+    public void testURLCatching() throws InvalidIdentityFileException {
52
+        IdentityManager.load();
53
+        
54
+        final UrlCatcherPlugin plugin = new UrlCatcherPlugin();
55
+
56
+        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
57
+                null, "http://www.google.com/ www.example.com foo://bar.baz");
58
+        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
59
+                null, "No URLs here, no sir!");        
60
+        
61
+        assertEquals(3, plugin.getURLS().size());
62
+        assertTrue(plugin.getURLS().containsKey("http://www.google.com/"));
63
+        assertTrue(plugin.getURLS().containsKey("www.example.com"));
64
+        assertTrue(plugin.getURLS().containsKey("foo://bar.baz"));
65
+    }    
66
+
67
+}

Načítá se…
Zrušit
Uložit