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