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