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