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 svt.gui.sw; 26 27 import static org.openoffice.test.common.Testspace.getFile; 28 import static org.openoffice.test.common.Testspace.getPath; 29 import static org.openoffice.test.common.Testspace.prepareData; 30 import static org.openoffice.test.vcl.Tester.*; 31 import static testlib.gui.AppTool.*; 32 import static testlib.gui.UIMap.*; 33 34 import java.io.FileOutputStream; 35 import java.io.PrintStream; 36 import java.util.HashMap; 37 import java.util.logging.Level; 38 39 import org.junit.After; 40 import org.junit.AfterClass; 41 import org.junit.Before; 42 import org.junit.BeforeClass; 43 import org.junit.Ignore; 44 import org.junit.Rule; 45 import org.junit.Test; 46 import org.junit.rules.TestName; 47 import org.openoffice.test.common.DataSheet; 48 import org.openoffice.test.common.FileUtil; 49 import org.openoffice.test.common.Logger; 50 import org.openoffice.test.common.SystemUtil; 51 import org.openoffice.test.common.Testspace; 52 53 public class FileTypeAboutWriter { 54 @Rule 55 public Logger log = Logger.getLogger(this); 56 57 @Rule 58 public TestName testname = new TestName(); 59 60 private static DataSheet xmlResult; 61 62 private String pid = null; 63 64 private static int iterator = 100; 65 66 private int i = 0; 67 68 69 /** 70 * @throws java.lang.Exception 71 */ 72 @BeforeClass beforeClass()73 public static void beforeClass() throws Exception { 74 xmlResult = new DataSheet(getFile("output/svt_writertype.xml")); 75 xmlResult.addRow("Data", "Method", "No", "Consumed Time(MS)", "Memory(VSZ)", "Memory(RSS)", "Handles(Windows Only)"); 76 } 77 78 @AfterClass afterClass()79 public static void afterClass() throws Exception { 80 app.stop(); 81 } 82 83 @Before before()84 public void before()throws Exception{ 85 app.start(true); 86 } 87 88 89 @Test saveNewSWWithShapeToHTML()90 public void saveNewSWWithShapeToHTML()throws Exception{ 91 for ( i = 1; i <= iterator; i++) { 92 long start = System.currentTimeMillis(); 93 createNewSW(); 94 if(!swDrawingToolbar.exists()){ 95 app.dispatch(".uno:AvailableToolbars?Toolbar:string=drawbar"); 96 } 97 sleep(2); 98 app.dispatch(".uno:Rect"); 99 writer.focus(); 100 writer.drag(200, 200, 300, 300); 101 sleep(2); 102 103 typeKeys("<esc>"); 104 sleep(2); 105 saveToOther(i,".html"); 106 //reopen 107 String saveTo = getPath("temp/" + "tempDOC" + i + ".html"); 108 startCenterOpenButton.click(); 109 submitOpenDlg(saveTo); 110 sleep(1); 111 app.dispatch(".uno:CloseDoc"); 112 long end = System.currentTimeMillis(); 113 addRecord(i, start, end); 114 } 115 } 116 117 @Test saveNewSWWithLineToDoc()118 public void saveNewSWWithLineToDoc()throws Exception{ 119 for (i = 1; i <= iterator; i++) { 120 long start = System.currentTimeMillis(); 121 createNewSW(); 122 if(!swDrawingToolbar.exists()){ 123 app.dispatch(".uno:AvailableToolbars?Toolbar:string=drawbar"); 124 } 125 sleep(2); 126 swInsertLineButtonOnToolbar.click(); 127 writer.focus(); 128 for(int j=0;j<10;j++){ 129 // due to snap-to-grid the lines below will not all be parallel! 130 writer.drag( 150+j, 150+j*10, 200+j, 200+j*10); 131 sleep( 0.5); 132 } 133 typeKeys("<esc>"); 134 sleep(2); 135 saveToOther(i,".doc"); 136 long end = System.currentTimeMillis(); 137 addRecord(i, start, end); 138 } 139 } 140 141 @Test saveNewSWWithPicToDoc()142 public void saveNewSWWithPicToDoc() throws Exception { 143 String pic = prepareData("image/blue_256x256.jpg"); 144 for (i = 1; i <= iterator; i++) { 145 long start = System.currentTimeMillis(); 146 createNewSW(); 147 writer.menuItem("Insert->Picture->From File...").select(); 148 sleep(2); 149 filePickerPath.setText(pic); 150 sleep(1); 151 filePickerOpen.click(); 152 sleep(3); 153 typeKeys("<esc>"); 154 sleep(2); 155 saveToOther(i,".doc"); 156 long end = System.currentTimeMillis(); 157 addRecord(i, start, end); 158 } 159 } 160 createNewSW()161 private void createNewSW() { 162 app.dispatch("private:factory/swriter"); 163 } 164 saveToOther(int iterator, String type)165 private void saveToOther(int iterator, String type){ 166 String saveTo = getPath("temp/" + "tempDOC" + iterator + type); 167 writer.menuItem("File->Save As...").select(); 168 FileUtil.deleteFile(saveTo); 169 submitSaveDlg(saveTo); 170 if (activeMsgBox.exists()) { 171 activeMsgBox.yes(); 172 sleep(2); 173 } 174 if (alienFormatDlg.exists(3)) 175 alienFormatDlg.ok(); 176 app.dispatch(".uno:CloseDoc"); 177 startCenterOpenButton.waitForExistence(30, 2); 178 startCenterOpenButton.click(); 179 submitOpenDlg(saveTo); 180 sleep(2); 181 app.dispatch(".uno:CloseDoc"); 182 183 } 184 addRecord(int i, long start, long end)185 private void addRecord(int i, long start, long end) { 186 HashMap<String, Object> perf = aoo.getPerfData(); 187 xmlResult.addRow("Data",testname.getMethodName(), i, (end - start), 188 perf.get("vsz"), perf.get("rss"), perf.get("handles")); 189 log.log( Level.INFO, "\t"+testname.getMethodName()+"["+i+"] took "+(end-start)+"ms"); 190 } 191 192 193 } 194