Procházet zdrojové kódy

Unit test for issue 1845


git-svn-id: http://svn.dmdirc.com/trunk@4842 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6.3m1rc1
Chris Smith před 15 roky
rodič
revize
100ee42985

+ 6
- 3
test/com/dmdirc/harness/TestWritableFrameContainer.java Zobrazit soubor

@@ -22,7 +22,8 @@
22 22
 
23 23
 package com.dmdirc.harness;
24 24
 
25
-import com.dmdirc.*;
25
+import com.dmdirc.Server;
26
+import com.dmdirc.WritableFrameContainer;
26 27
 import com.dmdirc.config.ConfigManager;
27 28
 import com.dmdirc.config.IdentityManager;
28 29
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -42,7 +43,8 @@ public class TestWritableFrameContainer extends WritableFrameContainer {
42 43
         this(lineLength, IdentityManager.getGlobalConfig());
43 44
     }
44 45
 
45
-    public void sendLine(String line) {
46
+    public void sendLine(final String line) {
47
+        // Do nothing
46 48
     }
47 49
 
48 50
     public InputWindow getFrame() {
@@ -54,10 +56,11 @@ public class TestWritableFrameContainer extends WritableFrameContainer {
54 56
     }
55 57
 
56 58
     public String toString() {
57
-        return null;
59
+        return "window";
58 60
     }
59 61
 
60 62
     public void windowClosing() {
63
+        // Do nothing
61 64
     }
62 65
 
63 66
     public Server getServer() {

+ 0
- 69
test/com/dmdirc/harness/ui/TestInputTextFrame.java Zobrazit soubor

@@ -1,69 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.harness.ui;
24
-
25
-import com.dmdirc.WritableFrameContainer;
26
-import com.dmdirc.commandparser.PopupType;
27
-import com.dmdirc.commandparser.parsers.CommandParser;
28
-import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
-import com.dmdirc.ui.swing.components.InputTextFrame;
30
-
31
-import javax.swing.JPopupMenu;
32
-
33
-public class TestInputTextFrame extends InputTextFrame {
34
-
35
-    public TestInputTextFrame(WritableFrameContainer owner) {
36
-        super(owner);
37
-    }
38
-
39
-    @Override
40
-    public void addCustomPopupItems(JPopupMenu popupMenu) {
41
-        return;
42
-    }
43
-
44
-    @Override
45
-    public PopupType getChannelPopupType() {
46
-        return PopupType.CHAN_CHANNEL;
47
-    }
48
-
49
-    @Override
50
-    public PopupType getHyperlinkPopupType() {
51
-        return PopupType.CHAN_CHANNEL;
52
-    }
53
-
54
-    @Override
55
-    public PopupType getNicknamePopupType() {
56
-        return PopupType.CHAN_CHANNEL;
57
-    }
58
-
59
-    @Override
60
-    public PopupType getNormalPopupType() {
61
-        return PopupType.CHAN_CHANNEL;
62
-    }
63
-
64
-    @Override
65
-    public CommandParser getCommandParser() {
66
-        return GlobalCommandParser.getGlobalCommandParser();
67
-    }
68
-
69
-}

+ 96
- 24
test/com/dmdirc/ui/swing/components/InputTextFrameTest.java Zobrazit soubor

@@ -23,22 +23,29 @@
23 23
 package com.dmdirc.ui.swing.components;
24 24
 
25 25
 import com.dmdirc.WritableFrameContainer;
26
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
26 27
 import com.dmdirc.config.ConfigManager;
27 28
 import com.dmdirc.config.IdentityManager;
28 29
 import com.dmdirc.harness.TestConfigManagerMap;
29 30
 import com.dmdirc.harness.TestWritableFrameContainer;
30
-import com.dmdirc.harness.ui.TestInputTextFrame;
31
+import com.dmdirc.harness.ui.ClassFinder;
31 32
 import com.dmdirc.harness.ui.UIClassTestRunner;
32 33
 import com.dmdirc.harness.ui.UITestIface;
33 34
 
34 35
 import com.dmdirc.ui.WindowManager;
36
+import com.dmdirc.ui.interfaces.Window;
37
+import com.dmdirc.ui.swing.CustomInputFrame;
35 38
 import com.dmdirc.ui.swing.SwingController;
39
+import com.dmdirc.ui.swing.UIUtilities;
36 40
 import java.awt.Toolkit;
37 41
 import java.awt.datatransfer.StringSelection;
38 42
 import java.awt.event.KeyEvent;
43
+import javax.swing.text.JTextComponent;
39 44
 import org.fest.swing.core.EventMode;
40 45
 import org.fest.swing.core.KeyPressInfo;
41 46
 import org.fest.swing.core.matcher.DialogByTitleMatcher;
47
+import org.fest.swing.core.matcher.JButtonByTextMatcher;
48
+import org.fest.swing.fixture.DialogFixture;
42 49
 import org.fest.swing.fixture.FrameFixture;
43 50
 import org.fest.swing.fixture.JInternalFrameFixture;
44 51
 import org.fest.swing.util.Platform;
@@ -52,10 +59,10 @@ import static org.junit.Assert.*;
52 59
 @RunWith(UIClassTestRunner.class)
53 60
 public class InputTextFrameTest implements UITestIface {
54 61
 
55
-    FrameFixture mainframe;
56
-    JInternalFrameFixture window;
57
-    TestConfigManagerMap cmmap;
58
-    TestWritableFrameContainer owner;
62
+    static FrameFixture mainframe;
63
+    static JInternalFrameFixture window;
64
+    static TestConfigManagerMap cmmap;
65
+    static TestWritableFrameContainer owner;
59 66
 
60 67
     @Before
61 68
     public void setUp() {
@@ -64,36 +71,99 @@ public class InputTextFrameTest implements UITestIface {
64 71
         cmmap = new TestConfigManagerMap();
65 72
         cmmap.settings.put("ui.pasteProtectionLimit", "1");
66 73
 
67
-        owner = new TestWritableFrameContainer(512, cmmap);
74
+        if (window == null) {
75
+            owner = new TestWritableFrameContainer(512, cmmap);
76
+
77
+            setupWindow(cmmap);
78
+        }
68 79
     }
69 80
 
70 81
     @After
71 82
     public void tearDown() {
72
-        if (window != null) {
73
-            window.close();
74
-        }
75
-
76
-        if (mainframe != null) {
77
-            mainframe.close();
78
-        }
83
+        // ??
79 84
     }
80 85
 
81 86
     @Test
82 87
     public void testPasteDialogAppearing() throws InterruptedException {
83
-        setupWindow(cmmap);
88
+        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
89
+                new StringSelection("line1\nline2"), null);
84 90
 
91
+        window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
92
+                .modifiers(Platform.controlOrCommandMask()));
93
+        mainframe.dialog(DialogByTitleMatcher.withTitleAndShowing("Multi-line paste"))
94
+                .requireVisible().close();
95
+    }
96
+
97
+    @Test
98
+    public void testPasteDialogContents() throws InterruptedException {
85 99
         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
86 100
                 new StringSelection("line1\nline2"), null);
87 101
 
88
-        while (true) {
89
-            Thread.yield();
90
-            Thread.sleep(1000);
91
-        }
102
+        window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
103
+                .modifiers(Platform.controlOrCommandMask()));
104
+
105
+        final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
106
+                .withTitleAndShowing("Multi-line paste"));
92 107
 
93
-        //window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_C)
94
-        //        .modifiers(Platform.controlOrCommandMask()));
95
-        //mainframe.dialog(DialogByTitleMatcher.withTitle("Multi-line paste")).
96
-          //      requireVisible();
108
+        dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
109
+        dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
110
+                .requireText("line1\nline2");
111
+        dlg.close();
112
+    }
113
+
114
+    @Test
115
+    public void testPasteDialogWithTextBefore() throws InterruptedException {
116
+        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
117
+                new StringSelection("line1\nline2"), null);
118
+
119
+        window.textBox().enterText("testing:");
120
+        window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
121
+                .modifiers(Platform.controlOrCommandMask()));
122
+
123
+        final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
124
+                .withTitleAndShowing("Multi-line paste"));
125
+
126
+        dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
127
+        dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
128
+                .requireText("testing:line1\nline2");
129
+        dlg.close();
130
+    }
131
+
132
+    @Test
133
+    public void testPasteDialogWithTextAfter() throws InterruptedException {
134
+        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
135
+                new StringSelection("line1\nline2"), null);
136
+
137
+        window.textBox().enterText("<- testing").pressAndReleaseKey(
138
+                KeyPressInfo.keyCode(KeyEvent.VK_HOME));
139
+        window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
140
+                .modifiers(Platform.controlOrCommandMask()));
141
+
142
+        final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
143
+                .withTitleAndShowing("Multi-line paste"));
144
+
145
+        dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
146
+        dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
147
+                .requireText("line1\nline2<- testing");
148
+        dlg.close();
149
+    }
150
+
151
+    @Test
152
+    public void testPasteDialogWithTextAround() throws InterruptedException {
153
+        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
154
+                new StringSelection("line1\nline2"), null);
155
+
156
+        window.textBox().enterText("testing:<- testing").selectText(8, 8);
157
+        window.textBox().pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_V)
158
+                .modifiers(Platform.controlOrCommandMask()));
159
+
160
+        final DialogFixture dlg = mainframe.dialog(DialogByTitleMatcher
161
+                .withTitleAndShowing("Multi-line paste"));
162
+
163
+        dlg.requireVisible().button(JButtonByTextMatcher.withText("Edit")).click();
164
+        dlg.textBox(new ClassFinder<TextAreaInputField>(TextAreaInputField.class, null))
165
+                .requireText("testing:line1\nline2<- testing");
166
+        dlg.close();
97 167
     }
98 168
 
99 169
     public static junit.framework.Test suite() {
@@ -101,10 +171,13 @@ public class InputTextFrameTest implements UITestIface {
101 171
     }
102 172
 
103 173
     protected void setupWindow(final ConfigManager configManager) {
174
+        UIUtilities.initUISettings();
175
+
104 176
         mainframe = new FrameFixture(SwingController.getMainFrame());
105 177
         mainframe.robot.settings().eventMode(EventMode.AWT);
106 178
 
107
-        final TestInputTextFrame titf = new TestInputTextFrame(owner);
179
+        final CustomInputFrame titf = new CustomInputFrame(owner,
180
+                GlobalCommandParser.getGlobalCommandParser());
108 181
 
109 182
         titf.setTitle("testing123");
110 183
 
@@ -113,7 +186,6 @@ public class InputTextFrameTest implements UITestIface {
113 186
         WindowManager.addWindow(titf);
114 187
 
115 188
         titf.open();
116
-        titf.show();
117 189
 
118 190
         window = new JInternalFrameFixture(mainframe.robot, titf);
119 191
     }

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