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.sw.table; 23 24 import static org.junit.Assert.*; 25 import static org.openoffice.test.vcl.Tester.*; 26 import static testlib.gui.AppTool.*; 27 import static testlib.gui.UIMap.*; 28 29 import org.junit.After; 30 import org.junit.Before; 31 import org.junit.Ignore; 32 import org.junit.Rule; 33 import org.junit.Test; 34 import org.openoffice.test.common.Logger; 35 import org.openoffice.test.common.SystemUtil; 36 37 import testlib.gui.AppTool; 38 39 public class TableGeneral { 40 41 @Rule 42 public Logger log = Logger.getLogger(this); 43 44 @Before 45 public void setUp() throws Exception { 46 // Start OpenOffice 47 app.start(); 48 49 AppTool.newTextDocument(); 50 // Insert a table 51 app.dispatch(".uno:InsertTable"); 52 } 53 54 @After 55 public void tearDown() throws Exception { 56 app.stop(); 57 } 58 59 /** 60 * Test setting table size in text document 61 * 62 * @throws Exception 63 */ 64 @Test 65 public void testTableSize() throws Exception { 66 67 swTableSizeColBox.focus(); 68 typeKeys("<delete>"); 69 typeKeys("3"); 70 swTableSizeRowBox.focus(); 71 typeKeys("<delete>"); 72 typeKeys("4"); 73 writerInsertTable.ok(); 74 75 writer.focus(); 76 // verify the rows in the table 77 assertNotNull(statusBar.getItemTextById(8)); 78 for (int i = 0; i < 3; i++) { 79 typeKeys("<down>"); 80 assertNotNull(statusBar.getItemTextById(8)); 81 } 82 typeKeys("<down>"); 83 sleep(1); 84 assertFalse(tableToolbar.exists()); 85 } 86 87 /** 88 * Test setting table cell background in text document 89 * 90 * @throws Exception 91 */ 92 @Test 93 @Ignore("Bug #120378- the table cell fill color change when copy one table cell in word processor to presentation") 94 public void testTableBackground() throws Exception { 95 writerInsertTable.ok(); 96 assertNotNull(statusBar.getItemTextById(8)); 97 writer.focus(); 98 // set table cell background 99 app.dispatch(".uno:TableDialog"); 100 swTableBackground.select(); 101 assertTrue("Table background property dialog pop up", 102 swTableBackground.exists()); 103 swTableBackgroundColor.focus(); 104 swTableBackgroundColor.click(50, 50); 105 swTableBackground.ok(); 106 // verify table cell background color 107 writer.focus(); 108 // select the cell which is filled with color 109 app.dispatch(".uno:EntireCell"); 110 111 typeKeys("<ctrl c>"); 112 AppTool.newPresentation(); 113 typeKeys("<ctrl v>"); 114 // enable table cell area format dialog 115 app.dispatch(".uno:FormatArea"); 116 sleep(1); 117 assertEquals("Light red", sdTableBACGColorListbox.getSelText()); 118 // close table cell area format dialog 119 sdTableBACGColorArea.cancel(); 120 } 121 122 /** 123 * Test setting table border in text document 124 * 125 * @throws Exception 126 */ 127 @Test 128 public void testTableBorder() throws Exception { 129 writerInsertTable.ok(); 130 assertNotNull(statusBar.getItemTextById(8)); 131 // set table border as none 132 writer.focus(); 133 app.dispatch(".uno:TableDialog"); 134 swTableBorder.select(); 135 assertTrue("Table border property dialog pop up", 136 swTableBorder.exists()); 137 swTableBorderLineArrange.click(10, 10); 138 swTableBorder.ok(); 139 } 140 141 /** 142 * Test setting table border line style,line color,spacing to content in 143 * text document 144 * 145 * @throws Exception 146 */ 147 @Test 148 public void testTableBorderLineStyle() throws Exception { 149 writerInsertTable.ok(); 150 assertNotNull(statusBar.getItemTextById(8)); 151 writer.focus(); 152 app.dispatch(".uno:TableDialog"); 153 swTableBorder.select(); 154 assertTrue("Table border property dialog pop up", 155 swTableBorder.exists()); 156 // set line style 157 swTableBorderLineStyle.select(8); 158 // set line color 159 swTableBorderLineColor.select(5); 160 // set spacing to content 161 swTableSTCLeft.focus(); 162 typeKeys("<ctrl a>"); 163 typeKeys("<delete>"); 164 // set spacing to content 165 typeKeys("0.5"); 166 // set table shadow 167 swTableShadow.click(40, 10); 168 swTableShadowSize.focus(); 169 typeKeys("<ctrl a>"); 170 typeKeys("<delete>"); 171 typeKeys("2"); 172 swTableShadowColor.select(5); 173 swTableBorder.ok(); 174 // verify the setting property of table 175 writer.focus(); 176 app.dispatch(".uno:TableDialog"); 177 swTableBorder.select(); 178 assertEquals("2.60 pt", swTableBorderLineStyle.getItemText(8)); 179 assertEquals("Magenta", swTableBorderLineColor.getItemText(5)); 180 assertEquals("0.50\"", swTableSTCLeft.getText()); 181 assertEquals("0.50\"", swTableSTCRight.getText()); 182 assertEquals("0.50\"", swTableSTCTop.getText()); 183 assertEquals("0.50\"", swTableSTCBottom.getText()); 184 assertEquals("1.97\"", swTableShadowSize.getText()); 185 assertEquals("Magenta", swTableShadowColor.getItemText(5)); 186 assertTrue("SWTableSTC_SYNC", swTableSTCSYNC.isChecked()); 187 swTableBorder.close(); 188 189 // uncheck Synchronize box and set spacing to content 190 writer.focus(); 191 app.dispatch(".uno:TableDialog"); 192 swTableBorder.select(); 193 swTableSTCSYNC.uncheck(); 194 // set left spacing to content 195 swTableSTCLeft.focus(); 196 typeKeys("<ctrl a>"); 197 typeKeys("<delete>"); 198 typeKeys("0.5"); 199 // set right spacing to content 200 swTableSTCRight.focus(); 201 typeKeys("<ctrl a>"); 202 typeKeys("<delete>"); 203 typeKeys("0.8"); 204 // set top spacing to content 205 swTableSTCTop.focus(); 206 typeKeys("<ctrl a>"); 207 typeKeys("<delete>"); 208 typeKeys("1.0"); 209 // set bottom spacing to content 210 swTableSTCBottom.focus(); 211 typeKeys("<ctrl a>"); 212 typeKeys("<delete>"); 213 typeKeys("2"); 214 swTableBorder.ok(); 215 assertNotNull(statusBar.getItemTextById(8)); 216 217 writer.focus(); 218 // verify the setting value of spacing to content for table 219 app.dispatch(".uno:TableDialog"); 220 swTableBorder.select(); 221 assertEquals("0.50\"", swTableSTCLeft.getText()); 222 assertEquals("0.80\"", swTableSTCRight.getText()); 223 assertEquals("1.00\"", swTableSTCTop.getText()); 224 assertEquals("1.97\"", swTableSTCBottom.getText()); 225 assertFalse("SWTableSTC_SYNC", swTableSTCSYNC.isChecked()); 226 swTableBorder.close(); 227 } 228 229 /** 230 * create table with auto format 231 * 232 * @throws Exception 233 */ 234 @Test 235 public void testTableAutoFormat() throws Exception { 236 // create table with auto format 237 button("sw:PushButton:DLG_INSERT_TABLE:BT_AUTOFORMAT").click(); 238 assertTrue("Table auto format dialog pop up", swTableAutoFMT.exists()); 239 swTableAutoFormatListbox.select(3); 240 swTableAutoFMT.ok(); 241 // verify the auto format is that just selected 242 button("sw:PushButton:DLG_INSERT_TABLE:BT_AUTOFORMAT").click(); 243 assertEquals("Blue", swTableAutoFormatListbox.getSelText()); 244 swTableAutoFMT.close(); 245 writerInsertTable.ok(); 246 assertNotNull(statusBar.getItemTextById(8)); 247 248 } 249 250 /** 251 * set row height and select row,insert/delete row 252 * 253 * @throws Exception 254 */ 255 @Test 256 public void testTableRowHeight() throws Exception { 257 writerInsertTable.ok(); 258 assertNotNull(statusBar.getItemTextById(8)); 259 260 // set row height 261 writer.focus(); 262 writer.openContextMenu(); 263 swTableRowHeightMenu.select(); 264 assertTrue(swTableSetRowHeightDialog.exists()); 265 swTableSetRowHeight.focus(); 266 typeKeys("<ctrl a>"); 267 typeKeys("<delete>"); 268 typeKeys("0.5"); 269 swTableSetRowHeightDialog.ok(); 270 271 // verify row height 272 writer.focus(); 273 writer.openContextMenu(); 274 swTableRowHeightMenu.select(); 275 assertTrue(swTableSetRowHeightDialog.exists()); 276 assertEquals("0.50\"", swTableSetRowHeight.getText()); 277 swTableSetRowHeightDialog.close(); 278 } 279 280 /** 281 * test select row 282 * 283 * @throws Exception 284 */ 285 @Test 286 public void testTableSelectRow() throws Exception { 287 writerInsertTable.ok(); 288 assertNotNull(statusBar.getItemTextById(8)); 289 // select row 290 writer.focus(); 291 writer.openContextMenu(); 292 swTableSelectRowMenu.select(); 293 294 // verify select one row successfully 295 typeKeys("<ctrl c>"); 296 typeKeys("<down>"); 297 typeKeys("<down>"); 298 typeKeys("<enter>"); 299 typeKeys("<ctrl v>"); 300 typeKeys("<up>"); 301 assertTrue(tableToolbar.exists()); 302 303 } 304 305 /** 306 * insert row and verify how many row inserted 307 * 308 * @throws Exception 309 */ 310 @Test 311 public void testTableInsertRow() throws Exception { 312 writerInsertTable.ok(); 313 assertNotNull(statusBar.getItemTextById(8)); 314 writer.focus(); 315 writer.openContextMenu(); 316 swTableInsertRowMenu.select(); 317 assertTrue("SWTable_InsertRow Dialog pop up", swTableInsertRow.exists()); 318 swTableInsertRowColumnSetNumber.focus(); 319 typeKeys("<ctrl a>"); 320 typeKeys("<delete>"); 321 typeKeys("3"); 322 swTableInsertRow.ok(); 323 324 writer.focus(); 325 // verify how many rows in the table 326 assertNotNull(statusBar.getItemTextById(8)); 327 for (int i = 0; i < 4; i++) { 328 typeKeys("<down>"); 329 assertNotNull(statusBar.getItemTextById(8)); 330 } 331 typeKeys("<down>"); 332 sleep(1); 333 assertFalse(tableToolbar.exists()); 334 } 335 336 /** 337 * delete row and verify row 338 * 339 * @throws Exception 340 */ 341 @Test 342 public void testTableRowDelete() throws Exception { 343 writerInsertTable.ok(); 344 assertNotNull(statusBar.getItemTextById(8)); 345 // delete row 346 writer.focus(); 347 writer.openContextMenu(); 348 swTableRowDleteMenu.select(); 349 // verify whether delete row 350 writer.focus(); 351 assertNotNull(statusBar.getItemTextById(8)); 352 typeKeys("<down>"); 353 sleep(1); 354 assertFalse(tableToolbar.exists()); 355 356 } 357 358 /** 359 * set column width and verify 360 * 361 * @throws Exception 362 */ 363 @Test 364 public void testTableColumnWidth() throws Exception { 365 writerInsertTable.ok(); 366 assertNotNull(statusBar.getItemTextById(8)); 367 // set column width 368 writer.focus(); 369 writer.openContextMenu(); 370 swTableColumnWidthMenu.select(); 371 swTableSetColumnWidth.focus(); 372 typeKeys("<ctrl a>"); 373 typeKeys("<delete>"); 374 typeKeys("2"); 375 swTableSetColumnDialog.ok(); 376 // verify column width 377 writer.focus(); 378 writer.openContextMenu(); 379 swTableColumnWidthMenu.select(); 380 assertEquals("2.00\"", swTableSetColumnWidth.getText()); 381 382 } 383 384 /** 385 * select column and verify 386 * 387 * @throws Exception 388 */ 389 @Test 390 public void testTableColumnSelect() throws Exception { 391 writerInsertTable.ok(); 392 assertNotNull(statusBar.getItemTextById(8)); 393 writer.focus(); 394 writer.openContextMenu(); 395 swTableColumnSelectMenu.select(); 396 397 // verify select one column 398 typeKeys("<ctrl c>"); 399 typeKeys("<down>"); 400 typeKeys("<down>"); 401 typeKeys("<enter>"); 402 typeKeys("<ctrl v>"); 403 typeKeys("<up>"); 404 assertTrue(tableToolbar.exists()); 405 406 } 407 408 /** 409 * insert column and verify 410 * 411 * @throws Exception 412 */ 413 @Test 414 public void testTableColumnInsert() throws Exception { 415 writerInsertTable.ok(); 416 assertNotNull(statusBar.getItemTextById(8)); 417 // insert column 418 writer.focus(); 419 writer.openContextMenu(); 420 swTableColumnInsertMenu.select(); 421 swTableInsertRowColumnSetNumber.focus(); 422 typeKeys("<ctrl a>"); 423 typeKeys("<delete>"); 424 typeKeys("3"); 425 swTableInsertColumn.ok(); 426 // verify insert column successfully 427 writer.focus(); 428 assertTrue(tableToolbar.exists()); 429 for (int i = 0; i < 9; i++) { 430 typeKeys("<right>"); 431 sleep(1); 432 assertTrue(tableToolbar.exists()); 433 } 434 typeKeys("<right>"); 435 sleep(1); 436 assertFalse(tableToolbar.exists()); 437 } 438 439 /** 440 * delete column and verify whether delete or not 441 * 442 * @throws Exception 443 */ 444 public void testTableColumnDelete() throws Exception { 445 writerInsertTable.ok(); 446 assertNotNull(statusBar.getItemTextById(8)); 447 // delete column 448 writer.focus(); 449 writer.openContextMenu(); 450 swTableColumnDeleteMenu.select(); 451 // verify delete column 452 writer.focus(); 453 assertTrue(tableToolbar.exists()); 454 for (int i = 0; i < 7; i++) { 455 typeKeys("<right>"); 456 assertTrue(tableToolbar.exists()); 457 } 458 sleep(1); 459 assertFalse(tableToolbar.exists()); 460 } 461 462 /** 463 * split cell 464 * 465 * @throws Exception 466 */ 467 @Test 468 public void testTableCellSplit() throws Exception { 469 writerInsertTable.ok(); 470 assertTrue(tableToolbar.exists()); 471 for (int k = 0; k < 2; k++) { 472 writer.focus(); 473 writer.openContextMenu(); 474 swTableCellSplitMenu.select(); 475 swTableCellSplitNumber.focus(); 476 typeKeys("<ctrl a>"); 477 typeKeys("<delete>"); 478 typeKeys("2"); 479 if (k == 0) { 480 // split table cell horizontally 481 swTableCellSplitDialog.ok(); 482 } else { 483 // split table cell 484 swTableCellSplitVERTButton.check(); 485 // vertically 486 swTableCellSplitDialog.ok(); 487 } 488 } 489 // verify cell split successfully 490 writer.focus(); 491 assertTrue(tableToolbar.exists()); 492 for (int i = 0; i < 7; i++) { 493 typeKeys("<right>"); 494 assertTrue(tableToolbar.exists()); 495 } 496 sleep(1); 497 assertFalse(tableToolbar.exists()); 498 } 499 500 /** 501 * Test convert table to text in text document 502 * 503 * @throws Exception 504 */ 505 @Test 506 public void testConvertTableToText() throws Exception { 507 writerInsertTable.ok(); 508 writer.focus(); 509 typeKeys("1<right>2<right>3<right>4"); 510 sleep(1); 511 512 // Convert table to text 513 app.dispatch(".uno:ConvertTableToText"); 514 assertTrue("Convert Table to Text dialog pop up", 515 writerConvertTableToTextDlg.exists()); 516 // typeKeys("<enter>"); 517 writerConvertTableToTextDlg.ok(); 518 519 // Verify if text is converted successfully 520 app.dispatch(".uno:SelectAll"); 521 app.dispatch(".uno:Copy"); 522 if (SystemUtil.isWindows()) 523 assertEquals("Converted text", "1\t2\r\n3\t4\r\n", 524 app.getClipboard()); 525 else 526 assertEquals("Converted text", "1\t2\n3\t4\n", app.getClipboard()); 527 } 528 } 529