xref: /AOO41X/test/testgui/source/bvt/gui/FileTypeTest.java (revision 44cf02803b51681da4056cdf9500cc33ee29bd2f)
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 /**
23  *
24  */
25 package bvt.gui;
26 
27 import static org.junit.Assert.*;
28 import static org.openoffice.test.common.Testspace.*;
29 import static org.openoffice.test.vcl.Tester.*;
30 import static testlib.gui.AppTool.*;
31 import static testlib.gui.UIMap.*;
32 
33 import java.awt.Rectangle;
34 
35 import org.junit.AfterClass;
36 import org.junit.Assert;
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Rule;
40 import org.junit.Test;
41 import org.openoffice.test.common.GraphicsUtil;
42 import org.openoffice.test.common.Logger;
43 
44 import testlib.gui.SCTool;
45 
46 /**
47  *
48  */
49 public class FileTypeTest {
50 
51     @Rule
52     public Logger log = Logger.getLogger(this);
53 
54     @BeforeClass
beforeClass()55     public static void beforeClass() {
56         app.clean();
57     }
58 
59     @AfterClass
afterClass()60     public static void afterClass() {
61         app.stop();
62     }
63 
64     @Before
before()65     public void before() {
66         app.stop();
67         app.start();
68     }
69 
70 
71     /**
72      * Test New/Save a text document
73      *
74      * @throws Exception
75      */
76     @Test
testSaveNewODT()77     public void testSaveNewODT() throws Exception {
78         saveNewDocument("helloworld_saveas.odt");
79     }
80 
81     @Test
testSaveNewOTT()82     public void testSaveNewOTT() throws Exception {
83         saveNewDocument("helloworld_saveas.ott");
84     }
85 
86     @Test
testSaveNewSXW()87     public void testSaveNewSXW() throws Exception {
88         saveNewDocument("helloworld_saveas.sxw");
89     }
90 
91     @Test
testSaveNewSTW()92     public void testSaveNewSTW() throws Exception {
93         saveNewDocument("helloworld_saveas.stw");
94     }
95 
96     @Test
testSaveNewDOC()97     public void testSaveNewDOC() throws Exception {
98         saveNewDocument("helloworld_saveas.doc");
99     }
100 
101     @Test
testSaveNewTXT()102     public void testSaveNewTXT() throws Exception {
103         saveNewDocument("helloworld_saveas.txt");
104     }
105 
saveNewDocument(String file)106     private void saveNewDocument(String file) {
107         String saveTo = "temp/" + file;
108         String text = "@AOO";
109         newTextDocument();
110         writer.typeKeys(text);
111         // Verify the text via system clip board
112         Assert.assertEquals("The typed text into writer", text, copyAll());
113 
114         // menuItem("Text Properties...").select();
115         app.dispatch(".uno:FontDialog");
116         effectsPage.select();
117         effectsPageColor.select(6);
118         effectsPage.ok();
119         sleep(1);
120 
121         // Save the text document
122         deleteFile(saveTo);
123         saveAs(saveTo);
124         close();
125         open(saveTo);
126         // Reopen the saved file
127         writer.waitForExistence(10, 2);
128         sleep(1);
129         // Verify if the text still exists in the file
130         Assert.assertEquals("The typed text into writer is saved!", text, copyAll());
131     }
132 
133     @Test
testSaveNewODS()134     public void testSaveNewODS() throws Exception {
135         saveNewSpreadsheet("helloworld_saveas.ods");
136     }
137 
138     @Test
testSaveNewOTS()139     public void testSaveNewOTS() throws Exception {
140         saveNewSpreadsheet("helloworld_saveas.ots");
141     }
142 
143     @Test
testSaveNewSXC()144     public void testSaveNewSXC() throws Exception {
145         saveNewSpreadsheet("helloworld_saveas.sxc");
146     }
147 
148     @Test
testSaveNewSTC()149     public void testSaveNewSTC() throws Exception {
150         saveNewSpreadsheet("helloworld_saveas.stc");
151     }
152 
153     // @Test
154     // public void testSaveNewCSV() throws Exception {
155     // saveNewSpreadsheet("helloworld_saveas.csv");
156     // }
157 
158     @Test
testSaveNewXLS()159     public void testSaveNewXLS() throws Exception {
160         saveNewSpreadsheet("helloworld_saveas.xls");
161     }
162 
saveNewSpreadsheet(String file)163     private void saveNewSpreadsheet(String file) {
164         String saveTo = "temp/" + file;
165         String text = "@AOO";
166         newSpreadsheet();
167         SCTool.selectRange("A65536");
168         calc.typeKeys(text);
169         deleteFile(saveTo);
170         saveAs(saveTo);
171         close();
172         open(saveTo);
173         calc.waitForExistence(10, 2);
174         sleep(1);
175         Assert.assertEquals("The typed text is saved!", text, SCTool.getCellText("A65536"));
176     }
177 
178     @Test
testSaveNewODP()179     public void testSaveNewODP() throws Exception {
180         saveNewPresentation("helloworld_saveas.odp");
181     }
182 
183     @Test
testSaveNewOTP()184     public void testSaveNewOTP() throws Exception {
185         saveNewPresentation("helloworld_saveas.otp");
186     }
187 
188     @Test
testSaveNewPPT()189     public void testSaveNewPPT() throws Exception {
190         saveNewPresentation("helloworld_saveas.ppt");
191     }
192 
193     @Test
testSaveNewPOT()194     public void testSaveNewPOT() throws Exception {
195         saveNewPresentation("helloworld_saveas.pot");
196     }
197 
198     @Test
testSaveNewSXI()199     public void testSaveNewSXI() throws Exception {
200         saveNewPresentation("helloworld_saveas.sxi");
201     }
202 
203     @Test
testSaveNewSTI()204     public void testSaveNewSTI() throws Exception {
205         saveNewPresentation("helloworld_saveas.sti");
206     }
207 
saveNewPresentation(String file)208     private void saveNewPresentation(String file) {
209         String saveTo = "temp/" + file;
210         String text = "@AOO";
211         newPresentation();
212         impress.typeKeys(text);
213         impress.doubleClick(0.1, 0.5);
214         deleteFile(saveTo);
215         saveAs(saveTo);
216         close();
217         open(saveTo);
218         impress.waitForExistence(10, 2);
219         sleep(1);
220         impress.typeKeys("<tab><enter>");
221         sleep(1);
222         Assert.assertEquals("The typed text is saved!", text, copyAll().trim());
223     }
224 
225     // drawing
226 
227     /**
228      * Test save a new drawing as .odg
229      */
230     @Test
testSaveNewODG()231     public void testSaveNewODG() throws Exception {
232         saveNewDrawing("draw_saveas.odg");
233     }
234 
235     /**
236      * Test save a new drawing as .otg
237      */
238     @Test
testSaveNewOTG()239     public void testSaveNewOTG() throws Exception {
240         saveNewDrawing("draw_saveas.otg");
241     }
242 
243     /**
244      * Test save a new drawing as .sxd
245      */
246     @Test
testSaveNewSXD()247     public void testSaveNewSXD() throws Exception {
248         saveNewDrawing("draw_saveas.sxd");
249     }
250 
251     /**
252      * Test save a new drawing as .std
253      */
254     @Test
testSaveNewSTD()255     public void testSaveNewSTD() throws Exception {
256         saveNewDrawing("draw_saveas.std");
257     }
258 
259     /**
260      * New/Save a draw document 1. New a draw document 2. Insert a picture 3.
261      * Save it as the input filename 4. Reopen the saved file 5. Check if the
262      * picture is still there
263      *
264      * @param filename
265      *            : filename to be saved
266      * @throws Exception
267      */
saveNewDrawing(String filename)268     public void saveNewDrawing(String filename) {
269         String saveTo = "temp/" + filename;
270         String bmp_green = prepareData("image/green_256x256.bmp");
271         // Create a new drawing document
272         newDrawing();
273         // Insert a picture fully filled with green
274         app.dispatch(".uno:InsertGraphic");
275         submitOpenDlg(bmp_green);
276         // Focus on edit pane
277         draw.click(5, 5);
278         sleep(1);
279         // Verify if the picture is inserted successfully
280         Rectangle rectangle = GraphicsUtil.findRectangle(draw.getScreenRectangle(), 0xFF00FF00);
281         assertNotNull("Green rectangle: " + rectangle, rectangle);
282         deleteFile(saveTo);
283         saveAs(saveTo);
284         close();
285         open(saveTo);
286         draw.waitForExistence(10, 2);
287         sleep(1);
288         // Verify if the picture still exists in the file
289         Rectangle rectangle1 = GraphicsUtil.findRectangle(draw.getScreenRectangle(), 0xFF00FF00);
290         assertNotNull("Green rectangle: " + rectangle1, rectangle1);
291     }
292 
293     // math
294     /**
295      * Test save a new math as .odf
296      */
297     @Test
testSaveNewODF()298     public void testSaveNewODF() throws Exception {
299         saveNewMath("math_saveas.odf");
300     }
301 
302     /**
303      * Test save a new math as .sxm
304      */
305     @Test
testSaveNewSXM()306     public void testSaveNewSXM() throws Exception {
307         saveNewMath("math_saveas.sxm");
308     }
309 
310     /**
311      * Test save a new math as .mml
312      */
313     @Test
testSaveNewMML()314     public void testSaveNewMML() throws Exception {
315         saveNewMath("math_saveas.mml");
316     }
317 
318     /**
319      * New/Save a math 1. New a math 2. Insert a formula 3. Save it as the input
320      * filename 4. Reopen the saved file 5. Check if the formula is still there
321      *
322      * @param filename
323      *            : filename to be saved
324      * @throws Exception
325      */
saveNewMath(String filename)326     public void saveNewMath(String filename) {
327         String saveTo = "temp/" + filename;
328         String text = "5 times 3 = 15";
329         // Create a new math
330         newFormula();
331         // Insert a formula
332         mathEditWindow.typeKeys(text);
333         // Verify the text via system clip board
334         assertEquals("The typed formula into math", text, copyAll());
335 
336         // Save the formula
337         deleteFile(saveTo);
338         saveAs(saveTo);
339         close();
340         open(saveTo);
341         mathEditWindow.waitForExistence(10, 2);
342         sleep(1);
343         mathEditWindow.focus();
344         assertEquals("The typed formula into math is saved", text, copyAll());
345     }
346 }
347