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