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.sd;
27 
28 import static org.junit.Assert.assertEquals;
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.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.OpenOffice;
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 import testlib.gui.SCTool;
54 
55 public class BasicFuncOnImpress {
56 	@Rule
57 	public Logger log = Logger.getLogger(this);
58 
59 	@Rule
60 	public TestName testname = new TestName();
61 
62 	private static DataSheet xmlResult;
63 
64 	private String pid = null;
65 
66 	private static int iterator = 100;
67 
68 	private int i = 0;
69 
70 	/**
71 	 * @throws java.lang.Exception
72 	 */
73 	@BeforeClass
74 	public static void beforeClass() throws Exception {
75 
76 		xmlResult = new DataSheet(getFile("output/svt_gui_sd.xml"));
77 		xmlResult.addRow("BasicFunOnImpress","Method", "Iterator", "Consumed Time(MS)",
78 				"Memory(KB)", "CPU(%)");
79 	}
80 
81 	@AfterClass
82 	public static void afterClass() throws Exception {
83 		app.stop();
84 	}
85 
86 	@Before
87 	public void before() throws Exception{
88 		app.start(true);
89 	}
90 
91 	@Test
92 	public void saveNewSDWithNewSlides() throws Exception {
93 		for (i = 1; i <= iterator; i++) {
94 			long start = System.currentTimeMillis();
95 			createNewSD();
96 			impress.menuItem("Insert->Slide").select();
97 			sleep(2);
98 			saveAndReopenNewSD(i);
99 			long end = System.currentTimeMillis();
100 			addRecord(i, start, end);
101 		}
102 	}
103 
104 	@Test
105 	public void saveNewSDWithTable() throws Exception {
106 		for (i = 1; i <= iterator; i++) {
107 			long start = System.currentTimeMillis();
108 			createNewSD();
109 			app.dispatch(".uno:InsertTable", 3);
110 			sleep(2);
111 			numberofCol.setText("5");
112 			numberofRow.setText("4");
113 			sleep(2);
114 			insertTable.ok();
115 			impress.typeKeys("<enter>");
116 			impress.typeKeys("2");
117 			impress.typeKeys("<right>");
118 			impress.typeKeys("2");
119 			impress.typeKeys("<right>");
120 			impress.typeKeys("<ctrl end>");
121 			impress.typeKeys("2");
122 			sleep(2);
123 			saveAndReopenNewSD(i);
124 			long end = System.currentTimeMillis();
125 			addRecord(i, start, end);
126 		}
127 	}
128 
129 	@Test
130 	public void saveNewSDWithPic() throws Exception {
131 		String pic = prepareData("image/blue_256x256.jpg");
132 		for (i = 1; i <= iterator; i++) {
133 			long start = System.currentTimeMillis();
134 			createNewSD();
135 			impress.menuItem("Insert->Picture->From File...").select();
136 			sleep(2);
137 			filePickerPath.setText(pic);
138 			sleep(1);
139 			filePickerOpen.click();
140 			sleep(5);
141 			impress.typeKeys("<esc>");
142 			sleep(2);
143 			saveAndReopenNewSD(i);
144 			long end = System.currentTimeMillis();
145 			addRecord(i, start, end);
146 		}
147 	}
148 
149 	@Test
150 	public void saveNewSDWithTextbox()throws Exception{
151 		if(!sdDrawingToolbar.exists()){
152 			app.dispatch(".uno:AvailableToolbars?Toolbar:string=toolbar");
153 		}
154 		for (i = 1; i <= iterator; i++) {
155 			long start = System.currentTimeMillis();
156 			createNewSD();
157 			sdInsertTextboxButtonOnToolbar.click();
158 			impress.focus();
159 			impress.drag(100, 100, 200, 200);
160 			typeKeys("test");
161 			typeKeys("<esc>");
162 			sleep(2);
163 			saveAndReopenNewSD(i);
164 			long end = System.currentTimeMillis();
165 			addRecord(i, start, end);
166 		}
167 	}
168 
169 	@Test
170 	public void saveNewSDWithExternalSlides() throws Exception {
171 		String externalFile = prepareData("pvt/plain_200p.odp");
172 		for (i = 1; i <= iterator; i++) {
173 			long start = System.currentTimeMillis();
174 			createNewSD();
175 			app.dispatch(".uno:ImportFromFile");
176 			sleep(2);
177 			filePickerPath.setText(externalFile);
178 			filePickerOpen.click();
179 			sleep(2);
180 			insertSlideObjects.ok();
181 			sleep(5);
182 			saveAndReopenNewSD(i);
183 			long end = System.currentTimeMillis();
184 			addRecord(i, start, end);
185 		}
186 	}
187 
188 	@Test
189 	public void saveNewSDWithAnimation()throws Exception{
190 		for (i = 1; i <= iterator; i++) {
191 			long start = System.currentTimeMillis();
192 			createNewSD();
193 			//Insert a Shape and select it via Navigator
194 			sdCalloutShapes.click();
195 			impress.focus();
196 			impress.drag(100, 100, 200, 200);
197 			app.dispatch(".uno:CustomAnimation");
198 			sdAddAnimation.click();
199 			sdEntranceAnimationTab.waitForExistence(60, 2);
200 			sdEntranceAnimationTab.select("Circle");
201 			typeKeys("<enter>");
202 			sdAnimationList.openContextMenu();
203 			typeKeys("<down><down><enter>");
204 			impress.menuItem("Slide Show->Slide Show").select();
205 			sleep(10);
206 			impress.typeKeys("<esc>");
207 			sleep(5);
208 			saveAndReopenNewSD(i);
209 			long end = System.currentTimeMillis();
210 			addRecord(i, start, end);
211 		}
212 	}
213 
214 	@Test
215 	public void saveNewSDWithShowSettings() throws Exception {
216 		String externalFile = prepareData("pvt/plain_200p.odp");
217 		for (i = 1; i <= iterator; i++) {
218 			long start = System.currentTimeMillis();
219 			createNewSD();
220 			// Insert Slides from External Sample files
221 			impress.menuItem("Insert->File...").select();
222 			sleep(2);
223 			filePickerPath.setText(externalFile);
224 			filePickerOpen.click();
225 			sleep(2);
226 			insertSlideObjects.ok();
227 			sleep(20);
228 
229 			// Slide Screen Show Settings
230 			impress.menuItem("Slide Show->Slide Transition...").select();
231 			sleep(2);
232 			impressSlideTransitions.select("Uncover Up");
233 			sleep(2);
234 			slideShowSpeed.select("Slow");
235 			sleep(5);
236 			slideAutoAfter.check();
237 			sleep(2);
238 			applyToAllSlides.click();
239 			sleep(2);
240 			impress.menuItem("Slide Show->Slide Show").select();
241 			sleep(70);
242 			impress.typeKeys("<esc>");
243 			sleep(5);
244 			saveAndReopenNewSD(i);
245 			long end = System.currentTimeMillis();
246 			addRecord(i, start, end);
247 		}
248 	}
249 
250 	@Test
251 	public void saveSDTemplate()throws Exception{
252 		String templateFile = prepareData("svt/DarkBlue.otp");
253 		for (i = 1; i <= iterator; i++) {
254 			long start = System.currentTimeMillis();
255 			app.dispatch(".uno:Open");
256 			submitOpenDlg(templateFile);
257 			impress.waitForExistence(10, 2);
258 			sleep(5);
259 			saveAndReopenNewSD(i);
260 			long end = System.currentTimeMillis();
261 			addRecord(i, start, end);
262 		}
263 	}
264 
265 	@Test
266 	public void opChartOnOpenedSD() throws Exception {
267 		String file = prepareData("svt/OLEinODP.odp");
268 		for (i = 1; i <= iterator; i++) {
269 			long start = System.currentTimeMillis();
270 			app.dispatch(".uno:Open");
271 			submitOpenDlg(file);
272 			impress.waitForExistence(10, 2);
273 			sleep(5);
274 			if (!sdNavigatorDlg.exists()) {
275 				app.dispatch(".uno:Navigator");
276 			}
277 			impress.focus();
278 			sdNavigator.focus();
279 			sdNavigator.collapseAll();
280 			sdNavigator.expand(0);
281 			sdNavigator.select(1);
282 			typeKeys("<enter>");
283 			impress.menuItem("Edit->Copy").select();
284 			sleep(2);
285 			impress.menuItem("Edit->Paste").select();
286 			sleep(2);
287 
288 			sdNavigator.focus();
289 			sdNavigator.collapseAll();
290 			sdNavigator.expand(0);
291 			sdNavigator.select(2);
292 			typeKeys("<enter>");
293 			impress.menuItem("Edit->Copy").select();
294 			sleep(2);
295 			impress.menuItem("Edit->Paste").select();
296 			sleep(2);
297 
298 			sdNavigator.focus();
299 			sdNavigator.collapseAll();
300 			sdNavigator.expand(0);
301 			sdNavigator.select(3);
302 			typeKeys("<enter>");
303 			impress.menuItem("Edit->Copy").select();
304 			sleep(2);
305 			impress.menuItem("Edit->Paste").select();
306 			sleep(2);
307 			closeWithoutSaveSD();
308 			long end = System.currentTimeMillis();
309 			addRecord(i, start, end);
310 		}
311 	}
312 
313 	@Test
314 	public void switchViewOfOpenedSD() throws Exception {
315 		String file = prepareData("pvt/plain_200p.odp");
316 		for (i = 1; i <= iterator; i++) {
317 			long start = System.currentTimeMillis();
318 			app.dispatch(".uno:Open");
319 			submitOpenDlg(file);
320 			impress.waitForExistence(10, 2);
321 			sleep(5);
322 
323 			impress.menuItem("View->Outline").select();
324 			sleep(2);
325 			impressOutline.menuItem("View->Slide Sorter").select();
326 			sleep(10);
327 			impressSlideSorter.menuItem("View->Notes Page").select();
328 			sleep(2);
329 			impressHandoutView.menuItem("View->Master->Slide Master").select();
330 			sleep(2);
331 			impress.menuItem("View->Master->Notes Master").select();
332 			sleep(2);
333 
334 			impressHandoutView.menuItem("View->Normal").select();
335 			sleep(2);
336 			closeWithoutSaveSD();
337 			long end = System.currentTimeMillis();
338 			addRecord(i, start, end);
339 		}
340 	}
341 
342 	private void createNewSD() {
343 		app.dispatch("private:factory/simpress?slot=6686");
344 		presentationWizard.ok();
345 	}
346 
347 	private void saveAndReopenNewSD(int iterator) {
348 		String saveTo = getPath("temp/" + "tempSD_New" + iterator + ".odp");
349 		impress.menuItem("File->Save As...").select();
350 		FileUtil.deleteFile(saveTo);
351 		submitSaveDlg(saveTo);
352 		if (activeMsgBox.exists()) {
353 			activeMsgBox.yes();
354 			sleep(2);
355 		}
356 		sleep(5);
357 		app.dispatch(".uno:CloseDoc");
358 		startCenterOpenButton.waitForExistence(30, 2);
359 		startCenterOpenButton.click();
360 		submitOpenDlg(saveTo);
361 		sleep(2);
362 		app.dispatch(".uno:CloseDoc");
363 	}
364 
365 	private void closeWithoutSaveSD() {
366 		impress.menuItem("File->Close").select();
367 		if (activeMsgBox.exists()) {
368 			activeMsgBox.no();
369 			sleep(2);
370 		}
371 	}
372 
373 	private HashMap<String, Object> getPerfData() {
374 		HashMap<String, Object> proccessInfo = SystemUtil
375 				.findProcess(".*(soffice\\.bin|soffice\\.exe|soffice).*");
376 		String pid = (String) proccessInfo.get("pid");
377 		return SystemUtil.getProcessPerfData(pid);
378 	}
379 
380 	private void addRecord(int i, long start, long end) {
381 		HashMap<String, Object> perf = getPerfData();
382 		xmlResult.addRow("BasicFuncOnImpress",testname.getMethodName(), i, (end - start),
383 				perf.get("rss"), perf.get("pcpu"));
384 	}
385 }
386