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 Assert.assertEquals("The typed text is saved!", text, copyAll().trim()); 222 } 223 224 // drawing 225 226 /** 227 * Test save a new drawing as .odg 228 */ 229 @Test testSaveNewODG()230 public void testSaveNewODG() throws Exception { 231 saveNewDrawing("draw_saveas.odg"); 232 } 233 234 /** 235 * Test save a new drawing as .otg 236 */ 237 @Test testSaveNewOTG()238 public void testSaveNewOTG() throws Exception { 239 saveNewDrawing("draw_saveas.otg"); 240 } 241 242 /** 243 * Test save a new drawing as .sxd 244 */ 245 @Test testSaveNewSXD()246 public void testSaveNewSXD() throws Exception { 247 saveNewDrawing("draw_saveas.sxd"); 248 } 249 250 /** 251 * Test save a new drawing as .std 252 */ 253 @Test testSaveNewSTD()254 public void testSaveNewSTD() throws Exception { 255 saveNewDrawing("draw_saveas.std"); 256 } 257 258 /** 259 * New/Save a draw document 1. New a draw document 2. Insert a picture 3. 260 * Save it as the input filename 4. Reopen the saved file 5. Check if the 261 * picture is still there 262 * 263 * @param filename 264 * : filename to be saved 265 * @throws Exception 266 */ saveNewDrawing(String filename)267 public void saveNewDrawing(String filename) { 268 String saveTo = "temp/" + filename; 269 String bmp_green = prepareData("image/green_256x256.bmp"); 270 // Create a new drawing document 271 newDrawing(); 272 // Insert a picture fully filled with green 273 app.dispatch(".uno:InsertGraphic"); 274 submitOpenDlg(bmp_green); 275 // Focus on edit pane 276 draw.click(5, 5); 277 sleep(1); 278 // Verify if the picture is inserted successfully 279 Rectangle rectangle = GraphicsUtil.findRectangle(draw.getScreenRectangle(), 0xFF00FF00); 280 assertNotNull("Green rectangle: " + rectangle, rectangle); 281 deleteFile(saveTo); 282 saveAs(saveTo); 283 close(); 284 open(saveTo); 285 draw.waitForExistence(10, 2); 286 sleep(1); 287 // Verify if the picture still exists in the file 288 Rectangle rectangle1 = GraphicsUtil.findRectangle(draw.getScreenRectangle(), 0xFF00FF00); 289 assertNotNull("Green rectangle: " + rectangle1, rectangle1); 290 } 291 292 // math 293 /** 294 * Test save a new math as .odf 295 */ 296 @Test testSaveNewODF()297 public void testSaveNewODF() throws Exception { 298 saveNewMath("math_saveas.odf"); 299 } 300 301 /** 302 * Test save a new math as .sxm 303 */ 304 @Test testSaveNewSXM()305 public void testSaveNewSXM() throws Exception { 306 saveNewMath("math_saveas.sxm"); 307 } 308 309 /** 310 * Test save a new math as .mml 311 */ 312 @Test testSaveNewMML()313 public void testSaveNewMML() throws Exception { 314 saveNewMath("math_saveas.mml"); 315 } 316 317 /** 318 * New/Save a math 1. New a math 2. Insert a formula 3. Save it as the input 319 * filename 4. Reopen the saved file 5. Check if the formula is still there 320 * 321 * @param filename 322 * : filename to be saved 323 * @throws Exception 324 */ saveNewMath(String filename)325 public void saveNewMath(String filename) { 326 String saveTo = "temp/" + filename; 327 String text = "5 times 3 = 15"; 328 // Create a new math 329 newFormula(); 330 // Insert a formula 331 mathEditWindow.typeKeys(text); 332 // Verify the text via system clip board 333 assertEquals("The typed formula into math", text, copyAll()); 334 335 // Save the formula 336 deleteFile(saveTo); 337 saveAs(saveTo); 338 close(); 339 open(saveTo); 340 mathEditWindow.waitForExistence(10, 2); 341 sleep(1); 342 mathEditWindow.focus(); 343 assertEquals("The typed formula into math is saved", text, copyAll()); 344 } 345 } 346