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 		sleep(1);
112 		// Verify the text via system clip board
113 		String result = copyAll();
114 		sleep(1);
115 		Assert.assertEquals("The typed text into writer", text, result);
116 		result = null;
117 
118 		// menuItem("Text Properties...").select();
119 		app.dispatch(".uno:FontDialog");
120 		effectsPage.select();
121 		effectsPageColor.select(6);
122 		effectsPage.ok();
123 		sleep(1);
124 
125 		// Save the text document
126 		deleteFile(saveTo);
127 		saveAs(saveTo);
128 		close();
129 		open(saveTo);
130 		// Reopen the saved file
131 		writer.waitForExistence(10, 2);
132 		sleep(1);
133 		// Verify if the text still exists in the file
134 		result = copyAll();
135 		sleep(1);
136 		Assert.assertEquals("The typed text into writer is saved!", text, result);
137 	}
138 
139 	@Test
testSaveNewODS()140 	public void testSaveNewODS() throws Exception {
141 		saveNewSpreadsheet("helloworld_saveas.ods");
142 	}
143 
144 	@Test
testSaveNewOTS()145 	public void testSaveNewOTS() throws Exception {
146 		saveNewSpreadsheet("helloworld_saveas.ots");
147 	}
148 
149 	@Test
testSaveNewSXC()150 	public void testSaveNewSXC() throws Exception {
151 		saveNewSpreadsheet("helloworld_saveas.sxc");
152 	}
153 
154 	@Test
testSaveNewSTC()155 	public void testSaveNewSTC() throws Exception {
156 		saveNewSpreadsheet("helloworld_saveas.stc");
157 	}
158 
159 	// @Test
160 	// public void testSaveNewCSV() throws Exception {
161 	// saveNewSpreadsheet("helloworld_saveas.csv");
162 	// }
163 
164 	@Test
testSaveNewXLS()165 	public void testSaveNewXLS() throws Exception {
166 		saveNewSpreadsheet("helloworld_saveas.xls");
167 	}
168 
saveNewSpreadsheet(String file)169 	private void saveNewSpreadsheet(String file) {
170 		String saveTo = "temp/" + file;
171 		String text = "@AOO";
172 		newSpreadsheet();
173 		SCTool.selectRange("A65536");
174 		calc.typeKeys(text);
175 		deleteFile(saveTo);
176 		saveAs(saveTo);
177 		close();
178 		open(saveTo);
179 		calc.waitForExistence(10, 2);
180 		sleep(1);
181 		Assert.assertEquals("The typed text is saved!", text, SCTool.getCellText("A65536"));
182 	}
183 
184 	@Test
testSaveNewODP()185 	public void testSaveNewODP() throws Exception {
186 		saveNewPresentation("helloworld_saveas.odp");
187 	}
188 
189 	@Test
testSaveNewOTP()190 	public void testSaveNewOTP() throws Exception {
191 		saveNewPresentation("helloworld_saveas.otp");
192 	}
193 
194 	@Test
testSaveNewPPT()195 	public void testSaveNewPPT() throws Exception {
196 		saveNewPresentation("helloworld_saveas.ppt");
197 	}
198 
199 	@Test
testSaveNewPOT()200 	public void testSaveNewPOT() throws Exception {
201 		saveNewPresentation("helloworld_saveas.pot");
202 	}
203 
204 	@Test
testSaveNewSXI()205 	public void testSaveNewSXI() throws Exception {
206 		saveNewPresentation("helloworld_saveas.sxi");
207 	}
208 
209 	@Test
testSaveNewSTI()210 	public void testSaveNewSTI() throws Exception {
211 		saveNewPresentation("helloworld_saveas.sti");
212 	}
213 
saveNewPresentation(String file)214 	private void saveNewPresentation(String file) {
215 		String saveTo = "temp/" + file;
216 		String text = "@AOO";
217 		newPresentation();
218 		impress.typeKeys(text);
219 		impress.doubleClick(0.1, 0.5);
220 		deleteFile(saveTo);
221 		saveAs(saveTo);
222 		close();
223 		open(saveTo);
224 		impress.waitForExistence(10, 2);
225 		sleep(1);
226 		impress.typeKeys("<tab><enter>");
227 		sleep(1);
228 		String result = copyAll();
229 		sleep(1);
230 		Assert.assertEquals("The typed text is saved!", text, result.trim());
231 	}
232 
233 	// drawing
234 
235 	/**
236 	 * Test save a new drawing as .odg
237 	 */
238 	@Test
testSaveNewODG()239 	public void testSaveNewODG() throws Exception {
240 		saveNewDrawing("draw_saveas.odg");
241 	}
242 
243 	/**
244 	 * Test save a new drawing as .otg
245 	 */
246 	@Test
testSaveNewOTG()247 	public void testSaveNewOTG() throws Exception {
248 		saveNewDrawing("draw_saveas.otg");
249 	}
250 
251 	/**
252 	 * Test save a new drawing as .sxd
253 	 */
254 	@Test
testSaveNewSXD()255 	public void testSaveNewSXD() throws Exception {
256 		saveNewDrawing("draw_saveas.sxd");
257 	}
258 
259 	/**
260 	 * Test save a new drawing as .std
261 	 */
262 	@Test
testSaveNewSTD()263 	public void testSaveNewSTD() throws Exception {
264 		saveNewDrawing("draw_saveas.std");
265 	}
266 
267 	/**
268 	 * New/Save a draw document 1. New a draw document 2. Insert a picture 3.
269 	 * Save it as the input filename 4. Reopen the saved file 5. Check if the
270 	 * picture is still there
271 	 *
272 	 * @param filename
273 	 *            : filename to be saved
274 	 * @throws Exception
275 	 */
saveNewDrawing(String filename)276 	public void saveNewDrawing(String filename) {
277 		String saveTo = "temp/" + filename;
278 		String bmp_green = prepareData("image/green_256x256.bmp");
279 		// Create a new drawing document
280 		newDrawing();
281 		// Insert a picture fully filled with green
282 		app.dispatch(".uno:InsertGraphic");
283 		submitOpenDlg(bmp_green);
284 		// Focus on edit pane
285 		draw.click(5, 5);
286 		sleep(1);
287 		// Verify if the picture is inserted successfully
288 		Rectangle rectangle = GraphicsUtil.findRectangle(draw.getScreenRectangle(), 0xFF00FF00);
289 		assertNotNull("Green rectangle: " + rectangle, rectangle);
290 		deleteFile(saveTo);
291 		saveAs(saveTo);
292 		close();
293 		open(saveTo);
294 		draw.waitForExistence(10, 2);
295 		sleep(1);
296 		// Verify if the picture still exists in the file
297 		Rectangle rectangle1 = GraphicsUtil.findRectangle(draw.getScreenRectangle(), 0xFF00FF00);
298 		assertNotNull("Green rectangle: " + rectangle1, rectangle1);
299 	}
300 
301 	// math
302 	/**
303 	 * Test save a new math as .odf
304 	 */
305 	@Test
testSaveNewODF()306 	public void testSaveNewODF() throws Exception {
307 		saveNewMath("math_saveas.odf");
308 	}
309 
310 	/**
311 	 * Test save a new math as .sxm
312 	 */
313 	@Test
testSaveNewSXM()314 	public void testSaveNewSXM() throws Exception {
315 		saveNewMath("math_saveas.sxm");
316 	}
317 
318 	/**
319 	 * Test save a new math as .mml
320 	 */
321 	@Test
testSaveNewMML()322 	public void testSaveNewMML() throws Exception {
323 		saveNewMath("math_saveas.mml");
324 	}
325 
326 	/**
327 	 * New/Save a math 1. New a math 2. Insert a formula 3. Save it as the input
328 	 * filename 4. Reopen the saved file 5. Check if the formula is still there
329 	 *
330 	 * @param filename
331 	 *            : filename to be saved
332 	 * @throws Exception
333 	 */
saveNewMath(String filename)334 	public void saveNewMath(String filename) {
335 		String saveTo = "temp/" + filename;
336 		String text = "5 times 3 = 15";
337 		// Create a new math
338 		newFormula();
339 		// Insert a formula
340 		mathEditWindow.typeKeys(text);
341 		sleep(1);
342 		// Verify the text via system clip board
343 		String result = copyAll();
344 		sleep(1);
345 		assertEquals("The typed formula into math", text, result);
346 		result = null;
347 
348 		// Save the formula
349 		deleteFile(saveTo);
350 		saveAs(saveTo);
351 		close();
352 		open(saveTo);
353 		mathEditWindow.waitForExistence(10, 2);
354 		sleep(1);
355 		mathEditWindow.focus();
356 		result = copyAll();
357 		sleep(1);
358 		assertEquals("The typed formula into math is saved", text, result);
359 	}
360 }
361