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