157caf934SLiu Zhe /************************************************************** 257caf934SLiu Zhe * 357caf934SLiu Zhe * Licensed to the Apache Software Foundation (ASF) under one 457caf934SLiu Zhe * or more contributor license agreements. See the NOTICE file 557caf934SLiu Zhe * distributed with this work for additional information 657caf934SLiu Zhe * regarding copyright ownership. The ASF licenses this file 757caf934SLiu Zhe * to you under the Apache License, Version 2.0 (the 857caf934SLiu Zhe * "License"); you may not use this file except in compliance 957caf934SLiu Zhe * with the License. You may obtain a copy of the License at 1057caf934SLiu Zhe * 1157caf934SLiu Zhe * http://www.apache.org/licenses/LICENSE-2.0 1257caf934SLiu Zhe * 1357caf934SLiu Zhe * Unless required by applicable law or agreed to in writing, 1457caf934SLiu Zhe * software distributed under the License is distributed on an 1557caf934SLiu Zhe * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1657caf934SLiu Zhe * KIND, either express or implied. See the License for the 1757caf934SLiu Zhe * specific language governing permissions and limitations 1857caf934SLiu Zhe * under the License. 1957caf934SLiu Zhe * 2057caf934SLiu Zhe *************************************************************/ 2157caf934SLiu Zhe 2257caf934SLiu Zhe /** 2357caf934SLiu Zhe * 2457caf934SLiu Zhe */ 2557caf934SLiu Zhe 2657caf934SLiu Zhe package pvt.gui; 2757caf934SLiu Zhe 28f46d12a6SLiu Zhe import static org.junit.Assert.*; 2957caf934SLiu Zhe import static org.openoffice.test.common.Testspace.*; 3057caf934SLiu Zhe import static org.openoffice.test.vcl.Tester.*; 31f46d12a6SLiu Zhe import static testlib.gui.AppTool.*; 3257caf934SLiu Zhe import static testlib.gui.UIMap.*; 3357caf934SLiu Zhe 34f46d12a6SLiu Zhe import java.awt.Rectangle; 3557caf934SLiu Zhe import java.util.HashMap; 3657caf934SLiu Zhe 3757caf934SLiu Zhe import org.junit.AfterClass; 3857caf934SLiu Zhe import org.junit.BeforeClass; 3957caf934SLiu Zhe import org.junit.Rule; 4057caf934SLiu Zhe import org.junit.Test; 4157caf934SLiu Zhe import org.junit.rules.TestName; 4257caf934SLiu Zhe import org.openoffice.test.OpenOffice; 4357caf934SLiu Zhe import org.openoffice.test.common.Condition; 44e4b83892SLiu Zhe import org.openoffice.test.common.DataSheet; 45f46d12a6SLiu Zhe import org.openoffice.test.common.GraphicsUtil; 4657caf934SLiu Zhe import org.openoffice.test.common.Logger; 4757caf934SLiu Zhe 4857caf934SLiu Zhe 4957caf934SLiu Zhe public class Benchmark { 5057caf934SLiu Zhe @Rule 5157caf934SLiu Zhe public Logger log = Logger.getLogger(this); 5257caf934SLiu Zhe 5357caf934SLiu Zhe @Rule 5457caf934SLiu Zhe public TestName testname = new TestName(); 5557caf934SLiu Zhe 56e4b83892SLiu Zhe private static DataSheet result; 5757caf934SLiu Zhe 58e4b83892SLiu Zhe private static final double INTERVAL = 0.1; 5957caf934SLiu Zhe 60*9edf8282SLiu Zhe private static int repeat = 8; 61*9edf8282SLiu Zhe 6257caf934SLiu Zhe public Benchmark() { 6357caf934SLiu Zhe 6457caf934SLiu Zhe } 6557caf934SLiu Zhe 6657caf934SLiu Zhe @BeforeClass 6757caf934SLiu Zhe public static void beforeClass() throws Exception { 6857caf934SLiu Zhe OpenOffice.killAll(); 69*9edf8282SLiu Zhe result = new DataSheet(getFile("output/pvt_gui_benchmark.xml"), true); 70*9edf8282SLiu Zhe result.addRow("data", "Scenario", "No", "Consumed Time", "Memory(VSZ)", "Memory(RSS)", "Handles(Windows Only)"); 7157caf934SLiu Zhe } 7257caf934SLiu Zhe 7357caf934SLiu Zhe @AfterClass 7457caf934SLiu Zhe public static void afterClass() throws Exception { 75*9edf8282SLiu Zhe app.stop(); 7657caf934SLiu Zhe } 7757caf934SLiu Zhe 7857caf934SLiu Zhe private void addRecord(int i, long start, long end) { 79*9edf8282SLiu Zhe sleep(2); 80*9edf8282SLiu Zhe HashMap<String, Object> perf = aoo.getPerfData(); 81*9edf8282SLiu Zhe result.addRow("data", testname.getMethodName(), i, (end - start), perf.get("vsz"), perf.get("rss"), perf.get("handles")); 8257caf934SLiu Zhe } 8357caf934SLiu Zhe 8457caf934SLiu Zhe @Test 8557caf934SLiu Zhe public void coolStartup() throws Exception { 86*9edf8282SLiu Zhe app.stop(); 87*9edf8282SLiu Zhe for (int i = 0; i < repeat; i++) { 8857caf934SLiu Zhe aoo.cleanUserInstallation(); 89*9edf8282SLiu Zhe assertFalse("User profile exists", aoo.getUserInstallation().exists()); 9057caf934SLiu Zhe aoo.start(); 9157caf934SLiu Zhe long start = System.currentTimeMillis(); 9257caf934SLiu Zhe startcenter.waitForExistence(120, INTERVAL); 9357caf934SLiu Zhe long end = System.currentTimeMillis(); 94*9edf8282SLiu Zhe addRecord(i, start, end); 95*9edf8282SLiu Zhe app.quit(); 96*9edf8282SLiu Zhe } 9757caf934SLiu Zhe } 9857caf934SLiu Zhe 9957caf934SLiu Zhe @Test 10057caf934SLiu Zhe public void warmStartup() throws Exception { 101*9edf8282SLiu Zhe // Make sure we has generated user profile 102*9edf8282SLiu Zhe app.start(true); 103*9edf8282SLiu Zhe app.quit(); 104*9edf8282SLiu Zhe 105*9edf8282SLiu Zhe for (int i = 0; i < repeat; i++) { 106*9edf8282SLiu Zhe assertTrue("User profile exists", aoo.getUserInstallation().exists()); 10757caf934SLiu Zhe aoo.start(); 10857caf934SLiu Zhe long start = System.currentTimeMillis(); 10957caf934SLiu Zhe startcenter.waitForExistence(120, INTERVAL); 11057caf934SLiu Zhe long end = System.currentTimeMillis(); 11157caf934SLiu Zhe addRecord(i, start, end); 112*9edf8282SLiu Zhe app.quit(); 11357caf934SLiu Zhe } 11457caf934SLiu Zhe } 11557caf934SLiu Zhe 11657caf934SLiu Zhe @Test 11757caf934SLiu Zhe public void newTextDocument() { 118*9edf8282SLiu Zhe app.start(true); 119*9edf8282SLiu Zhe app.quit(); 120*9edf8282SLiu Zhe 121*9edf8282SLiu Zhe for (int i = 0; i < repeat; i++) { 122*9edf8282SLiu Zhe app.start(); 12357caf934SLiu Zhe startCenterWriterButton.click(0.5, 0.5); 12457caf934SLiu Zhe long start = System.currentTimeMillis(); 12557caf934SLiu Zhe writer.waitForExistence(60, INTERVAL); 12657caf934SLiu Zhe long end = System.currentTimeMillis(); 12757caf934SLiu Zhe addRecord(i, start, end); 128*9edf8282SLiu Zhe app.quit(); 12957caf934SLiu Zhe } 13057caf934SLiu Zhe } 13157caf934SLiu Zhe 13257caf934SLiu Zhe @Test 13357caf934SLiu Zhe public void newSpreadsheet() { 134*9edf8282SLiu Zhe app.start(true); 135*9edf8282SLiu Zhe app.quit(); 136*9edf8282SLiu Zhe for (int i = 0; i < repeat; i++) { 137*9edf8282SLiu Zhe app.start(); 13857caf934SLiu Zhe startCenterCalcButton.click(0.5, 0.5); 13957caf934SLiu Zhe long start = System.currentTimeMillis(); 14057caf934SLiu Zhe calc.waitForExistence(60, INTERVAL); 14157caf934SLiu Zhe long end = System.currentTimeMillis(); 14257caf934SLiu Zhe addRecord(i, start, end); 143*9edf8282SLiu Zhe app.quit(); 14457caf934SLiu Zhe } 14557caf934SLiu Zhe } 14657caf934SLiu Zhe 14757caf934SLiu Zhe @Test 14857caf934SLiu Zhe public void newPresentation() { 149*9edf8282SLiu Zhe app.start(true); 150*9edf8282SLiu Zhe app.quit(); 151*9edf8282SLiu Zhe for (int i = 0; i < repeat; i++) { 152*9edf8282SLiu Zhe app.start(); 15357caf934SLiu Zhe startCenterImpressButton.click(0.5, 0.5); 15457caf934SLiu Zhe presentationWizard.click(0.9, 0.95); 15557caf934SLiu Zhe long start = System.currentTimeMillis(); 15657caf934SLiu Zhe impress.waitForExistence(60, INTERVAL); 15757caf934SLiu Zhe long end = System.currentTimeMillis(); 15857caf934SLiu Zhe addRecord(i, start, end); 159*9edf8282SLiu Zhe app.quit(); 160*9edf8282SLiu Zhe } 161*9edf8282SLiu Zhe } 162*9edf8282SLiu Zhe 163*9edf8282SLiu Zhe @Test 164*9edf8282SLiu Zhe public void slideShow() { 165*9edf8282SLiu Zhe app.start(true); 166*9edf8282SLiu Zhe app.quit(); 167*9edf8282SLiu Zhe 168*9edf8282SLiu Zhe String path = prepareData("pvt/slideshow.odp"); 169*9edf8282SLiu Zhe final Rectangle rect = GraphicsUtil.getScreenRectangle(); 170*9edf8282SLiu Zhe // when slide show is running, top-center area will be filled with green 171*9edf8282SLiu Zhe rect.setRect(rect.getCenterX(), 2, 2, 2); 172*9edf8282SLiu Zhe for (int i = 0; i < repeat; i++) { 173*9edf8282SLiu Zhe app.start(); 174*9edf8282SLiu Zhe open(path); 175*9edf8282SLiu Zhe impress.waitForExistence(60, 1); 176*9edf8282SLiu Zhe sleep(2); 177*9edf8282SLiu Zhe assertFalse("Slideshow control exists", slideShow.exists()); 178*9edf8282SLiu Zhe assertFalse("Slideshow is not started", GraphicsUtil.isFilledWith(0xFF00FF00, rect)); 179*9edf8282SLiu Zhe typeKeys("<F5>"); 180*9edf8282SLiu Zhe long start = System.currentTimeMillis(); 181*9edf8282SLiu Zhe new Condition() { 182*9edf8282SLiu Zhe @Override 183*9edf8282SLiu Zhe public boolean value() { 184*9edf8282SLiu Zhe return GraphicsUtil.isFilledWith(0xFF00FF00, rect); 185*9edf8282SLiu Zhe } 186*9edf8282SLiu Zhe 187*9edf8282SLiu Zhe }.waitForTrue("", 120, INTERVAL); 188*9edf8282SLiu Zhe long end = System.currentTimeMillis(); 189*9edf8282SLiu Zhe addRecord(i, start, end); 190*9edf8282SLiu Zhe slideShow.typeKeys("<esc>"); 191*9edf8282SLiu Zhe sleep(2); 192*9edf8282SLiu Zhe app.quit(); 19357caf934SLiu Zhe } 19457caf934SLiu Zhe } 19557caf934SLiu Zhe 19657caf934SLiu Zhe @Test 197f46d12a6SLiu Zhe public void loadFinishPlainODT() { 198f46d12a6SLiu Zhe loadFinish("pvt/plain_200p.odt", "Page 1 / 23[0-9]{1}"); 19957caf934SLiu Zhe } 20057caf934SLiu Zhe 20157caf934SLiu Zhe @Test 202f46d12a6SLiu Zhe public void loadFinishPlainDOC() { 203e4b83892SLiu Zhe loadFinish("pvt/plain_50p.doc", "Page i / 5[0-9]{1}"); 20457caf934SLiu Zhe } 20557caf934SLiu Zhe 20657caf934SLiu Zhe @Test 207f46d12a6SLiu Zhe public void loadFinishPlainDOCX() { 208f46d12a6SLiu Zhe loadFinish("pvt/plain_200p.docx", "Page 1 / 19[0-9]{1}"); 20957caf934SLiu Zhe } 21057caf934SLiu Zhe 21157caf934SLiu Zhe @Test 21257caf934SLiu Zhe public void loadFinishPlainODS() { 213f46d12a6SLiu Zhe loadFinish("pvt/plain_11s.ods", "Sheet 1 / 11"); 21457caf934SLiu Zhe } 21557caf934SLiu Zhe 21657caf934SLiu Zhe @Test 217f46d12a6SLiu Zhe public void loadFinishPlainXLS() { 218f46d12a6SLiu Zhe loadFinish("pvt/plain_11s.xls", "Sheet 1 / 11"); 21957caf934SLiu Zhe } 22057caf934SLiu Zhe 22157caf934SLiu Zhe @Test 222f46d12a6SLiu Zhe public void loadFinishPlainXLSX() { 223f46d12a6SLiu Zhe loadFinish("pvt/plain_11s.xlsx", "Sheet 1 / 11"); 22457caf934SLiu Zhe } 22557caf934SLiu Zhe 22657caf934SLiu Zhe @Test 22757caf934SLiu Zhe public void loadFinishPlainODP() { 228f46d12a6SLiu Zhe loadFinish("pvt/plain_200p.odp", "Slide 1 / 200"); 22957caf934SLiu Zhe } 23057caf934SLiu Zhe 23157caf934SLiu Zhe @Test 23257caf934SLiu Zhe public void loadFinishPlainPPT() { 233f46d12a6SLiu Zhe loadFinish("pvt/plain_200p.ppt", "Slide 1 / 200"); 23457caf934SLiu Zhe } 23557caf934SLiu Zhe 23657caf934SLiu Zhe @Test 237f46d12a6SLiu Zhe public void loadFinishPlainPPTX() { 238f46d12a6SLiu Zhe loadFinish("pvt/plain_200p.pptx", "Slide 1 / 200"); 239f46d12a6SLiu Zhe } 240f46d12a6SLiu Zhe 241f46d12a6SLiu Zhe @Test 242f46d12a6SLiu Zhe public void loadFinishComplexDOC() { 243e4b83892SLiu Zhe loadFinish("pvt/complex_300p.doc", "Page 1 / 3[0-9]{2}"); 244f46d12a6SLiu Zhe } 245f46d12a6SLiu Zhe 246f46d12a6SLiu Zhe @Test 247*9edf8282SLiu Zhe public void loadFinishComplexDOCX() { 248*9edf8282SLiu Zhe loadFinish("pvt/complex_400p.doc", "Page 1 / 4[0-9]{2}"); 249*9edf8282SLiu Zhe } 250*9edf8282SLiu Zhe 251*9edf8282SLiu Zhe @Test 252f46d12a6SLiu Zhe public void loadFinishComplexODT() { 253e4b83892SLiu Zhe loadFinish("pvt/complex_800p.odt", "Page 1 / 8[0-9]{2}"); 254f46d12a6SLiu Zhe } 255f46d12a6SLiu Zhe 256f46d12a6SLiu Zhe @Test 257f46d12a6SLiu Zhe public void loadFinishComplexODS() { 258*9edf8282SLiu Zhe loadFinish("pvt/complex_19s.odt", "Sheet 8 / 19"); 259f46d12a6SLiu Zhe } 260f46d12a6SLiu Zhe 261f46d12a6SLiu Zhe @Test 26257caf934SLiu Zhe public void loadFinishComplexODP() { 263*9edf8282SLiu Zhe loadFinish("pvt/complex_150p.odp", "Slide 1 / 150"); 26457caf934SLiu Zhe } 26557caf934SLiu Zhe 26657caf934SLiu Zhe public void loadFinish(String file, final String indicator) { 267f46d12a6SLiu Zhe final int openIndicatorIndex = file.matches(".*\\.(odp|ppt|pptx)$") ? 4 : 0; 26857caf934SLiu Zhe String path = prepareData(file); 269*9edf8282SLiu Zhe app.stop(); 27057caf934SLiu Zhe for (int i = 0; i < 8; i++) { 271*9edf8282SLiu Zhe app.start(); 27257caf934SLiu Zhe app.dispatch(".uno:Open"); 27357caf934SLiu Zhe filePickerPath.setText(path); 274*9edf8282SLiu Zhe sleep(1); 275f46d12a6SLiu Zhe filePickerOpen.click(0.5, 0.5); 27657caf934SLiu Zhe long start = System.currentTimeMillis(); 27757caf934SLiu Zhe new Condition() { 27857caf934SLiu Zhe @Override 27957caf934SLiu Zhe public boolean value() { 280f46d12a6SLiu Zhe try { 281f46d12a6SLiu Zhe String text = statusBar.getItemText(openIndicatorIndex); 282f46d12a6SLiu Zhe return text.matches(indicator); 283f46d12a6SLiu Zhe } catch (Exception e) { 28457caf934SLiu Zhe return false; 285f46d12a6SLiu Zhe } 28657caf934SLiu Zhe } 28757caf934SLiu Zhe 28857caf934SLiu Zhe }.waitForTrue("", 120, INTERVAL); 28957caf934SLiu Zhe long end = System.currentTimeMillis(); 29057caf934SLiu Zhe addRecord(i, start, end); 291f46d12a6SLiu Zhe discard(); 292*9edf8282SLiu Zhe app.quit(); 29357caf934SLiu Zhe } 29457caf934SLiu Zhe } 29557caf934SLiu Zhe 296f46d12a6SLiu Zhe @Test 297f46d12a6SLiu Zhe public void savePlainDOC() { 298e4b83892SLiu Zhe save("pvt/plain_50p.doc", "Page i / 5[0-9]{1}"); 299f46d12a6SLiu Zhe } 30057caf934SLiu Zhe 301f46d12a6SLiu Zhe @Test 302f46d12a6SLiu Zhe public void savePlainODT() { 303f46d12a6SLiu Zhe save("pvt/plain_200p.odt", "Page 1 / 23[0-9]{1}"); 304f46d12a6SLiu Zhe } 305f46d12a6SLiu Zhe 306f46d12a6SLiu Zhe @Test 307f46d12a6SLiu Zhe public void saveComplexDOC() { 308e4b83892SLiu Zhe save("pvt/complex_300p.doc", "Page 1 / 3[0-9]{2}"); 309f46d12a6SLiu Zhe } 310f46d12a6SLiu Zhe 311f46d12a6SLiu Zhe @Test 312f46d12a6SLiu Zhe public void saveComplexODT() { 313e4b83892SLiu Zhe save("pvt/complex_800p.odt", "Page 1 / 8[0-9]{2}"); 314f46d12a6SLiu Zhe } 315f46d12a6SLiu Zhe 316f46d12a6SLiu Zhe @Test 317f46d12a6SLiu Zhe public void savePlainXLS() { 318f46d12a6SLiu Zhe save("pvt/plain_11s.xls", "Sheet 1 / 11"); 319f46d12a6SLiu Zhe } 320f46d12a6SLiu Zhe 321f46d12a6SLiu Zhe @Test 322f46d12a6SLiu Zhe public void savePlainODS() { 323f46d12a6SLiu Zhe save("pvt/plain_11s.ods", "Sheet 1 / 11"); 324f46d12a6SLiu Zhe } 325f46d12a6SLiu Zhe 326f46d12a6SLiu Zhe @Test 327f46d12a6SLiu Zhe public void saveComplexODS() { 328*9edf8282SLiu Zhe save("pvt/complex_19s.ods", "Sheet 8 / 19"); 329f46d12a6SLiu Zhe } 330f46d12a6SLiu Zhe 331f46d12a6SLiu Zhe @Test 332f46d12a6SLiu Zhe public void savePlainODP() { 333f46d12a6SLiu Zhe save("pvt/plain_200p.odp", "Slide 1 / 200"); 334f46d12a6SLiu Zhe } 335f46d12a6SLiu Zhe 336f46d12a6SLiu Zhe @Test 337f46d12a6SLiu Zhe public void savePlainPPT() { 338f46d12a6SLiu Zhe save("pvt/plain_200p.ppt", "Slide 1 / 200"); 339f46d12a6SLiu Zhe } 340f46d12a6SLiu Zhe 341f46d12a6SLiu Zhe @Test 342f46d12a6SLiu Zhe public void saveComplexODP() { 343*9edf8282SLiu Zhe save("pvt/complex_150p.odp", "Slide 1 / 150"); 344f46d12a6SLiu Zhe } 345f46d12a6SLiu Zhe 346f46d12a6SLiu Zhe public void save(String file, final String openIndicator) { 347f46d12a6SLiu Zhe boolean alienFormat = file.matches(".*\\.(doc|xls|ppt|docx|xlsx|pptx)$"); 348f46d12a6SLiu Zhe final int openIndicatorIndex = file.matches(".*\\.(odp|ppt|pptx)$") ? 4 : 0; 349f46d12a6SLiu Zhe final int saveIndicatorIndex = file.matches(".*\\.(odt|doc|docx)$") ? 5 : file.matches(".*\\.(ods|xls|xlsx)$") ? 4 : 2; 350*9edf8282SLiu Zhe app.stop(); 351f46d12a6SLiu Zhe String picture = prepareData("image/red_64x64.bmp"); 352*9edf8282SLiu Zhe for (int i = 0; i < repeat; i++) { 353f46d12a6SLiu Zhe String dir = "temp/file" + i; 354f46d12a6SLiu Zhe getFile(dir).mkdirs(); 355*9edf8282SLiu Zhe app.start(); 356f46d12a6SLiu Zhe open(prepareData(file, dir)); 357f46d12a6SLiu Zhe new Condition() { 358f46d12a6SLiu Zhe @Override 359f46d12a6SLiu Zhe public boolean value() { 360f46d12a6SLiu Zhe try { 361f46d12a6SLiu Zhe String text = statusBar.getItemText(openIndicatorIndex); 362f46d12a6SLiu Zhe return text.matches(openIndicator); 363f46d12a6SLiu Zhe } catch (Exception e) { 364f46d12a6SLiu Zhe return false; 365f46d12a6SLiu Zhe } 366f46d12a6SLiu Zhe } 367f46d12a6SLiu Zhe 368f46d12a6SLiu Zhe }.waitForTrue("", 120, 1); 369f46d12a6SLiu Zhe sleep(2); 370f46d12a6SLiu Zhe insertPicture(picture); 371f46d12a6SLiu Zhe sleep(3); 372f46d12a6SLiu Zhe assertEquals("File is modified", "*", statusBar.getItemText(saveIndicatorIndex)); 373f46d12a6SLiu Zhe app.dispatch(".uno:Save"); 374f46d12a6SLiu Zhe if (alienFormat) { 375f46d12a6SLiu Zhe alienFormatDlg.waitForExistence(3, 1); 376f46d12a6SLiu Zhe sleep(1); 377f46d12a6SLiu Zhe typeKeys("<enter>"); 378f46d12a6SLiu Zhe } 379f46d12a6SLiu Zhe 380f46d12a6SLiu Zhe long start = System.currentTimeMillis(); 381f46d12a6SLiu Zhe new Condition() { 382f46d12a6SLiu Zhe @Override 383f46d12a6SLiu Zhe public boolean value() { 384f46d12a6SLiu Zhe try { 385f46d12a6SLiu Zhe String text = statusBar.getItemText(saveIndicatorIndex); 386f46d12a6SLiu Zhe return " ".equals(text); 387f46d12a6SLiu Zhe } catch (Exception e) { 388f46d12a6SLiu Zhe return false; 389f46d12a6SLiu Zhe } 390f46d12a6SLiu Zhe } 391f46d12a6SLiu Zhe 392f46d12a6SLiu Zhe }.waitForTrue("", 120, INTERVAL); 393f46d12a6SLiu Zhe long end = System.currentTimeMillis(); 394f46d12a6SLiu Zhe addRecord(i, start, end); 395f46d12a6SLiu Zhe close(); 396*9edf8282SLiu Zhe app.stop(); 397f46d12a6SLiu Zhe } 398f46d12a6SLiu Zhe } 39957caf934SLiu Zhe } 400