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