xref: /AOO41X/test/testgui/source/pvt/gui/Benchmark.java (revision 464275f73717f5c86909a976eface2c484c3f953)
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 
26 package pvt.gui;
27 
28 import static org.junit.Assert.*;
29 import static org.openoffice.test.common.Testspace.*;
30 import static org.openoffice.test.vcl.Tester.*;
31 import static testlib.gui.AppTool.*;
32 import static testlib.gui.UIMap.*;
33 
34 import java.awt.Rectangle;
35 import java.util.HashMap;
36 
37 import org.junit.After;
38 import org.junit.AfterClass;
39 import org.junit.Before;
40 import org.junit.BeforeClass;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.junit.rules.TestName;
44 import org.openoffice.test.OpenOffice;
45 import org.openoffice.test.common.Condition;
46 import org.openoffice.test.common.DataSheet;
47 import org.openoffice.test.common.GraphicsUtil;
48 import org.openoffice.test.common.Logger;
49 
50 
51 public class Benchmark {
52     @Rule
53     public Logger log = Logger.getLogger(this);
54 
55     @Rule
56     public TestName testname = new TestName();
57 
58     private static DataSheet result;
59 
60     private static final double INTERVAL = 0.1;
61 
62     private static int repeat = 2;
63 
64     private int i  = 0;
65 
Benchmark()66     public Benchmark() {
67 
68     }
69 
70     @BeforeClass
beforeClass()71     public static void beforeClass() throws Exception {
72         OpenOffice.killAll();
73         result = new DataSheet(getFile("output/" + Benchmark.class.getName() + ".xml"));
74         result.addRow("data", "Scenario", "No", "Consumed Time", "Memory(VSZ)", "Memory(RSS)", "Handles(Windows Only)");
75     }
76 
77     @AfterClass
afterClass()78     public static void afterClass() throws Exception {
79         //app.stop();
80     }
81 
82     @Before
before()83     public void before() {
84         app.start(true);
85         app.quit();
86     }
87 
88     @After
after()89     public void after() {
90         if (i < repeat)
91             result.addRow("data", testname.getMethodName(), i, "err", "err", "err", "err", "err");
92     }
93 
addRecord(long start, long end)94     private void addRecord(long start, long end) {
95         sleep(2);
96         HashMap<String, Object>  perf = aoo.getPerfData();
97         result.addRow("data", testname.getMethodName(), i, (end - start), perf.get("vsz"), perf.get("rss"), perf.get("handles"));
98     }
99 
100     @Test
coolStartup()101     public void coolStartup() throws Exception {
102         for (i = 0; i < repeat; i++) {
103             aoo.cleanUserInstallation();
104             assertFalse("User profile exists", aoo.getUserInstallation().exists());
105             aoo.start();
106             long start = System.currentTimeMillis();
107             startcenter.waitForExistence(120, INTERVAL);
108             long end = System.currentTimeMillis();
109             addRecord(start, end);
110             app.quit();
111         }
112 
113     }
114 
115     @Test
warmStartup()116     public void warmStartup() throws Exception {
117         for (i = 0; i < repeat; i++) {
118             assertTrue("User profile exists", aoo.getUserInstallation().exists());
119             aoo.start();
120             long start = System.currentTimeMillis();
121             startcenter.waitForExistence(120, INTERVAL);
122             long end = System.currentTimeMillis();
123             addRecord(start, end);
124             app.quit();
125         }
126 
127     }
128 
129     @Test
newTextDocument()130     public void newTextDocument() {
131         for (i = 0; i < repeat; i++) {
132             app.start();
133             startCenterWriterButton.click(0.5, 0.5);
134             long start = System.currentTimeMillis();
135             writer.waitForExistence(60, INTERVAL);
136             long end = System.currentTimeMillis();
137             addRecord(start, end);
138             app.quit();
139         }
140 
141     }
142 
143     @Test
newSpreadsheet()144     public void newSpreadsheet() {
145         for (i = 0; i < repeat; i++) {
146             app.start();
147             startCenterCalcButton.click(0.5, 0.5);
148             long start = System.currentTimeMillis();
149             calc.waitForExistence(60, INTERVAL);
150             long end = System.currentTimeMillis();
151             addRecord(start, end);
152             app.quit();
153         }
154 
155     }
156 
157     @Test
newPresentation()158     public void newPresentation() {
159         for (i = 0; i < repeat; i++) {
160             app.start();
161             startCenterImpressButton.click(0.5, 0.5);
162             presentationWizard.click(0.9, 0.95);
163             long start = System.currentTimeMillis();
164             impress.waitForExistence(60, INTERVAL);
165             long end = System.currentTimeMillis();
166             addRecord(start, end);
167             app.quit();
168         }
169 
170     }
171 
172     @Test
slideShow()173     public void slideShow() {
174         String path = prepareData("pvt/slideshow.odp");
175         final Rectangle rect = GraphicsUtil.getScreenRectangle();
176         // when slide show is running, top-center area will be filled with green
177         rect.setRect(rect.getCenterX(), 2, 2, 2);
178         for (i = 0; i < repeat; i++) {
179             app.start();
180             open(path);
181             impress.waitForExistence(60, 1);
182             sleep(2);
183             assertFalse("Slideshow control exists", slideShow.exists());
184             assertFalse("Slideshow is not started", GraphicsUtil.isFilledWith(0xFF00FF00, rect));
185             typeKeys("<F5>");
186             long start = System.currentTimeMillis();
187             new Condition() {
188                 @Override
189                 public boolean value() {
190                     return GraphicsUtil.isFilledWith(0xFF00FF00, rect);
191                 }
192 
193             }.waitForTrue("", 120, INTERVAL);
194             long end = System.currentTimeMillis();
195             addRecord(start, end);
196             slideShow.typeKeys("<esc>");
197             sleep(2);
198             app.quit();
199         }
200 
201     }
202 
203     @Test
loadFinishPlainODT()204     public void loadFinishPlainODT() {
205         loadFinish("pvt/plain_200p.odt", "Page 1 / 23[0-9]{1}");
206     }
207 
208     @Test
loadFinishPlainDOC()209     public void loadFinishPlainDOC() {
210         loadFinish("pvt/plain_50p.doc", "Page i / 5[0-9]{1}");
211     }
212 
213     @Test
loadFinishPlainDOCX()214     public void loadFinishPlainDOCX() {
215         loadFinish("pvt/plain_200p.docx", "Page 1 / 1[8-9]{1}[0-9]{1}");
216     }
217 
218     @Test
loadFinishPlainODS()219     public void loadFinishPlainODS() {
220         loadFinish("pvt/plain_11s.ods", "Sheet 1 / 11");
221     }
222 
223     @Test
loadFinishPlainXLS()224     public void loadFinishPlainXLS() {
225         loadFinish("pvt/plain_11s.xls", "Sheet 1 / 11");
226     }
227 
228     @Test
loadFinishPlainXLSX()229     public void loadFinishPlainXLSX() {
230         loadFinish("pvt/plain_11s.xlsx", "Sheet 1 / 11");
231     }
232 
233     @Test
loadFinishPlainODP()234     public void loadFinishPlainODP() {
235         loadFinish("pvt/plain_200p.odp", "Slide 1 / 200");
236     }
237 
238     @Test
loadFinishPlainPPT()239     public void loadFinishPlainPPT() {
240         loadFinish("pvt/plain_200p.ppt", "Slide 1 / 200");
241     }
242 
243     @Test
loadFinishPlainPPTX()244     public void loadFinishPlainPPTX() {
245         loadFinish("pvt/plain_200p.pptx", "Slide 1 / 200");
246     }
247 
248     @Test
loadFinishComplexDOC()249     public void loadFinishComplexDOC() {
250         loadFinish("pvt/complex_300p.doc", "Page 1 / 3[0-9]{2}");
251     }
252 
253     @Test
loadFinishComplexDOCX()254     public void loadFinishComplexDOCX() {
255         loadFinish("pvt/complex_400p.docx", "Page 1 / 3[2-9]{2}");
256     }
257 
258     @Test
loadFinishComplexODT()259     public void loadFinishComplexODT() {
260         loadFinish("pvt/complex_800p.odt", "Page 1 / 8[0-9]{2}");
261     }
262 
263     @Test
loadFinishComplexODS()264     public void loadFinishComplexODS() {
265         loadFinish("pvt/complex_19s.ods", "Sheet 8 / 19");
266     }
267 
268     @Test
loadFinishComplexXLS()269     public void loadFinishComplexXLS() {
270         loadFinish("pvt/complex_29s.xls", "Sheet 2 / 29");
271     }
272 
273     @Test
loadFinishComplexXLSX()274     public void loadFinishComplexXLSX() {
275         loadFinish("pvt/complex_29s.xlsx", "Sheet 29 / 29");
276     }
277 
278     @Test
loadFinishComplexODP()279     public void loadFinishComplexODP() {
280         loadFinish("pvt/complex_150p.odp", "Slide 1 / 150");
281     }
282 
283     @Test
loadFinishComplexPPT()284     public void loadFinishComplexPPT() {
285         loadFinish("pvt/complex_100p.ppt", "Slide 1 / 100");
286     }
287 
288     @Test
loadFinishComplexPPTX()289     public void loadFinishComplexPPTX() {
290         loadFinish("pvt/complex_100p.pptx", "Slide 1 / 100");
291     }
292 
loadFinish(String file, final String indicator)293     public void loadFinish(String file, final String indicator) {
294         final int openIndicatorIndex = file.matches(".*\\.(odp|ppt|pptx)$") ? 4 : 0;
295         String path = prepareData(file);
296         for (i = 0; i < repeat; i++) {
297             app.start();
298             app.dispatch(".uno:Open");
299             filePickerPath.setText(path);
300             sleep(1);
301             filePickerOpen.click(0.5, 0.5);
302             long start = System.currentTimeMillis();
303             new Condition() {
304                 @Override
305                 public boolean value() {
306                     try {
307                         String text = statusBar.getItemText(openIndicatorIndex);
308                         return text.matches(indicator);
309                     } catch (Exception e) {
310                         return false;
311                     }
312                 }
313 
314             }.waitForTrue("", 120, INTERVAL);
315             long end = System.currentTimeMillis();
316             addRecord(start, end);
317             discard();
318             app.quit();
319         }
320 
321     }
322 
323     @Test
savePlainODT()324     public void savePlainODT() {
325         save("pvt/plain_200p.odt", "Page 1 / 23[0-9]{1}");
326     }
327 
328     @Test
savePlainDOC()329     public void savePlainDOC() {
330         save("pvt/plain_50p.doc", "Page i / 5[0-9]{1}");
331     }
332 
333     @Test
savePlainODS()334     public void savePlainODS() {
335         save("pvt/plain_11s.ods", "Sheet 1 / 11");
336     }
337 
338     @Test
savePlainXLS()339     public void savePlainXLS() {
340         save("pvt/plain_11s.xls", "Sheet 1 / 11");
341     }
342 
343     @Test
savePlainODP()344     public void savePlainODP() {
345         save("pvt/plain_200p.odp", "Slide 1 / 200");
346     }
347 
348     @Test
savePlainPPT()349     public void savePlainPPT() {
350         save("pvt/plain_200p.ppt", "Slide 1 / 200");
351     }
352 
353     @Test
saveComplexODT()354     public void saveComplexODT() {
355         save("pvt/complex_800p.odt", "Page 1 / 8[0-9]{2}");
356     }
357 
358     @Test
saveComplexDOC()359     public void saveComplexDOC() {
360         save("pvt/complex_300p.doc", "Page 1 / 3[0-9]{2}");
361     }
362 
363     @Test
saveComplexODS()364     public void saveComplexODS() {
365         save("pvt/complex_19s.ods", "Sheet 8 / 19");
366     }
367 
368     @Test
saveComplexXLS()369     public void saveComplexXLS() {
370         save("pvt/complex_29s.xls", "Sheet 2 / 29");
371     }
372 
373     @Test
saveComplexODP()374     public void saveComplexODP() {
375         save("pvt/complex_150p.odp", "Slide 1 / 150");
376     }
377 
378     @Test
saveComplexPPT()379     public void saveComplexPPT() {
380         save("pvt/complex_100p.ppt", "Slide 1 / 100");
381     }
382 
save(String file, final String openIndicator)383     public void save(String file, final String openIndicator) {
384         boolean alienFormat = file.matches(".*\\.(doc|xls|ppt|docx|xlsx|pptx)$");
385         final int openIndicatorIndex = file.matches(".*\\.(odp|ppt|pptx)$") ? 4 : 0;
386         final int saveIndicatorIndex = file.matches(".*\\.(odt|doc|docx)$") ? 5 : file.matches(".*\\.(ods|xls|xlsx)$") ? 4 : 2;
387         String picture = prepareData("image/red_64x64.bmp");
388         for (i = 0; i < repeat; i++) {
389             String dir = "temp/file" + i;
390             getFile(dir).mkdirs();
391             app.start();
392             open(prepareData(file, dir));
393             new Condition() {
394                 @Override
395                 public boolean value() {
396                     try {
397                         String text = statusBar.getItemText(openIndicatorIndex);
398                         return text.matches(openIndicator);
399                     } catch (Exception e) {
400                         return false;
401                     }
402                 }
403 
404             }.waitForTrue("", 120, 1);
405             sleep(2);
406             insertPicture(picture);
407             sleep(5);
408             assertEquals("File is modified", "*", statusBar.getItemText(saveIndicatorIndex));
409             app.dispatch(".uno:Save");
410             if (alienFormat) {
411                 alienFormatDlg.waitForExistence(3, 1);
412                 sleep(1);
413                 typeKeys("<enter>");
414             }
415 
416             long start = System.currentTimeMillis();
417             new Condition() {
418                 @Override
419                 public boolean value() {
420                     try {
421                         String text = statusBar.getItemText(saveIndicatorIndex);
422                         return " ".equals(text);
423                     } catch (Exception e) {
424                         return false;
425                     }
426                 }
427 
428             }.waitForTrue("", 120, INTERVAL);
429             long end = System.currentTimeMillis();
430             addRecord(start, end);
431             close();
432             app.stop();
433         }
434 
435     }
436 }
437