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 package svt.gui.sw; 26 27 import static org.openoffice.test.common.Testspace.getFile; 28 import static org.openoffice.test.common.Testspace.getPath; 29 import static org.openoffice.test.common.Testspace.prepareData; 30 import static org.openoffice.test.vcl.Tester.*; 31 import static testlib.gui.AppTool.*; 32 import static testlib.gui.UIMap.*; 33 34 import java.io.FileOutputStream; 35 import java.io.PrintStream; 36 import java.util.HashMap; 37 38 import org.junit.After; 39 import org.junit.AfterClass; 40 import org.junit.Before; 41 import org.junit.BeforeClass; 42 import org.junit.Ignore; 43 import org.junit.Rule; 44 import org.junit.Test; 45 import org.junit.rules.TestName; 46 import org.openoffice.test.common.DataSheet; 47 import org.openoffice.test.common.FileUtil; 48 import org.openoffice.test.common.Logger; 49 import org.openoffice.test.common.SystemUtil; 50 import org.openoffice.test.common.Testspace; 51 52 public class BasicFuncOnWriter { 53 @Rule 54 public Logger log = Logger.getLogger(this); 55 56 @Rule 57 public TestName testname = new TestName(); 58 59 private static DataSheet xmlResult; 60 61 private String pid = null; 62 63 private static int iterator = 2; 64 65 private int i = 0; 66 67 /** 68 * @throws java.lang.Exception 69 */ 70 @BeforeClass 71 public static void beforeClass() throws Exception { 72 xmlResult = new DataSheet(getFile("output/svt.xml")); 73 xmlResult.addRow("Data", "Method", "No", "Consumed Time(MS)", "Memory(VSZ)", "Memory(RSS)", "Handles(Windows Only)"); 74 } 75 76 @AfterClass 77 public static void afterClass() throws Exception { 78 app.stop(); 79 } 80 81 @Before 82 public void before()throws Exception{ 83 app.start(true); 84 } 85 86 @Test 87 public void saveNewSWWithPic() throws Exception { 88 String pic = prepareData("image/blue_256x256.jpg"); 89 for (i = 1; i <= iterator; i++) { 90 long start = System.currentTimeMillis(); 91 createNewSW(); 92 writer.menuItem("Insert->Picture->From File...").select(); 93 sleep(2); 94 filePickerPath.setText(pic); 95 sleep(1); 96 filePickerOpen.click(); 97 sleep(5); 98 typeKeys("<esc>"); 99 sleep(2); 100 saveAndReopenNewSW(i); 101 long end = System.currentTimeMillis(); 102 addRecord(i, start, end); 103 } 104 } 105 106 107 @Test 108 public void saveNewSWWithBullet() throws Exception { 109 for (i = 1; i <= iterator; i++) { 110 long start = System.currentTimeMillis(); 111 createNewSW(); 112 writer.typeKeys("The first"); 113 writer.typeKeys("<enter>"); 114 sleep(3); 115 writer.typeKeys("The second"); 116 app.dispatch(".uno:SelectAll"); 117 writer.menuItem("Format->Bullets and Numbering...").select(); 118 sleep(3); 119 bulletPage.ok(); 120 writer.typeKeys("<ctrl z"); 121 sleep(1); 122 writer.typeKeys("<ctrl y>"); 123 sleep(1); 124 writer.typeKeys("<ctrl end>"); 125 writer.typeKeys("<enter>"); 126 sleep(2); 127 128 writer.focus(); 129 saveAndReopenNewSW(i); 130 long end = System.currentTimeMillis(); 131 addRecord(i, start, end); 132 } 133 } 134 135 @Test 136 public void saveNewSWWithUnDoDelete()throws Exception{ 137 if(!sdDrawingToolbar.exists()){ 138 app.dispatch(".uno:AvailableToolbars?Toolbar:string=toolbar"); 139 } 140 for (i = 1; i <= iterator; i++) { 141 long start = System.currentTimeMillis(); 142 createNewSW(); 143 app.dispatch(".uno:Ellipse"); 144 writer.focus(); 145 writer.drag(200, 200, 300, 300); 146 typeKeys("<Delete>"); 147 typeKeys("<ctrl z>"); 148 typeKeys("<ctrl y>"); 149 150 saveAndReopenNewSW(i); 151 long end = System.currentTimeMillis(); 152 addRecord(i, start, end); 153 } 154 } 155 156 157 @Test 158 public void saveNewSWWithSpellCheck() throws Exception { 159 for (i = 1; i <= iterator; i++) { 160 long start = System.currentTimeMillis(); 161 createNewSW(); 162 writer.typeKeys("goood"); 163 sleep(2); 164 writer.menuItem("Tools->Spelling and Grammar...").select(); 165 sleep(2); 166 spellcheckDlgSuggestionList.select(0); 167 spellcheckDlgIgnoreOnce.click(); 168 activeMsgBox.ok(); 169 sleep(2); 170 saveAndReopenNewSW(i); 171 long end = System.currentTimeMillis(); 172 addRecord(i, start, end); 173 } 174 } 175 176 @Test 177 public void saveNewSWWithHeaderFooter() throws Exception { 178 for (i = 1; i <= iterator; i++) { 179 long start = System.currentTimeMillis(); 180 createNewSW(); 181 writer.menuItem("Insert->Header->Default").select(); 182 sleep(2); 183 writer.typeKeys("Header"); 184 sleep(2); 185 writer.menuItem("Insert->Footer->Default").select(); 186 sleep(2); 187 writer.typeKeys("Footer"); 188 sleep(2); 189 writer.typeKeys("<ctrl end>"); 190 sleep(2); 191 writer.typeKeys("<enter>"); 192 sleep(2); 193 saveAndReopenNewSW(i); 194 long end = System.currentTimeMillis(); 195 addRecord(i, start, end); 196 } 197 } 198 199 @Test 200 public void saveNewSWWithFrameAnchor() throws Exception { 201 for (i = 1; i <= iterator; i++) { 202 long start = System.currentTimeMillis(); 203 createNewSW(); 204 writer.menuItem("Insert->Frame...").select(); 205 sleep(2); 206 writerFrameDlg.ok(); 207 writer.menuItem("Format->Anchor->To Page").select(); 208 sleep(2); 209 writer.menuItem("Format->Anchor->To Paragraph").select(); 210 sleep(2); 211 writer.menuItem("Format->Anchor->To Character").select(); 212 sleep(2); 213 writer.menuItem("Format->Anchor->As Character").select(); 214 sleep(2); 215 writer.typeKeys("<esc>"); 216 sleep(2); 217 writer.typeKeys("<enter>"); 218 sleep(2); 219 saveAndReopenNewSW(i); 220 long end = System.currentTimeMillis(); 221 addRecord(i, start, end); 222 } 223 } 224 225 @Test 226 public void saveNewSWWithSDAsOLE()throws Exception{ 227 String linkFile = prepareData("pvt/plain_200p.odp"); 228 for (i = 1; i <= iterator; i++) { 229 long start = System.currentTimeMillis(); 230 createNewSW(); 231 app.dispatch(".uno:InsertObject"); 232 sleep(2); 233 insertObject.waitForExistence(60, 2); 234 objectFromFile.check(); 235 objectFilePath.setText(linkFile); 236 objectFileLink.check(); 237 insertObject.ok(); 238 sleep(10); 239 240 writer.focus(); 241 writer.doubleClick(200, 300); 242 sleep(15); 243 writer.activate(); 244 writer.click(10, 10); 245 sleep(5); 246 247 saveAndReopenNewSW(i); 248 long end = System.currentTimeMillis(); 249 addRecord(i, start, end); 250 } 251 } 252 253 @Test 254 public void saveNewSWWithTOC() throws Exception { 255 for (i = 1; i <= iterator; i++) { 256 long start = System.currentTimeMillis(); 257 createNewSW(); 258 for (int j = 0; j < 6; j++) { 259 writer.typeKeys(String.valueOf(j + 1)); 260 writer.typeKeys("<enter>"); 261 } 262 writer.typeKeys("<ctrl home>"); 263 for (int k = 0; k < 2; k++) { 264 writer.typeKeys("<shift down>"); 265 } 266 if (!styleAndFormattingDlg.exists()) { 267 app.dispatch(".uno:DesignerDialog"); 268 sleep(2); 269 } 270 271 styleAndFormattingList.doubleClick(0.5, 0.25); 272 sleep(2); 273 writer.typeKeys("<down>"); 274 writer.typeKeys("<right>"); 275 writer.typeKeys("<left>"); 276 for (int k = 0; k < 2; k++) { 277 writer.typeKeys("<shift down>"); 278 } 279 styleAndFormattingList.doubleClick(0.5, 0.3); 280 sleep(2); 281 writer.typeKeys("<ctrl home>"); 282 sleep(2); 283 writer.menuItem("Insert->Indexes and Tables->Indexes and Tables...").select(); 284 sleep(2); 285 insertIndexDlg.ok(); 286 sleep(2); 287 writer.typeKeys("<ctrl end>"); 288 saveAndReopenNewSW(i); 289 long end = System.currentTimeMillis(); 290 addRecord(i, start, end); 291 } 292 } 293 294 @Test 295 public void splitMergeTableOnOpenedSW() throws Exception { 296 String file = prepareData("svt/swdesign.odt"); 297 for (i = 1; i <= iterator; i++) { 298 long start = System.currentTimeMillis(); 299 app.dispatch(".uno:Open"); 300 submitOpenDlg(file); 301 writer.waitForExistence(10, 2); 302 writer.typeKeys("<down>"); 303 writer.typeKeys("<down>"); 304 sleep(2); 305 306 writer.menuItem("Table->Split Cells").select(); 307 sleep(2); 308 writerSplitCellDlg.ok(); 309 sleep(2); 310 311 writer.typeKeys("<shift down>"); 312 writer.typeKeys("<shift down>"); 313 writer.typeKeys("<shift down>"); 314 writer.typeKeys("<shift down>"); 315 writer.typeKeys("<shift down>"); 316 sleep(2); 317 writer.menuItem("Table->Merge Cells").select(); 318 sleep(2); 319 320 writer.typeKeys("<enter>"); 321 closeWithoutSaveSW(); 322 long end = System.currentTimeMillis(); 323 addRecord(i, start, end); 324 } 325 } 326 327 @Test 328 public void addDelColumnsRowsInTableOnOpenedSW() throws Exception { 329 String file = prepareData("svt/swdesign.odt"); 330 for (i = 1; i <= iterator; i++) { 331 long start = System.currentTimeMillis(); 332 app.dispatch(".uno:Open"); 333 submitOpenDlg(file); 334 writer.waitForExistence(10, 2); 335 writer.typeKeys("<down>"); 336 writer.typeKeys("<down>"); 337 sleep(2); 338 339 app.dispatch(".uno:InsertRowDialog"); 340 writerInsertRowsDlg.ok(); 341 sleep(2); 342 343 writer.menuItem("Table->Delete->Rows").select(); 344 sleep(2); 345 346 app.dispatch(".uno:InsertColumnDialog"); 347 writerInsertColumnsDlg.ok(); 348 sleep(2); 349 350 writer.menuItem("Table->Delete->Columns").select(); 351 sleep(2); 352 353 closeWithoutSaveSW(); 354 long end = System.currentTimeMillis(); 355 addRecord(i, start, end); 356 } 357 } 358 359 @Test 360 public void setParaPropertoesOnOpenedSW() throws Exception { 361 String file = prepareData("pvt/plain_200p.odt"); 362 for (i = 1; i <= iterator; i++) { 363 long start = System.currentTimeMillis(); 364 app.dispatch(".uno:Open"); 365 submitOpenDlg(file); 366 writer.waitForExistence(10, 2); 367 writer.focus(); 368 app.dispatch(".uno:ParagraphDialog"); 369 alignPage.select(); 370 alignPageRight.check(); 371 sleep(2); 372 alignPageVerticalAlign.select("Bottom"); 373 sleep(2); 374 alignPage.ok(); 375 sleep(2); 376 writer.typeKeys("<ctrl end>"); 377 sleep(5); 378 379 closeWithoutSaveSW(); 380 long end = System.currentTimeMillis(); 381 addRecord(i, start, end); 382 } 383 } 384 385 @Test 386 public void InsertPicToOpenedSW() throws Exception { 387 String file = prepareData("pvt/plain_200p.odt"); 388 String pic = prepareData("image/blue_256x256.jpg"); 389 for (i = 1; i <= iterator; i++) { 390 long start = System.currentTimeMillis(); 391 app.dispatch(".uno:Open"); 392 submitOpenDlg(file); 393 writer.waitForExistence(10, 2); 394 writer.focus(); 395 writer.menuItem("Insert->Picture->From File...").select(); 396 sleep(2); 397 filePickerPath.setText(pic); 398 sleep(1); 399 filePickerOpen.click(); 400 sleep(5); 401 writer.typeKeys("<esc>"); 402 sleep(2); 403 closeWithoutSaveSW(); 404 long end = System.currentTimeMillis(); 405 addRecord(i, start, end); 406 } 407 } 408 409 @Test 410 public void InsertOLEToOpenedSW() throws Exception { 411 String file = prepareData("pvt/plain_200p.odt"); 412 for (i = 1; i <= iterator; i++) { 413 long start = System.currentTimeMillis(); 414 app.dispatch(".uno:Open"); 415 submitOpenDlg(file); 416 writer.waitForExistence(10, 2); 417 writer.focus(); 418 app.dispatch(".uno:InsertObject"); 419 sleep(2); 420 insertObject.ok(); 421 sleep(10); 422 typeKeys("<esc>"); 423 sleep(5); 424 typeKeys("<esc>"); 425 sleep(5); 426 closeWithoutSaveSW(); 427 long end = System.currentTimeMillis(); 428 addRecord(i, start, end); 429 } 430 } 431 432 @Test 433 public void InsertChartToOpenedSW() throws Exception { 434 String file = prepareData("pvt/plain_200p.odt"); 435 for (i = 1; i <= iterator; i++) { 436 long start = System.currentTimeMillis(); 437 app.dispatch(".uno:Open"); 438 submitOpenDlg(file); 439 writer.waitForExistence(10, 2); 440 writer.focus(); 441 app.dispatch(".uno:InsertObjectChart"); 442 // writer.menuItem("Insert->Object->Chart...").select(); 443 sleep(5); 444 typeKeys("<esc>"); 445 sleep(5); 446 typeKeys("<esc>"); 447 sleep(5); 448 typeKeys("<esc>"); 449 sleep(5); 450 closeWithoutSaveSW(); 451 long end = System.currentTimeMillis(); 452 addRecord(i, start, end); 453 } 454 } 455 456 @Test 457 public void openSWWithXForm()throws Exception{ 458 String file = prepareData("svt/sickness_self-certification_meory issue.odt"); 459 for (i = 1; i <= iterator; i++) { 460 long start = System.currentTimeMillis(); 461 app.dispatch(".uno:Open"); 462 submitOpenDlg(file); 463 writer.waitForExistence(10, 2); 464 app.dispatch(".uno:CloseDoc"); 465 466 long end = System.currentTimeMillis(); 467 addRecord(i, start, end); 468 } 469 } 470 471 @Test 472 public void openSWWithSecuritySignature()throws Exception{ 473 String file = prepareData("svt/howtouse.odt"); 474 for (i = 1; i <= iterator; i++) { 475 long start = System.currentTimeMillis(); 476 app.dispatch(".uno:Open"); 477 submitOpenDlg(file); 478 writer.waitForExistence(10, 2); 479 app.dispatch(".uno:CloseDoc"); 480 481 long end = System.currentTimeMillis(); 482 addRecord(i, start, end); 483 } 484 } 485 486 487 private void createNewSW() { 488 app.dispatch("private:factory/swriter"); 489 } 490 491 private void saveAndReopenNewSW(int iterator) { 492 String saveTo = getPath("temp/" + "tempSW_New" + iterator + ".odt"); 493 writer.menuItem("File->Save As...").select(); 494 FileUtil.deleteFile(saveTo); 495 submitSaveDlg(saveTo); 496 if (activeMsgBox.exists()) { 497 activeMsgBox.yes(); 498 sleep(2); 499 } 500 app.dispatch(".uno:CloseDoc"); 501 startCenterOpenButton.waitForExistence(30, 2); 502 startCenterOpenButton.click(); 503 submitOpenDlg(saveTo); 504 sleep(1); 505 app.dispatch(".uno:CloseDoc"); 506 } 507 508 private void closeWithoutSaveSW() { 509 writer.menuItem("File->Close").select(); 510 if (activeMsgBox.exists()) { 511 activeMsgBox.no(); 512 sleep(2); 513 } 514 } 515 516 private void addRecord(int i, long start, long end) { 517 HashMap<String, Object> perf = aoo.getPerfData(); 518 xmlResult.addRow("Data",testname.getMethodName(), i, (end - start), 519 perf.get("vsz"), perf.get("rss"), perf.get("handles")); 520 } 521 522 } 523