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