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 svt.gui.sc;
27 
28 import static org.openoffice.test.common.Testspace.getFile;
29 import static org.openoffice.test.common.Testspace.getPath;
30 import static org.openoffice.test.common.Testspace.prepareData;
31 import static org.openoffice.test.vcl.Tester.sleep;
32 import static testlib.gui.AppTool.submitOpenDlg;
33 import static testlib.gui.AppTool.submitSaveDlg;
34 import static testlib.gui.AppTool.typeKeys;
35 import static testlib.gui.UIMap.activeMsgBox;
36 import static testlib.gui.UIMap.aoo;
37 import static testlib.gui.UIMap.app;
38 import static testlib.gui.UIMap.calc;
39 import static testlib.gui.UIMap.chartWizard;
40 import static testlib.gui.UIMap.filePickerOpen;
41 import static testlib.gui.UIMap.filePickerPath;
42 import static testlib.gui.UIMap.filterValue1;
43 import static testlib.gui.UIMap.fontworkGalleryDlg;
44 import static testlib.gui.UIMap.scAfterCurrentSheet;
45 import static testlib.gui.UIMap.scFormatCode;
46 import static testlib.gui.UIMap.scInsertSheetDlg;
47 import static testlib.gui.UIMap.scNewSheetName;
48 import static testlib.gui.UIMap.scPrintArea;
49 import static testlib.gui.UIMap.scPrintAreaType;
50 import static testlib.gui.UIMap.scValidityCriteriaAllowList;
51 import static testlib.gui.UIMap.scValidityCriteriaTabpage;
52 import static testlib.gui.UIMap.scValidityDecimalCompareOperator;
53 import static testlib.gui.UIMap.scValidityErrorAlertTabPage;
54 import static testlib.gui.UIMap.scValidityErrorMessage;
55 import static testlib.gui.UIMap.scValidityErrorMessageTitle;
56 import static testlib.gui.UIMap.scValidityShowErrorMessage;
57 import static testlib.gui.UIMap.scValiditySourceInput;
58 import static testlib.gui.UIMap.sortOptionsPage;
59 import static testlib.gui.UIMap.sortOptionsPageRangeContainsColumnLabels;
60 import static testlib.gui.UIMap.sortPage;
61 import static testlib.gui.UIMap.sortPageAscending1;
62 import static testlib.gui.UIMap.sortPageBy1;
63 import static testlib.gui.UIMap.standardFilterDlg;
64 import static testlib.gui.UIMap.startCenterOpenButton;
65 
66 import java.util.HashMap;
67 import java.util.logging.Level;
68 
69 import org.junit.AfterClass;
70 import org.junit.Before;
71 import org.junit.BeforeClass;
72 import org.junit.Rule;
73 import org.junit.Test;
74 import org.junit.rules.TestName;
75 import org.openoffice.test.common.DataSheet;
76 import org.openoffice.test.common.FileUtil;
77 import org.openoffice.test.common.Logger;
78 
79 import testlib.gui.SCTool;
80 
81 public class BasicFuncOnCalc {
82 	@Rule
83 	public Logger log = Logger.getLogger(this);
84 
85 	@Rule
86 	public TestName testname = new TestName();
87 
88 	private static DataSheet xmlResult;
89 
90 	private static int iterator = 100;
91 
92 	private int i = 0;
93 
94 	/**
95 	 * @throws java.lang.Exception
96 	 */
97 	@BeforeClass
beforeClass()98 	public static void beforeClass() throws Exception {
99 		xmlResult = new DataSheet(getFile("output/svt_calc.xml"));
100 		xmlResult.addRow("Data", "Method", "No", "Consumed Time(MS)", "Memory(VSZ)", "Memory(RSS)", "Handles(Windows Only)");
101 	}
102 
103 	@AfterClass
afterClass()104 	public static void afterClass() throws Exception {
105 		app.stop();
106 	}
107 
108 	@Before
before()109 	public void before()throws Exception{
110 		app.start(true);
111 	}
112 
113 
114 	@Test
saveNewSCWithNumberFormat()115 	public void saveNewSCWithNumberFormat() {
116 		for (i = 1; i <= iterator; i++) {
117 			long start = System.currentTimeMillis();
118 			createNewSC();
119 			SCTool.selectRange("A1");
120 			typeKeys("0.3");
121 			sleep(1);
122 			app.dispatch(".uno:FormatCellDialog");
123 			sleep(2);
124 			scFormatCode.setText("0%");
125 			typeKeys("<enter>");
126 			sleep(1);
127 			saveAndReopenNewSC(i);
128 			long end = System.currentTimeMillis();
129 			addRecord(i, start, end);
130 		}
131 	}
132 
133 	@Test
saveNewSCWithPrintRange()134 	public void saveNewSCWithPrintRange() throws Exception {
135 		for (i = 1; i <= iterator; i++) {
136 			long start = System.currentTimeMillis();
137 			createNewSC();
138 			app.dispatch(".uno:EditPrintArea");
139 			sleep(1);
140 			scPrintAreaType.select("- user defined -");
141 			scPrintArea.setText("$A$1:$C$4");
142 			typeKeys("<enter>");
143 			SCTool.selectRange("A1");
144 			typeKeys("test");
145 			saveAndReopenNewSC(i);
146 			long end = System.currentTimeMillis();
147 			addRecord(i, start, end);
148 		}
149 	}
150 
151 	@Test
saveNewSCWithText()152 	public void saveNewSCWithText() throws Exception {
153 		for (i = 1; i <= iterator; i++) {
154 			long start = System.currentTimeMillis();
155 			createNewSC();
156 			SCTool.selectRange("A1");
157 			typeKeys("test");
158 			saveAndReopenNewSC(i);
159 			long end = System.currentTimeMillis();
160 			addRecord(i, start, end);
161 		}
162 	}
163 
164 	@Test
saveNewSCWithDataSort()165 	public void saveNewSCWithDataSort() throws Exception {
166 		for (i = 1; i <= iterator; i++) {
167 			long start = System.currentTimeMillis();
168 			createNewSC();
169 			SCTool.selectRange("A1");
170 			typeKeys("3<down>2<down>5<down>1<down>6<down>4<down>10<down>8<down>9<down>7");
171 			sleep(1);
172 			app.dispatch(".uno:DataSort");
173 			sortOptionsPage.select();
174 			sortOptionsPageRangeContainsColumnLabels.uncheck();
175 			sortPage.select();
176 			sortPageBy1.select(1); // "Column A"
177 			sortPageAscending1.check();
178 			sortPage.ok();
179 			saveAndReopenNewSC(i);
180 			long end = System.currentTimeMillis();
181 			addRecord(i, start, end);
182 		}
183 	}
184 
185 	@Test
saveNewSCWithInsertSheets()186 	public void saveNewSCWithInsertSheets() throws Exception {
187 		for (i = 1; i <= iterator; i++) {
188 			long start = System.currentTimeMillis();
189 			createNewSC();
190 			app.dispatch(".uno:Insert");
191 			scAfterCurrentSheet.check();
192 			scNewSheetName.setText("Instant Filter");
193 			scInsertSheetDlg.ok();
194 			sleep(5);
195 			saveAndReopenNewSC(i);
196 			long end = System.currentTimeMillis();
197 			addRecord(i, start, end);
198 		}
199 	}
200 
201 	@Test
saveNewSCWithStandardFilter()202 	public void saveNewSCWithStandardFilter() throws Exception {
203 		for (i = 1; i <= iterator; i++) {
204 			long start = System.currentTimeMillis();
205 			createNewSC();
206 			SCTool.selectRange("A1");
207 			typeKeys("A<down>1<down>2<down>3<down>1<down>2<down>3<down>1<down>2<down>3");
208 			sleep(1);
209 			SCTool.selectRange("A1");
210 			app.dispatch(".uno:DataFilterStandardFilter");
211 			sleep(2);
212 			filterValue1.setText("1");
213 			standardFilterDlg.ok();
214 			saveAndReopenNewSC(i);
215 			long end = System.currentTimeMillis();
216 			addRecord(i, start, end);
217 		}
218 	}
219 
220 	@Test
saveNewSCWithInsertPic()221 	public void saveNewSCWithInsertPic() throws Exception {
222 		String pic = prepareData("image/blue_256x256.jpg");
223 		for (i = 1; i <= iterator; i++) {
224 			long start = System.currentTimeMillis();
225 			createNewSC();
226 			calc.menuItem("Insert->Picture->From File...").select();
227 			sleep(2);
228 			filePickerPath.setText(pic);
229 			sleep(1);
230 			filePickerOpen.click();
231 			sleep(2);
232 			typeKeys("<esc>");
233 			sleep(2);
234 			saveAndReopenNewSC(i);
235 			long end = System.currentTimeMillis();
236 			addRecord(i, start, end);
237 		}
238 	}
239 
240 	@Test
saveNewSCWithValidaty()241 	public void saveNewSCWithValidaty() throws Exception {
242 		for (i = 1; i <= iterator; i++) {
243 			long start = System.currentTimeMillis();
244 			createNewSC();
245 			app.dispatch(".uno:Insert");
246 			scAfterCurrentSheet.check();
247 			scNewSheetName.setText("Data Validate");
248 			scInsertSheetDlg.ok();
249 			sleep(5);
250 			SCTool.selectRange("B2:E5");
251 			sleep(2);
252 
253 			app.dispatch(".uno:Validation");
254 			scValidityCriteriaTabpage.select();
255 			scValidityCriteriaAllowList.select("Whole Numbers");
256 			scValidityDecimalCompareOperator.select("greater than");
257 			scValiditySourceInput.setText("1");
258 			scValidityErrorAlertTabPage.select();
259 			scValidityShowErrorMessage.check();
260 			scValidityErrorMessageTitle.setText("Error");
261 			scValidityErrorMessage.setText("Must greater than 1");
262 			scValidityErrorAlertTabPage.ok();
263 
264 			SCTool.selectRange("B2");
265 			typeKeys("0<enter>");
266 			activeMsgBox.ok();
267 			sleep(1);
268 
269 			SCTool.selectRange("E5");
270 			typeKeys("1<enter>");
271 			activeMsgBox.ok();
272 			sleep(1);
273 
274 			SCTool.selectRange("E2");
275 			typeKeys("2<enter>");
276 			sleep(5);
277 			saveAndReopenNewSC(i);
278 			long end = System.currentTimeMillis();
279 			addRecord(i, start, end);
280 		}
281 	}
282 
283 	@Test
insertChartToOpenedSC()284 	public void insertChartToOpenedSC() throws Exception {
285 		String file = prepareData("pvt/plain_11s.ods");
286 		String[][] inputStr = { { "Area", "Item", "Count" }, { "1", "2", "3" },
287 				{ "4", "5", "6" }, { "7", "8", "9" }, { "10", "11", "12" } };
288 		for (i = 1; i <= iterator; i++) {
289 			long start = System.currentTimeMillis();
290 			app.dispatch(".uno:Open");
291 			submitOpenDlg(file);
292 			calc.waitForExistence(20, 2);
293 			sleep(2);
294 
295 			// Insert Chart
296 			app.dispatch(".uno:Insert");
297 			scAfterCurrentSheet.check();
298 			scNewSheetName.setText("Instant Chart");
299 			scInsertSheetDlg.ok();
300 			sleep(5);
301 			inputCells(inputStr);
302 			sleep(2);
303 			SCTool.selectRange("A1:C5");
304 			calc.menuItem("Insert->Chart...").select();
305 			sleep(1);
306 			chartWizard.ok();
307 			sleep(5);
308 			calc.typeKeys("<esc>");
309 			sleep(5);
310 			calc.typeKeys("<esc>");
311 			sleep(5);
312 			calc.typeKeys("<esc>");
313 			sleep(5);
314 			closeWithoutSaveSC();
315 			long end = System.currentTimeMillis();
316 			addRecord(i, start, end);
317 		}
318 	}
319 
320 	@Test
insertPicToOpenedSC()321 	public void insertPicToOpenedSC() throws Exception {
322 		String file = prepareData("pvt/plain_11s.ods");
323 		String pic = prepareData("image/blue_256x256.jpg");
324 		for (i = 1; i <= iterator; i++) {
325 			long start = System.currentTimeMillis();
326 			app.dispatch(".uno:Open");
327 			submitOpenDlg(file);
328 			calc.waitForExistence(20, 2);
329 			sleep(2);
330 
331 			// Insert Chart
332 			app.dispatch(".uno:Insert");
333 			scAfterCurrentSheet.check();
334 			scNewSheetName.setText("Instant Graphic");
335 			scInsertSheetDlg.ok();
336 			sleep(5);
337 			calc.menuItem("Insert->Picture->From File...").select();
338 			sleep(2);
339 			filePickerPath.setText(pic);
340 			sleep(1);
341 			filePickerOpen.click();
342 			sleep(5);
343 			calc.typeKeys("<esc>");
344 			sleep(2);
345 			closeWithoutSaveSC();
346 			long end = System.currentTimeMillis();
347 			addRecord(i, start, end);
348 		}
349 	}
350 
351 	@Test
insertFontWorkToOpenedSC()352 	public void insertFontWorkToOpenedSC() throws Exception {
353 		String file = prepareData("pvt/plain_11s.ods");
354 		for (i = 1; i <= iterator; i++) {
355 			long start = System.currentTimeMillis();
356 			app.dispatch(".uno:Open");
357 			submitOpenDlg(file);
358 			calc.waitForExistence(20, 2);
359 			sleep(2);
360 
361 			calc.menuItem("View->Toolbars->Fontwork").select();
362 			sleep(2);
363 			app.dispatch(".uno:FontworkGalleryFloater");
364 			sleep(2);
365 			typeKeys("<right>");
366 			fontworkGalleryDlg.ok();
367 			sleep(2);
368 			calc.typeKeys("<esc>");
369 			sleep(2);
370 
371 			closeWithoutSaveSC();
372 			long end = System.currentTimeMillis();
373 			addRecord(i, start, end);
374 		}
375 	}
376 
377 	@Test
switchFileContainingChart()378 	public void switchFileContainingChart() throws Exception {
379 		String file1 = prepareData("svt/64K_Chart1.ods");
380 		String file2 = prepareData("svt/64K_Chart2.ods");
381 		String file3 = prepareData("svt/64K_Chart3.ods");
382 		String file4 = prepareData("svt/64K_Chart4.ods");
383 		String file5 = prepareData("svt/64K_Chart5.ods");
384 		String file6 = prepareData("svt/64K_Chart6.ods");
385 
386 		for (i = 1; i <= iterator; i++) {
387 			long start = System.currentTimeMillis();
388 			app.dispatch(".uno:Open");
389 			submitOpenDlg(file1);
390 			calc.waitForExistence(20, 2);
391 			sleep(2);
392 
393 			app.dispatch(".uno:Open");
394 			submitOpenDlg(file2);
395 			calc.waitForExistence(20, 2);
396 			sleep(2);
397 
398 			app.dispatch(".uno:Open");
399 			submitOpenDlg(file3);
400 			calc.waitForExistence(20, 2);
401 			sleep(2);
402 
403 			app.dispatch(".uno:Open");
404 			submitOpenDlg(file4);
405 			calc.waitForExistence(20, 2);
406 			sleep(2);
407 
408 			app.dispatch(".uno:Open");
409 			submitOpenDlg(file5);
410 			calc.waitForExistence(20, 2);
411 			sleep(2);
412 
413 			app.dispatch(".uno:Open");
414 			submitOpenDlg(file6);
415 			calc.waitForExistence(20, 2);
416 
417 			sleep(2);
418 
419 			selectCertainFile(2);
420 			sleep(2);
421 			selectCertainFile(3);
422 			sleep(2);
423 			selectCertainFile(5);
424 			sleep(2);
425 
426 			closeAlldocuments();
427 			sleep(3);
428 			long end = System.currentTimeMillis();
429 			addRecord(i, start, end);
430 		}
431 	}
432 
selectCertainFile(int k)433 	public void selectCertainFile(int k) {
434 		calc.menuItem("Window").select();
435 		k += 5;
436 		for (int i = 0; i < k; i++) {
437 			typeKeys("<down>");
438 		}
439 		typeKeys("<enter>");
440 		sleep(2);
441 	}
442 
closeAlldocuments()443 	public void closeAlldocuments() {
444 		for (int index = 3; index < 9; index++) {
445 			calc.menuItem("File->Close").select();
446 			sleep(2);
447 		}
448 
449 	}
450 
inputCells(String[][] inputs)451 	public static void inputCells(String[][] inputs) {
452 		String back = "";
453 		for (int i = 0; i < inputs.length; i++) {
454 			calc.typeKeys(back);
455 			sleep(1);
456 			back = "";
457 			for (int j = 0; j < inputs[i].length; j++) {
458 				typeKeys(inputs[i][j]);
459 				typeKeys("<Right>");
460 				sleep(0.5);
461 				back += "<Left>";
462 			}
463 			back += "<enter>";
464 		}
465 		sleep(2);
466 	}
467 
createNewSC()468 	private void createNewSC() {
469 		app.dispatch("private:factory/scalc");
470 	}
471 
saveAndReopenNewSC(int iterator)472 	private void saveAndReopenNewSC(int iterator) {
473 		String saveTo = getPath("temp/" + "tempSC_New" + iterator + ".ods");
474 		calc.menuItem("File->Save As...").select();
475 		FileUtil.deleteFile(saveTo);
476 		submitSaveDlg(saveTo);
477 		if (activeMsgBox.exists()) {
478 			activeMsgBox.yes();
479 			sleep(2);
480 		}
481 		app.dispatch(".uno:CloseDoc");
482 		// sleep(2);
483 		startCenterOpenButton.waitForExistence(30, 2);
484 		startCenterOpenButton.click();
485 		submitOpenDlg(saveTo);
486 		sleep(1);
487 		app.dispatch(".uno:CloseDoc");
488 	}
489 
closeWithoutSaveSC()490 	private void closeWithoutSaveSC() {
491 		calc.menuItem("File->Close").select();
492 		activeMsgBox.no();
493 		sleep(2);
494 	}
495 
addRecord(int i, long start, long end)496 	private void addRecord(int i, long start, long end) {
497 		HashMap<String, Object>  perf = aoo.getPerfData();
498 		xmlResult.addRow("Data",testname.getMethodName(), i, (end - start),
499 				perf.get("vsz"), perf.get("rss"), perf.get("handles"));
500 		log.log( Level.INFO, "\t"+testname.getMethodName()+"["+i+"] took "+(end-start)+"ms");
501 	}
502 }
503