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