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