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