xref: /trunk/test/testgui/source/fvt/gui/sc/validity/ValidityDialogSetting.java (revision 3078b051c2c8f087aaab7571803d11e249d796b8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package fvt.gui.sc.validity;
23 
24 import static org.junit.Assert.*;
25 import static testlib.gui.AppTool.*;
26 import static testlib.gui.UIMap.*;
27 
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Ignore;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.openoffice.test.common.Logger;
34 
35 import testlib.gui.AppTool;
36 import testlib.gui.SCTool;
37 
38 public class ValidityDialogSetting {
39 
40     @Before
41     public void setUp() throws Exception {
42         app.start(true);
43         AppTool.newSpreadsheet();
44         SCTool.selectRange("A1:C5");
45         app.dispatch(".uno:Validation");
46     }
47 
48     @After
49     public void tearDown() throws Exception {
50         app.stop();
51     }
52 
53     /**
54      * test Allow not between Date type in Validity.
55      */
56     @Test
57     public void testAllowDateNotBetween() {
58         scValidityCriteriaTabpage.select();
59         scValidityCriteriaAllowList.select(3); // "Date"
60         scValidityDecimalCompareOperator.select(7); // "not between"
61         scValiditySourceInput.setText("01/01/08");
62         scValidityMaxValueInput.setText("03/01/08");
63         scValidityErrorAlertTabPage.select();
64         scValidityShowErrorMessage.check();
65         scValidityErrorMessageTitle.setText("Stop to enter");
66         scValidityErrorMessage.setText("Invalid value");
67         scValidityErrorAlertTabPage.ok();
68 
69         SCTool.selectRange("A1");
70         scInputBarInput.activate();
71         typeKeys("12/31/07");
72         typeKeys("<enter>");
73         assertEquals("12/31/07", SCTool.getCellText("A1"));
74 
75         SCTool.selectRange("A2");
76         scInputBarInput.activate();
77         typeKeys("03/02/08");
78         typeKeys("<enter>");
79         assertEquals("03/02/08", SCTool.getCellText("A2"));
80 
81         SCTool.selectRange("A3");
82         scInputBarInput.activate();
83         typeKeys("01/01/08");
84         typeKeys("<enter>");
85         assertEquals("Invalid value", activeMsgBox.getMessage());
86         activeMsgBox.ok();
87         assertEquals("", SCTool.getCellText("A3"));
88 
89         SCTool.selectRange("A4");
90         scInputBarInput.activate();
91         typeKeys("03/01/08");
92         typeKeys("<enter>");
93         assertEquals("Invalid value", activeMsgBox.getMessage());
94         activeMsgBox.ok();
95         assertEquals("", SCTool.getCellText("A4"));
96 
97         SCTool.selectRange("A5");
98         scInputBarInput.activate();
99         typeKeys("01/02/08");
100         typeKeys("<enter>");
101         assertEquals("Invalid value", activeMsgBox.getMessage());
102         activeMsgBox.ok();
103         assertEquals("", SCTool.getCellText("A5"));
104 
105         SCTool.selectRange("B1");
106         scInputBarInput.activate();
107         typeKeys("02/29/08");
108         typeKeys("<enter>");
109         assertEquals("Invalid value", activeMsgBox.getMessage());
110         activeMsgBox.ok();
111         assertEquals("", SCTool.getCellText("B1"));
112 
113         SCTool.selectRange("B2");
114         scInputBarInput.activate();
115         typeKeys("test");
116         typeKeys("<enter>");
117         assertEquals("Invalid value", activeMsgBox.getMessage());
118         activeMsgBox.ok();
119         assertEquals("", SCTool.getCellText("B2"));
120 
121         SCTool.selectRange("B3");
122         scInputBarInput.activate();
123         typeKeys("39448");
124         typeKeys("<enter>");
125         assertEquals("Invalid value", activeMsgBox.getMessage());
126         activeMsgBox.ok();
127         assertEquals("", SCTool.getCellText("B3"));
128     }
129 
130     /**
131      * test Allow Decimal equal in Validity.
132      */
133     @Test
134     public void testAllowDecimalEqual() {
135 
136         scValidityCriteriaTabpage.select();
137         scValidityCriteriaAllowList.select(2); // "Decimal"
138         scValidityDecimalCompareOperator.select(0); // "equal"
139         scValiditySourceInput.setText("0.33333333");
140         scValidityErrorAlertTabPage.select();
141         scValidityShowErrorMessage.check();
142         scValidityErrorMessageTitle.setText("Stop to enter");
143         scValidityErrorMessage.setText("Invalid value");
144         scValidityErrorAlertTabPage.ok();
145 
146         SCTool.selectRange("A1");
147         scInputBarInput.activate();
148         typeKeys("0.33333333");
149         typeKeys("<enter>");
150         assertEquals("0.33333333", SCTool.getCellText("A1"));
151 
152         SCTool.selectRange("A2");
153         scInputBarInput.activate();
154         typeKeys("=1/3");
155         typeKeys("<enter>");
156         assertEquals("Invalid value", activeMsgBox.getMessage());
157         activeMsgBox.ok();
158         assertEquals("", SCTool.getCellText("A2"));
159 
160         SCTool.selectRange("A3");
161         scInputBarInput.activate();
162         typeKeys("0.3");
163         typeKeys("<enter>");
164         assertEquals("Invalid value", activeMsgBox.getMessage());
165         activeMsgBox.ok();
166         assertEquals("", SCTool.getCellText("A3"));
167 
168         SCTool.selectRange("A4");
169         scInputBarInput.activate();
170         typeKeys("0.333333333");
171         typeKeys("<enter>");
172         assertEquals("Invalid value", activeMsgBox.getMessage());
173         activeMsgBox.ok();
174         assertEquals("", SCTool.getCellText("A4"));
175 
176         SCTool.selectRange("B2");
177         scInputBarInput.activate();
178         typeKeys("test");
179         typeKeys("<enter>");
180         assertEquals("Invalid value", activeMsgBox.getMessage());
181         activeMsgBox.ok();
182         assertEquals("", SCTool.getCellText("B2"));
183     }
184 
185     /**
186      * test Allow Text length, greater than or equal to in Validity.
187      */
188     @Test
189     public void testAllowGreaterTextLength() {
190 
191         scValidityCriteriaTabpage.select();
192         scValidityCriteriaAllowList.select(7); // "Text length"
193         scValidityDecimalCompareOperator.select(4); // "greater than or equal to"
194         scValiditySourceInput.setText("10");
195         scValidityErrorAlertTabPage.select();
196         scValidityShowErrorMessage.check();
197         scValidityErrorMessageTitle.setText("Stop to enter");
198         scValidityErrorMessage.setText("Invalid value");
199         scValidityErrorAlertTabPage.ok();
200 
201         SCTool.selectRange("A1");
202         scInputBarInput.activate();
203         typeKeys("testtesttesttest");
204         typeKeys("<enter>");
205         assertEquals("testtesttesttest", SCTool.getCellText("A1"));
206 
207         SCTool.selectRange("A2");
208         scInputBarInput.activate();
209         typeKeys("test test ");
210         typeKeys("<enter>");
211         assertEquals("test test ", SCTool.getCellText("A2"));
212 
213         SCTool.selectRange("A4");
214         scInputBarInput.activate();
215         typeKeys(" ");
216         typeKeys("<enter>");
217         assertEquals("Invalid value", activeMsgBox.getMessage());
218         activeMsgBox.ok();
219         assertEquals("", SCTool.getCellText("A4"));
220 
221         SCTool.selectRange("A3");
222         scInputBarInput.activate();
223         typeKeys("Testatest");
224         typeKeys("<enter>");
225         assertEquals("Invalid value", activeMsgBox.getMessage());
226         activeMsgBox.ok();
227         assertEquals("", SCTool.getCellText("A3"));
228     }
229 
230     /**
231      * test Allow Text length, less than in Validity.
232      */
233     @Test
234     public void testAllowLessThanTextLength() {
235 
236         scValidityCriteriaTabpage.select();
237         scValidityCriteriaAllowList.select(7); // "Text length"
238         scValidityDecimalCompareOperator.select(1); // "less than"
239         scValiditySourceInput.setText("10");
240 
241         scValidityInputHelpTabPage.select();
242         scValidityInputHelpCheckbox.check();
243         scValidityInputHelpTitle.setText("Help Info Title");
244         scValidityHelpMessage.setText("help info");
245 
246         scValidityErrorAlertTabPage.select();
247         scValidityShowErrorMessage.check();
248         scValidityErrorAlertActionList.select("Information");
249         scValidityErrorMessageTitle.setText("Notes to enter");
250         scValidityErrorMessage.setText("Invalid value");
251         scValidityErrorAlertTabPage.ok();
252 
253         SCTool.selectRange("A1");
254         scInputBarInput.activate();
255         typeKeys("testtesttesttest<enter>");
256         activeMsgBox.ok();
257         assertEquals("testtesttesttest", SCTool.getCellText("A1"));
258 
259         SCTool.selectRange("A2");
260         scInputBarInput.activate();
261         typeKeys("sfsafsddddddd<enter>");
262         activeMsgBox.cancel();
263         assertEquals("", SCTool.getCellText("A2"));
264 
265         SCTool.selectRange("A2");
266         scInputBarInput.activate();
267         typeKeys("10<enter>");
268         assertEquals("10", SCTool.getCellText("A2"));
269 
270         SCTool.selectRange("A3");
271         scInputBarInput.activate();
272         typeKeys("ok<enter>");
273         assertEquals("ok", SCTool.getCellText("A3"));
274     }
275 
276     /**
277      * test Allow list.
278      */
279     @Test
280     public void testAllowListSpecialChar() {
281 
282         scValidityCriteriaTabpage.select();
283         scValidityCriteriaAllowList.select(6); // "List"
284         scValidityEntries.focus();
285         typeKeys("a");
286         typeKeys("<enter>");
287         typeKeys("b");
288         scValidityErrorAlertTabPage.select();
289         scValidityShowErrorMessage.check();
290         scValidityErrorMessageTitle.setText("Stop to enter");
291         scValidityErrorMessage.setText("Invalid value");
292         scValidityCriteriaTabpage.select();
293         scValidityCriteriaTabpage.ok();
294 
295         // These codes are not stable: start
296         // calc.rightClick(1, 1);
297         // typeKeys("<shift s>");
298         // typeKeys("<down><enter>"); // Choose a
299         // sleep(2); // if no sleep, error occur
300         // These codes are not stable: end
301         SCTool.selectRange("A1");
302         scInputBarInput.activate();
303         typeKeys("a<enter>");
304         assertEquals("a", SCTool.getCellText("A1"));
305 
306         SCTool.selectRange("B2");
307         scInputBarInput.activate();
308         typeKeys("test");
309         typeKeys("<enter>");
310         assertEquals("Invalid value", activeMsgBox.getMessage());
311         activeMsgBox.ok();
312         assertEquals("", SCTool.getCellText("B2"));
313     }
314 
315     /**
316      * test Allow time between in Validity.
317      */
318     @Test
319     public void testAllowTimeBetween() {
320 
321         scValidityCriteriaTabpage.select();
322         scValidityCriteriaAllowList.select(4); // "Time"
323         scValidityDecimalCompareOperator.select(6); // "between"
324         scValiditySourceInput.setText("27:00");
325         scValidityMaxValueInput.setText("21:00");
326         scValidityErrorAlertTabPage.select();
327         scValidityShowErrorMessage.check();
328         scValidityErrorMessageTitle.setText("Stop to enter");
329         scValidityErrorMessage.setText("Invalid value");
330         scValidityErrorAlertTabPage.ok();
331 
332         SCTool.selectRange("A1");
333         scInputBarInput.activate();
334         typeKeys("21:00");
335         typeKeys("<enter>");
336         assertEquals("09:00:00 PM", SCTool.getCellText("A1"));
337 
338         SCTool.selectRange("A2");
339         scInputBarInput.activate();
340         typeKeys("27:00");
341         typeKeys("<enter>");
342         assertEquals("27:00:00", SCTool.getCellText("A2"));
343 
344         SCTool.selectRange("A3");
345         scInputBarInput.activate();
346         typeKeys("1.125");
347         typeKeys("<enter>");
348         assertEquals("1.125", SCTool.getCellText("A3"));
349 
350         SCTool.selectRange("A4");
351         scInputBarInput.activate();
352         typeKeys("0.875");
353         typeKeys("<enter>");
354         assertEquals("0.875", SCTool.getCellText("A4"));
355 
356         SCTool.selectRange("B1");
357         scInputBarInput.activate();
358         typeKeys("03:00:01");
359         typeKeys("<enter>");
360         assertEquals("Invalid value", activeMsgBox.getMessage());
361         activeMsgBox.ok();
362         assertEquals("", SCTool.getCellText("B1"));
363 
364         SCTool.selectRange("B2");
365         scInputBarInput.activate();
366         typeKeys("20:59:59");
367         typeKeys("<enter>");
368         assertEquals("Invalid value", activeMsgBox.getMessage());
369         activeMsgBox.ok();
370         assertEquals("", SCTool.getCellText("B2"));
371 
372         SCTool.selectRange("B3");
373         scInputBarInput.activate();
374         typeKeys("1.126");
375         typeKeys("<enter>");
376         assertEquals("Invalid value", activeMsgBox.getMessage());
377         activeMsgBox.ok();
378         assertEquals("", SCTool.getCellText("B3"));
379 
380         SCTool.selectRange("B4");
381         scInputBarInput.activate();
382         typeKeys("0.874");
383         typeKeys("<enter>");
384         assertEquals("Invalid value", activeMsgBox.getMessage());
385         activeMsgBox.ok();
386         assertEquals("", SCTool.getCellText("B4"));
387 
388         SCTool.selectRange("C1");
389         scInputBarInput.activate();
390         typeKeys("test");
391         typeKeys("<enter>");
392         assertEquals("Invalid value", activeMsgBox.getMessage());
393         activeMsgBox.ok();
394         assertEquals("", SCTool.getCellText("C1"));
395 
396         SCTool.selectRange("C2");
397         scInputBarInput.activate();
398         typeKeys("24:00");
399         typeKeys("<enter>");
400         assertEquals("24:00:00", SCTool.getCellText("C2"));
401 
402         SCTool.selectRange("C3");
403         scInputBarInput.activate();
404         typeKeys("12:00");
405         typeKeys("<enter>");
406         assertEquals("Invalid value", activeMsgBox.getMessage());
407         activeMsgBox.ok();
408         assertEquals("", SCTool.getCellText("C3"));
409     }
410 
411     /**
412      * test Allow time Greater than and equal to in Validity.
413      */
414     @Test
415     public void testAllowTimeGreaterThan() {
416 
417         scValidityCriteriaTabpage.select();
418         scValidityCriteriaAllowList.select(4); // "Time"
419         scValidityDecimalCompareOperator.select(4); // "greater than or equal to"
420         scValiditySourceInput.setText("8:00");
421 
422         scValidityErrorAlertTabPage.select();
423         scValidityShowErrorMessage.check();
424         scValidityErrorAlertActionList.select(1); // "Warning"
425 
426         scValidityErrorMessageTitle.setText("warning to enter");
427         scValidityErrorMessage.setText("Invalid value");
428         scValidityErrorAlertTabPage.ok();
429 
430         SCTool.selectRange("A1");
431         scInputBarInput.activate();
432         typeKeys("7:30");
433         typeKeys("<enter>");
434         assertEquals("Invalid value", activeMsgBox.getMessage());
435         activeMsgBox.ok();
436         assertEquals("07:30:00 AM", SCTool.getCellText("A1"));
437 
438         SCTool.selectRange("A2");
439         scInputBarInput.activate();
440         typeKeys("6:00");
441         typeKeys("<enter>");
442         assertEquals("Invalid value", activeMsgBox.getMessage());
443         activeMsgBox.cancel();
444         assertEquals("", SCTool.getCellText("A2"));
445 
446         SCTool.selectRange("A3");
447         scInputBarInput.activate();
448         typeKeys("8:00");
449         typeKeys("<enter>");
450         assertEquals("08:00:00 AM", SCTool.getCellText("A3"));
451     }
452 
453     /**
454      * test Allow whole number, less than or equal to in Validity.
455      */
456     @Test
457     public void testAllowWholeNumLessThan() {
458 
459         scValidityCriteriaTabpage.select();
460         scValidityCriteriaAllowList.select(1); // "Whole Numbers"
461         scValidityDecimalCompareOperator.select(3); // "less than or equal"
462         scValiditySourceInput.setText("100");
463         scValidityErrorAlertTabPage.select();
464         scValidityShowErrorMessage.check();
465         scValidityErrorMessageTitle.setText("Stop to enter");
466         scValidityErrorMessage.setText("Invalid value");
467         scValidityErrorAlertTabPage.ok();
468 
469         SCTool.selectRange("A1");
470         scInputBarInput.activate();
471         typeKeys("99");
472         typeKeys("<enter>");
473         assertEquals("99", SCTool.getCellText("A1"));
474 
475         SCTool.selectRange("A2");
476         scInputBarInput.activate();
477         typeKeys("100");
478         typeKeys("<enter>");
479         assertEquals("100", SCTool.getCellText("A2"));
480 
481         SCTool.selectRange("B1");
482         scInputBarInput.activate();
483         typeKeys("101");
484         typeKeys("<enter>");
485         assertEquals("Invalid value", activeMsgBox.getMessage());
486         activeMsgBox.ok();
487         assertEquals("", SCTool.getCellText("B1"));
488 
489         SCTool.selectRange("B2");
490         scInputBarInput.activate();
491         typeKeys("45.5");
492         typeKeys("<enter>");
493         assertEquals("Invalid value", activeMsgBox.getMessage());
494         activeMsgBox.ok();
495         assertEquals("", SCTool.getCellText("B2"));
496 
497         SCTool.selectRange("C1");
498         scInputBarInput.activate();
499         typeKeys("test");
500         typeKeys("<enter>");
501         assertEquals("Invalid value", activeMsgBox.getMessage());
502         activeMsgBox.ok();
503         assertEquals("", SCTool.getCellText("C1"));
504     }
505 
506     /**
507      * test default message of Error Alert in Validity.
508      */
509     @Test
510     public void testDefaultErrorAlertMessage() {
511 
512         scValidityCriteriaTabpage.select();
513         scValidityCriteriaAllowList.select(2); // "Decimal"
514         scValidityDecimalCompareOperator.select(0); // "equal"
515         scValiditySourceInput.setText("1");
516 
517         scValidityErrorAlertTabPage.select();
518         scValidityShowErrorMessage.check();
519         scValidityErrorAlertActionList.select(0); // "Stop"
520         scValidityErrorAlertTabPage.ok();
521 
522         SCTool.selectRange("A1");
523         scInputBarInput.activate();
524         typeKeys("13");
525         typeKeys("<enter>");
526         assertEquals("OpenOffice.org Calc", activeMsgBox.getCaption());
527         // assertEquals("Invalid value.",ActiveMsgBox.getMessage()); // Can not
528         // verify in multi-language
529         activeMsgBox.ok();
530         assertEquals("", SCTool.getCellText("A1"));
531     }
532 
533     /**
534      * test uncheck Error Alert in Validity.
535      */
536     @Test
537     public void testUncheckErrorAlert() {
538 
539         scValidityCriteriaTabpage.select();
540         scValidityCriteriaAllowList.select(2); // "Decimal"
541         scValidityDecimalCompareOperator.select(0); // "equal"
542         scValiditySourceInput.setText("1");
543 
544         scValidityErrorAlertTabPage.select();
545         scValidityShowErrorMessage.uncheck();
546         scValidityErrorAlertActionList.select(0); // "Stop"
547         scValidityErrorAlertTabPage.ok();
548 
549         SCTool.selectRange("A1");
550         typeKeys("13");
551         typeKeys("<enter>");
552         assertEquals("13", SCTool.getCellText("A1"));
553     }
554 
555     /**
556      * test Cell range source picker in Validity. Input from Edit Box.
557      */
558     @Test
559     public void testValidityCellRangeSourcePicker() {
560 
561         scValidityCriteriaTabpage.select();
562         scValidityCriteriaAllowList.select(5); // "Cell range"
563         scValiditySourcePicker.click();
564         assertEquals(false, scValidityCriteriaAllowList.exists());
565         scValiditySourceInput.setText("$E$2:$G$5");
566         scValiditySourcePicker.click();
567         assertEquals(true, scValidityCriteriaAllowList.exists());
568 
569         scValidityErrorAlertTabPage.select();
570         scValidityShowErrorMessage.check();
571         scValidityErrorAlertActionList.select(0); // "Stop"
572         scValidityErrorMessageTitle.setText("Stop to enter");
573         scValidityErrorMessage.setText("Invalid value.");
574         scValidityErrorAlertTabPage.ok();
575 
576         // calc.focus();
577         SCTool.selectRange("E2");
578         scInputBarInput.activate();
579         typeKeys("test");
580         typeKeys("<enter>");
581 
582         SCTool.selectRange("A1");
583         scInputBarInput.activate();
584         typeKeys("test32");
585         typeKeys("<enter>");
586         assertEquals("Invalid value.", activeMsgBox.getMessage());
587         activeMsgBox.ok();
588         assertEquals("", SCTool.getCellText("A1"));
589 
590         SCTool.selectRange("B1");
591         scInputBarInput.activate();
592         typeKeys("test");
593         typeKeys("<enter>");
594         assertEquals("test", SCTool.getCellText("B1"));
595     }
596 
597     /**
598      * test Allow Blank cell Checkbox in Validity.
599      */
600     @Test
601     public void testAllowBlankCells() {
602         scValidityCriteriaTabpage.select();
603         scValidityCriteriaAllowList.select(5); // "Cell range"
604         scValiditySourceInput.setText("$E$1:$E$5");
605         scValidityAllowBlankCells.check();
606         scValidityCriteriaTabpage.ok();
607 
608         SCTool.selectRange("E1");
609         typeKeys("A<enter>A<enter>A<enter>A<enter>A<enter>");
610 
611         SCTool.selectRange("A1");
612         typeKeys("A<enter>");
613         SCTool.selectRange("D1");
614         scInputBarInput.activate();
615         typeKeys("<backspace><enter>");
616         assertEquals("", SCTool.getCellText("D1"));
617 
618         SCTool.selectRange("B1");
619         app.dispatch(".uno:Validation");
620         scValidityCriteriaTabpage.select();
621         scValidityAllowBlankCells.uncheck();
622         typeKeys("<enter>");
623 
624         SCTool.selectRange("B1");
625         scInputBarInput.activate();
626         typeKeys("<backspace><enter>");
627         typeKeys("<enter>");
628     }
629 }
630