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