30 * <li> UI-robot based test for TextBox. |
30 * <li> UI-robot based test for TextBox. |
31 * |
31 * |
32 * <br><br> |
32 * <br><br> |
33 * Created: 2008-04-25 |
33 * Created: 2008-04-25 |
34 */ |
34 */ |
35 public class TestUITextBox extends UITestBase { |
35 public class TestUITextBox extends UITestBase |
|
36 { |
36 |
37 |
37 private static final int LENGTH = 100; |
38 private static final int LENGTH = 100; |
38 private static final int EXPECTED_CARET_POSITION = 5; |
39 private static final int EXPECTED_CARET_POSITION = 5; |
39 |
40 |
40 private TextBox textbox; |
41 private TextBox textbox; |
41 private int[] inputTextShort = new int[]{'7', '8', '8', '9', |
42 private int[] inputTextShort = new int[] {'7', '8', '8', '9', |
42 '4', '5', '5', '5', '5', }; |
43 '4', '5', '5', '5', '5', |
|
44 }; |
43 private int[] inputSentence = new int [] {'3', '3', '8', '8', '8', |
45 private int[] inputSentence = new int [] {'3', '3', '8', '8', '8', |
44 '3', '3', '7', '7', '7', |
46 '3', '3', '7', '7', '7', |
45 '9', '9', '9', '1', '0', '9', |
47 '9', '9', '9', '1', '0', '9', |
46 '6', '6', '6', '7', '7', |
48 '6', '6', '6', '7', '7', |
47 '7', '3', '0', '4', '4', |
49 '7', '3', '0', '4', '4', |
48 '4', '7', '7', '7', '7', |
50 '4', '7', '7', '7', '7', |
49 '0', '2', '2', '2', }; |
51 '0', '2', '2', '2', |
|
52 }; |
50 |
53 |
51 /** |
54 /** |
52 * Constructor. |
55 * Constructor. |
53 */ |
56 */ |
54 public TestUITextBox() { |
57 public TestUITextBox() |
|
58 { |
55 } |
59 } |
56 |
60 |
57 /** |
61 /** |
58 * Constructor. |
62 * Constructor. |
59 * |
63 * |
60 * @param sTestName name of the test |
64 * @param sTestName name of the test |
61 * @param rTestMethod TestMethod used |
65 * @param rTestMethod TestMethod used |
62 */ |
66 */ |
63 public TestUITextBox(String sTestName, TestMethod rTestMethod) { |
67 public TestUITextBox(String sTestName, TestMethod rTestMethod) |
|
68 { |
64 super(sTestName, rTestMethod); |
69 super(sTestName, rTestMethod); |
65 } |
70 } |
66 |
71 |
67 /** |
72 /** |
68 * Creates new test suite.You need to add a new aSuite.addTest entry for |
73 * Creates new test suite.You need to add a new aSuite.addTest entry for |
69 * any new test methods, otherwise they won't be run. |
74 * any new test methods, otherwise they won't be run. |
70 * @return suite |
75 * @return suite |
71 */ |
76 */ |
72 public Test suite() { |
77 public Test suite() |
|
78 { |
73 TestSuite aSuite = new TestSuite(); |
79 TestSuite aSuite = new TestSuite(); |
74 |
80 |
75 aSuite.addTest(new TestUITextBox("testNormalInputMode()", |
81 aSuite.addTest(new TestUITextBox("testNormalInputMode()", |
76 new TestMethod() { |
82 new TestMethod() |
77 public void run(TestCase tc) { |
83 { |
78 ((TestUITextBox) tc).testNormalInputMode(); |
84 public void run(TestCase tc) |
79 } |
85 { |
80 })); |
86 ((TestUITextBox) tc).testNormalInputMode(); |
81 aSuite.addTest(new TestUITextBox("testNonEditable()", new TestMethod() { |
87 } |
82 public void run(TestCase tc) { |
88 })); |
|
89 aSuite.addTest(new TestUITextBox("testNonEditable()", new TestMethod() |
|
90 { |
|
91 public void run(TestCase tc) |
|
92 { |
83 ((TestUITextBox) tc).testNonEditable(); |
93 ((TestUITextBox) tc).testNonEditable(); |
84 } |
94 } |
85 })); |
95 })); |
86 aSuite.addTest(new TestUITextBox("testCapSent()", new TestMethod() { |
96 aSuite.addTest(new TestUITextBox("testCapSent()", new TestMethod() |
87 public void run(TestCase tc) { |
97 { |
|
98 public void run(TestCase tc) |
|
99 { |
88 ((TestUITextBox) tc).testCapSent(); |
100 ((TestUITextBox) tc).testCapSent(); |
89 } |
101 } |
90 })); |
102 })); |
91 aSuite.addTest(new TestUITextBox("testGetCaretPosition()", |
103 aSuite.addTest(new TestUITextBox("testGetCaretPosition()", |
92 new TestMethod() { |
104 new TestMethod() |
93 public void run(TestCase tc) { |
105 { |
94 ((TestUITextBox) tc).testGetCaretPosition(); |
106 public void run(TestCase tc) |
95 } |
107 { |
96 })); |
108 ((TestUITextBox) tc).testGetCaretPosition(); |
|
109 } |
|
110 })); |
97 return aSuite; |
111 return aSuite; |
98 } |
112 } |
99 |
113 |
100 /** |
114 /** |
101 * This method tests that TextBox getString, returns |
115 * This method tests that TextBox getString, returns |
102 * correct text which was inputed with UIRobot. |
116 * correct text which was inputed with UIRobot. |
103 */ |
117 */ |
104 public void testNormalInputMode() { |
118 public void testNormalInputMode() |
|
119 { |
105 textbox = new TextBox("ANY", "", LENGTH, TextField.ANY); |
120 textbox = new TextBox("ANY", "", LENGTH, TextField.ANY); |
106 String getString; |
121 String getString; |
107 |
122 |
108 setCurrent(textbox); |
123 setCurrent(textbox); |
109 for (int i = 0; i < inputTextShort.length; i++) { |
124 for(int i = 0; i < inputTextShort.length; i++) |
|
125 { |
110 key(inputTextShort[i], 0); |
126 key(inputTextShort[i], 0); |
111 } |
127 } |
112 getString = textbox.getString(); |
128 getString = textbox.getString(); |
113 assertTrue("Expected: TextBox.getText() returns: " |
129 assertTrue("Expected: TextBox.getText() returns: " |
114 + "Puwg5. But returned " |
130 + "Puwg5. But returned " |
115 + getString, getString.equals("Puwg5")); |
131 + getString, getString.equals("Puwg5")); |
116 textbox = null; |
132 textbox = null; |
117 } |
133 } |
118 |
134 |
119 /** |
135 /** |
120 * Test that TextBox is not editable if |
136 * Test that TextBox is not editable if |
121 * UNEDITABLE is specified in constructor. |
137 * UNEDITABLE is specified in constructor. |
122 */ |
138 */ |
123 public void testNonEditable() { |
139 public void testNonEditable() |
|
140 { |
124 textbox = new TextBox("No Edit", "editing is not allowed", LENGTH, |
141 textbox = new TextBox("No Edit", "editing is not allowed", LENGTH, |
125 TextField.UNEDITABLE | TextField.ANY); |
142 TextField.UNEDITABLE | TextField.ANY); |
126 String getString; |
143 String getString; |
127 |
144 |
128 setCurrent(textbox); |
145 setCurrent(textbox); |
129 for (int i = 0; i < inputTextShort.length; i++) { |
146 for(int i = 0; i < inputTextShort.length; i++) |
|
147 { |
130 key(inputTextShort[i], 0); |
148 key(inputTextShort[i], 0); |
131 } |
149 } |
132 getString = textbox.getString(); |
150 getString = textbox.getString(); |
133 assertTrue("Expected: TextBox.getText() returns: " |
151 assertTrue("Expected: TextBox.getText() returns: " |
134 + "editing is not allowed. But returned " + getString, |
152 + "editing is not allowed. But returned " + getString, |
135 getString.equals("editing is not allowed")); |
153 getString.equals("editing is not allowed")); |
136 textbox = null; |
154 textbox = null; |
137 } |
155 } |
138 |
156 |
139 /** |
157 /** |
140 * Test that TextBox behaves correctly if INITIAL_CAPS_WORD specified. |
158 * Test that TextBox behaves correctly if INITIAL_CAPS_WORD specified. |
141 * every word should start with capital letter. |
159 * every word should start with capital letter. |
142 * TODO: waiting for fixes from eSWT. |
160 * TODO: waiting for fixes from eSWT. |
143 */ |
161 */ |
144 public void testCapWord() { |
162 public void testCapWord() |
|
163 { |
145 textbox = new TextBox("Capital Words", "", LENGTH, |
164 textbox = new TextBox("Capital Words", "", LENGTH, |
146 TextField.INITIAL_CAPS_WORD | TextField.ANY); |
165 TextField.INITIAL_CAPS_WORD | TextField.ANY); |
147 String getString; |
166 String getString; |
148 |
167 |
149 setCurrent(textbox); |
168 setCurrent(textbox); |
150 for (int i = 0; i < inputSentence.length; i++) { |
169 for(int i = 0; i < inputSentence.length; i++) |
|
170 { |
151 key(inputSentence[i], 0); |
171 key(inputSentence[i], 0); |
152 } |
172 } |
153 getString = textbox.getString(); |
173 getString = textbox.getString(); |
154 assertTrue("Expected: TextBox.getText() returns: " |
174 assertTrue("Expected: TextBox.getText() returns: " |
155 + "Every. Word Is C. But returned " + getString, getString |
175 + "Every. Word Is C. But returned " + getString, getString |
156 .equals("Every. Word Is C")); |
176 .equals("Every. Word Is C")); |
157 textbox = null; |
177 textbox = null; |
158 |
178 |
159 } |
179 } |
160 |
180 |
161 /** |
181 /** |
162 * Test that TextBox behaves correctly if INITIAL_CAPS_SENTENCE specified. |
182 * Test that TextBox behaves correctly if INITIAL_CAPS_SENTENCE specified. |
163 * every sentence should start with capital letter. |
183 * every sentence should start with capital letter. |
164 */ |
184 */ |
165 public void testCapSent() { |
185 public void testCapSent() |
|
186 { |
166 textbox = new TextBox("Capital Sentence", "", LENGTH, |
187 textbox = new TextBox("Capital Sentence", "", LENGTH, |
167 TextField.INITIAL_CAPS_SENTENCE | TextField.ANY); |
188 TextField.INITIAL_CAPS_SENTENCE | TextField.ANY); |
168 String getString; |
189 String getString; |
169 |
190 |
170 setCurrent(textbox); |
191 setCurrent(textbox); |
171 for (int i = 0; i < inputSentence.length; i++) { |
192 for(int i = 0; i < inputSentence.length; i++) |
|
193 { |
172 key(inputSentence[i], 0); |
194 key(inputSentence[i], 0); |
173 } |
195 } |
174 getString = textbox.getString(); |
196 getString = textbox.getString(); |
175 assertTrue("Expected: TextBox.getText() return: " |
197 assertTrue("Expected: TextBox.getText() return: " |
176 + "Every word is c. But returned " + getString, getString |
198 + "Every word is c. But returned " + getString, getString |
177 .equals("Every. Word is c")); |
199 .equals("Every. Word is c")); |
178 textbox = null; |
200 textbox = null; |
179 } |
201 } |
180 |
202 |
181 /** |
203 /** |
182 * TextBox.getCaretPosition() test. |
204 * TextBox.getCaretPosition() test. |
183 * Tests that getCaretPosition works correctly. |
205 * Tests that getCaretPosition works correctly. |
184 */ |
206 */ |
185 public void testGetCaretPosition() { |
207 public void testGetCaretPosition() |
|
208 { |
186 int getCaretPosition = 0; |
209 int getCaretPosition = 0; |
187 textbox = new TextBox("Get Caret", "", LENGTH, |
210 textbox = new TextBox("Get Caret", "", LENGTH, |
188 TextField.INITIAL_CAPS_SENTENCE | TextField.ANY); |
211 TextField.INITIAL_CAPS_SENTENCE | TextField.ANY); |
189 |
212 |
190 setCurrent(textbox); |
213 setCurrent(textbox); |
191 for (int i = 0; i < inputTextShort.length; i++) { |
214 for(int i = 0; i < inputTextShort.length; i++) |
|
215 { |
192 key(inputTextShort[i], 0); |
216 key(inputTextShort[i], 0); |
193 } |
217 } |
194 |
218 |
195 getCaretPosition = textbox.getCaretPosition(); |
219 getCaretPosition = textbox.getCaretPosition(); |
196 assertTrue("TextBox.getCaretPosition(). Expected: returns " |
220 assertTrue("TextBox.getCaretPosition(). Expected: returns " |
197 + EXPECTED_CARET_POSITION + " but got " + getCaretPosition, |
221 + EXPECTED_CARET_POSITION + " but got " + getCaretPosition, |
198 getCaretPosition == EXPECTED_CARET_POSITION); |
222 getCaretPosition == EXPECTED_CARET_POSITION); |
199 textbox = null; |
223 textbox = null; |
200 } |
224 } |
201 |
225 |
202 } |
226 } |