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 setUp()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 tearDown()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 testTableSize()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") testTableBackground()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 testTableBorder()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 testTableBorderLineStyle()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 final int nMagentaIndex = 16; // for AOO's colorpicker as of #i118828# 160 swTableBorderLineColor.select( nMagentaIndex); 161 // set spacing to content 162 swTableSTCLeft.focus(); 163 typeKeys("<ctrl a>"); 164 typeKeys("<delete>"); 165 // set spacing to content 166 typeKeys("0.5"); 167 // set table shadow 168 swTableShadow.click(40, 10); 169 swTableShadowSize.focus(); 170 typeKeys("<ctrl a>"); 171 typeKeys("<delete>"); 172 typeKeys("2"); 173 swTableShadowColor.select( nMagentaIndex); 174 swTableBorder.ok(); 175 // verify the setting property of table 176 writer.focus(); 177 app.dispatch(".uno:TableDialog"); 178 swTableBorder.select(); 179 assertEquals("2.60 pt", swTableBorderLineStyle.getItemText(8)); 180 assertEquals("Magenta", swTableBorderLineColor.getItemText( nMagentaIndex)); 181 assertEquals("0.50 \"", swTableSTCLeft.getText()); 182 assertEquals("0.50 \"", swTableSTCRight.getText()); 183 assertEquals("0.50 \"", swTableSTCTop.getText()); 184 assertEquals("0.50 \"", swTableSTCBottom.getText()); 185 assertEquals("1.97 \"", swTableShadowSize.getText()); 186 assertEquals("Magenta", swTableShadowColor.getItemText( nMagentaIndex)); 187 assertTrue("SWTableSTC_SYNC", swTableSTCSYNC.isChecked()); 188 swTableBorder.close(); 189 190 // uncheck Synchronize box and set spacing to content 191 writer.focus(); 192 app.dispatch(".uno:TableDialog"); 193 swTableBorder.select(); 194 swTableSTCSYNC.uncheck(); 195 // set left spacing to content 196 swTableSTCLeft.focus(); 197 sleep(0.2); 198 typeKeys("<ctrl a>"); 199 typeKeys("<delete>"); 200 typeKeys("0.5"); 201 // set right spacing to content 202 swTableSTCRight.focus(); 203 typeKeys("<ctrl a>"); 204 typeKeys("<delete>"); 205 typeKeys("0.8"); 206 // set top spacing to content 207 swTableSTCTop.focus(); 208 typeKeys("<ctrl a>"); 209 typeKeys("<delete>"); 210 typeKeys("1.0"); 211 // set bottom spacing to content 212 swTableSTCBottom.focus(); 213 typeKeys("<ctrl a>"); 214 typeKeys("<delete>"); 215 typeKeys("2"); 216 swTableBorder.ok(); 217 assertNotNull(statusBar.getItemTextById(8)); 218 219 writer.focus(); 220 // verify the setting value of spacing to content for table 221 app.dispatch(".uno:TableDialog"); 222 swTableBorder.select(); 223 assertEquals("0.50 \"", swTableSTCLeft.getText()); 224 assertEquals("0.80 \"", swTableSTCRight.getText()); 225 assertEquals("1.00 \"", swTableSTCTop.getText()); 226 assertEquals("1.97 \"", swTableSTCBottom.getText()); 227 assertFalse("SWTableSTC_SYNC", swTableSTCSYNC.isChecked()); 228 swTableBorder.close(); 229 } 230 231 /** 232 * create table with auto format 233 * 234 * @throws Exception 235 */ 236 @Test testTableAutoFormat()237 public void testTableAutoFormat() throws Exception { 238 // create table with auto format 239 button("sw:PushButton:DLG_INSERT_TABLE:BT_AUTOFORMAT").click(); 240 assertTrue("Table auto format dialog pop up", swTableAutoFMT.exists()); 241 swTableAutoFormatListbox.select(3); 242 swTableAutoFMT.ok(); 243 // verify the auto format is that just selected 244 button("sw:PushButton:DLG_INSERT_TABLE:BT_AUTOFORMAT").click(); 245 assertEquals("Blue", swTableAutoFormatListbox.getSelText()); 246 swTableAutoFMT.close(); 247 writerInsertTable.ok(); 248 assertNotNull(statusBar.getItemTextById(8)); 249 250 } 251 252 /** 253 * set row height and select row,insert/delete row 254 * 255 * @throws Exception 256 */ 257 @Test testTableRowHeight()258 public void testTableRowHeight() throws Exception { 259 writerInsertTable.ok(); 260 assertNotNull(statusBar.getItemTextById(8)); 261 262 // set row height 263 writer.focus(); 264 writer.openContextMenu(); 265 swTableRowHeightMenu.select(); 266 assertTrue(swTableSetRowHeightDialog.exists()); 267 swTableSetRowHeight.focus(); 268 typeKeys("<ctrl a>"); 269 typeKeys("<delete>"); 270 typeKeys("0.5"); 271 swTableSetRowHeightDialog.ok(); 272 273 // verify row height 274 writer.focus(); 275 writer.openContextMenu(); 276 swTableRowHeightMenu.select(); 277 assertTrue(swTableSetRowHeightDialog.exists()); 278 assertEquals("0.50 \"", swTableSetRowHeight.getText()); 279 swTableSetRowHeightDialog.close(); 280 } 281 282 /** 283 * test select row 284 * 285 * @throws Exception 286 */ 287 @Test testTableSelectRow()288 public void testTableSelectRow() throws Exception { 289 writerInsertTable.ok(); 290 assertNotNull(statusBar.getItemTextById(8)); 291 // select row 292 writer.focus(); 293 writer.openContextMenu(); 294 swTableSelectRowMenu.select(); 295 296 // verify select one row successfully 297 typeKeys("<ctrl c>"); 298 typeKeys("<down>"); 299 typeKeys("<down>"); 300 typeKeys("<enter>"); 301 typeKeys("<ctrl v>"); 302 typeKeys("<up>"); 303 assertTrue(tableToolbar.exists()); 304 305 } 306 307 /** 308 * insert row and verify how many row inserted 309 * 310 * @throws Exception 311 */ 312 @Test testTableInsertRow()313 public void testTableInsertRow() throws Exception { 314 writerInsertTable.ok(); 315 assertNotNull(statusBar.getItemTextById(8)); 316 writer.focus(); 317 writer.openContextMenu(); 318 swTableInsertRowMenu.select(); 319 assertTrue("SWTable_InsertRow Dialog pop up", swTableInsertRow.exists()); 320 swTableInsertRowColumnSetNumber.focus(); 321 typeKeys("<ctrl a>"); 322 typeKeys("<delete>"); 323 typeKeys("3"); 324 swTableInsertRow.ok(); 325 326 writer.focus(); 327 // verify how many rows in the table 328 assertNotNull(statusBar.getItemTextById(8)); 329 for (int i = 0; i < 4; i++) { 330 typeKeys("<down>"); 331 assertNotNull(statusBar.getItemTextById(8)); 332 } 333 typeKeys("<down>"); 334 sleep(1); 335 assertFalse(tableToolbar.exists()); 336 } 337 338 /** 339 * delete row and verify row 340 * 341 * @throws Exception 342 */ 343 @Test testTableRowDelete()344 public void testTableRowDelete() throws Exception { 345 writerInsertTable.ok(); 346 assertNotNull(statusBar.getItemTextById(8)); 347 // delete row 348 writer.focus(); 349 writer.openContextMenu(); 350 swTableRowDleteMenu.select(); 351 // verify whether delete row 352 writer.focus(); 353 assertNotNull(statusBar.getItemTextById(8)); 354 typeKeys("<down>"); 355 sleep(1); 356 assertFalse(tableToolbar.exists()); 357 358 } 359 360 /** 361 * set column width and verify 362 * 363 * @throws Exception 364 */ 365 @Test testTableColumnWidth()366 public void testTableColumnWidth() throws Exception { 367 writerInsertTable.ok(); 368 assertNotNull(statusBar.getItemTextById(8)); 369 // set column width 370 writer.focus(); 371 writer.openContextMenu(); 372 swTableColumnWidthMenu.select(); 373 swTableSetColumnWidth.focus(); 374 typeKeys("<ctrl a>"); 375 typeKeys("<delete>"); 376 typeKeys("2"); 377 swTableSetColumnDialog.ok(); 378 // verify column width 379 writer.focus(); 380 writer.openContextMenu(); 381 swTableColumnWidthMenu.select(); 382 assertEquals("2.00 \"", swTableSetColumnWidth.getText()); 383 384 } 385 386 /** 387 * select column and verify 388 * 389 * @throws Exception 390 */ 391 @Test testTableColumnSelect()392 public void testTableColumnSelect() throws Exception { 393 writerInsertTable.ok(); 394 assertNotNull(statusBar.getItemTextById(8)); 395 writer.focus(); 396 writer.openContextMenu(); 397 swTableColumnSelectMenu.select(); 398 399 // verify select one column 400 typeKeys("<ctrl c>"); 401 typeKeys("<down>"); 402 typeKeys("<down>"); 403 typeKeys("<enter>"); 404 typeKeys("<ctrl v>"); 405 typeKeys("<up>"); 406 assertTrue(tableToolbar.exists()); 407 408 } 409 410 /** 411 * insert column and verify 412 * 413 * @throws Exception 414 */ 415 @Test testTableColumnInsert()416 public void testTableColumnInsert() throws Exception { 417 writerInsertTable.ok(); 418 assertNotNull(statusBar.getItemTextById(8)); 419 // insert column 420 writer.focus(); 421 writer.openContextMenu(); 422 swTableColumnInsertMenu.select(); 423 swTableInsertRowColumnSetNumber.focus(); 424 typeKeys("<ctrl a>"); 425 typeKeys("<delete>"); 426 typeKeys("3"); 427 swTableInsertColumn.ok(); 428 // verify insert column successfully 429 writer.focus(); 430 assertTrue(tableToolbar.exists()); 431 for (int i = 0; i < 9; i++) { 432 typeKeys("<right>"); 433 sleep(1); 434 assertTrue(tableToolbar.exists()); 435 } 436 typeKeys("<right>"); 437 sleep(1); 438 assertFalse(tableToolbar.exists()); 439 } 440 441 /** 442 * delete column and verify whether delete or not 443 * 444 * @throws Exception 445 */ testTableColumnDelete()446 public void testTableColumnDelete() throws Exception { 447 writerInsertTable.ok(); 448 assertNotNull(statusBar.getItemTextById(8)); 449 // delete column 450 writer.focus(); 451 writer.openContextMenu(); 452 swTableColumnDeleteMenu.select(); 453 // verify delete column 454 writer.focus(); 455 assertTrue(tableToolbar.exists()); 456 for (int i = 0; i < 7; i++) { 457 typeKeys("<right>"); 458 assertTrue(tableToolbar.exists()); 459 } 460 sleep(1); 461 assertFalse(tableToolbar.exists()); 462 } 463 464 /** 465 * split cell 466 * 467 * @throws Exception 468 */ 469 @Test testTableCellSplit()470 public void testTableCellSplit() throws Exception { 471 writerInsertTable.ok(); 472 assertTrue(tableToolbar.exists()); 473 for (int k = 0; k < 2; k++) { 474 writer.focus(); 475 writer.openContextMenu(); 476 swTableCellSplitMenu.select(); 477 swTableCellSplitNumber.focus(); 478 typeKeys("<ctrl a>"); 479 typeKeys("<delete>"); 480 typeKeys("2"); 481 if (k == 0) { 482 // split table cell horizontally 483 swTableCellSplitDialog.ok(); 484 } else { 485 // split table cell 486 swTableCellSplitVERTButton.check(); 487 // vertically 488 swTableCellSplitDialog.ok(); 489 } 490 } 491 // verify cell split successfully 492 writer.focus(); 493 assertTrue(tableToolbar.exists()); 494 for (int i = 0; i < 7; i++) { 495 typeKeys("<right>"); 496 assertTrue(tableToolbar.exists()); 497 } 498 sleep(1); 499 assertFalse(tableToolbar.exists()); 500 } 501 502 /** 503 * Test convert table to text in text document 504 * 505 * @throws Exception 506 */ 507 @Test testConvertTableToText()508 public void testConvertTableToText() throws Exception { 509 writerInsertTable.ok(); 510 writer.focus(); 511 typeKeys("1<right>2<right>3<right>4"); 512 sleep(1); 513 514 // Convert table to text 515 app.dispatch(".uno:ConvertTableToText"); 516 assertTrue("Convert Table to Text dialog pop up", 517 writerConvertTableToTextDlg.exists()); 518 // typeKeys("<enter>"); 519 writerConvertTableToTextDlg.ok(); 520 521 // Verify if text is converted successfully 522 app.dispatch(".uno:SelectAll"); 523 app.dispatch(".uno:Copy"); 524 if (SystemUtil.isWindows()) 525 assertEquals("Converted text", "1\t2\r\n3\t4\r\n", 526 app.getClipboard()); 527 else 528 assertEquals("Converted text", "1\t2\n3\t4\n", app.getClipboard()); 529 } 530 } 531