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 		xmlResult = new DataSheet(getFile("output/svt.xml"));
76 		xmlResult.addRow("Data", "Method", "No", "Consumed Time(MS)", "Memory(VSZ)", "Memory(RSS)", "Handles(Windows Only)");
77 	}
78 
79 	@AfterClass
80 	public static void afterClass() throws Exception {
81 		app.stop();
82 	}
83 
84 	@Before
85 	public void before() throws Exception{
86 		app.start(true);
87 	}
88 
89 	@Test
90 	public void saveNewSDWithNewSlides() throws Exception {
91 		for (i = 1; i <= iterator; i++) {
92 			long start = System.currentTimeMillis();
93 			createNewSD();
94 			impress.menuItem("Insert->Slide").select();
95 			sleep(2);
96 			saveAndReopenNewSD(i);
97 			long end = System.currentTimeMillis();
98 			addRecord(i, start, end);
99 		}
100 	}
101 
102 	@Test
103 	public void saveNewSDWithTable() throws Exception {
104 		for (i = 1; i <= iterator; i++) {
105 			long start = System.currentTimeMillis();
106 			createNewSD();
107 			app.dispatch(".uno:InsertTable", 3);
108 			sleep(2);
109 			numberofCol.setText("5");
110 			numberofRow.setText("4");
111 			sleep(2);
112 			insertTable.ok();
113 			impress.typeKeys("<enter>");
114 			impress.typeKeys("2");
115 			impress.typeKeys("<right>");
116 			impress.typeKeys("2");
117 			impress.typeKeys("<right>");
118 			impress.typeKeys("<ctrl end>");
119 			impress.typeKeys("2");
120 			sleep(2);
121 			saveAndReopenNewSD(i);
122 			long end = System.currentTimeMillis();
123 			addRecord(i, start, end);
124 		}
125 	}
126 
127 	@Test
128 	public void saveNewSDWithPic() throws Exception {
129 		String pic = prepareData("image/blue_256x256.jpg");
130 		for (i = 1; i <= iterator; i++) {
131 			long start = System.currentTimeMillis();
132 			createNewSD();
133 			app.dispatch(".uno:InsertGraphic");
134 //			impress.menuItem("Insert->Picture->From File...").select();
135 			sleep(2);
136 			filePickerPath.setText(pic);
137 			sleep(1);
138 			filePickerOpen.click();
139 			sleep(5);
140 			impress.typeKeys("<esc>");
141 			sleep(2);
142 			saveAndReopenNewSD(i);
143 			long end = System.currentTimeMillis();
144 			addRecord(i, start, end);
145 		}
146 	}
147 
148 	@Test
149 	public void saveNewSDWithTextbox()throws Exception{
150 		if(!sdDrawingToolbar.exists()){
151 			app.dispatch(".uno:AvailableToolbars?Toolbar:string=toolbar");
152 		}
153 		for (i = 1; i <= iterator; i++) {
154 			long start = System.currentTimeMillis();
155 			createNewSD();
156 			sdInsertTextboxButtonOnToolbar.click();
157 			impress.focus();
158 			impress.drag(100, 100, 200, 200);
159 			typeKeys("test");
160 			typeKeys("<esc>");
161 			sleep(2);
162 			saveAndReopenNewSD(i);
163 			long end = System.currentTimeMillis();
164 			addRecord(i, start, end);
165 		}
166 	}
167 
168 	@Test
169 	public void saveNewSDWithExternalSlides() throws Exception {
170 		String externalFile = prepareData("pvt/plain_200p.odp");
171 		for (i = 1; i <= iterator; i++) {
172 			long start = System.currentTimeMillis();
173 			createNewSD();
174 			app.dispatch(".uno:ImportFromFile");
175 			sleep(2);
176 			filePickerPath.setText(externalFile);
177 			filePickerOpen.click();
178 			sleep(2);
179 			insertSlideObjects.ok();
180 			sleep(5);
181 			saveAndReopenNewSD(i);
182 			long end = System.currentTimeMillis();
183 			addRecord(i, start, end);
184 		}
185 	}
186 
187 	@Test
188 	public void saveNewSDWithAnimation()throws Exception{
189 		for (i = 1; i <= iterator; i++) {
190 			long start = System.currentTimeMillis();
191 			createNewSD();
192 			//Insert a Shape and select it via Navigator
193 			sdCalloutShapes.click();
194 			impress.focus();
195 			impress.drag(100, 100, 200, 200);
196 			app.dispatch(".uno:CustomAnimation");
197 			sdAddAnimation.click();
198 			sdEntranceAnimationTab.waitForExistence(60, 2);
199 			sdEntranceAnimationTab.select("Circle");
200 			typeKeys("<enter>");
201 			sdAnimationList.openContextMenu();
202 			typeKeys("<down><down><enter>");
203 			impress.menuItem("Slide Show->Slide Show").select();
204 			sleep(10);
205 			impress.typeKeys("<esc>");
206 			sleep(5);
207 			saveAndReopenNewSD(i);
208 			long end = System.currentTimeMillis();
209 			addRecord(i, start, end);
210 		}
211 	}
212 
213 	@Test
214 	public void saveNewSDWithShowSettings() throws Exception {
215 		String externalFile = prepareData("pvt/plain_200p.odp");
216 		for (i = 1; i <= iterator; i++) {
217 			long start = System.currentTimeMillis();
218 			createNewSD();
219 			// Insert Slides from External Sample files
220 			impress.menuItem("Insert->File...").select();
221 			sleep(2);
222 			filePickerPath.setText(externalFile);
223 			filePickerOpen.click();
224 			sleep(2);
225 			insertSlideObjects.ok();
226 			sleep(20);
227 
228 			// Slide Screen Show Settings
229 			impress.menuItem("Slide Show->Slide Transition...").select();
230 			sleep(2);
231 			impressSlideTransitions.select("Uncover Up");
232 			sleep(2);
233 			slideShowSpeed.select("Slow");
234 			sleep(5);
235 			slideAutoAfter.check();
236 			sleep(2);
237 			applyToAllSlides.click();
238 			sleep(2);
239 			impress.menuItem("Slide Show->Slide Show").select();
240 			sleep(70);
241 			impress.typeKeys("<esc>");
242 			sleep(5);
243 			saveAndReopenNewSD(i);
244 			long end = System.currentTimeMillis();
245 			addRecord(i, start, end);
246 		}
247 	}
248 
249 	@Test
250 	public void saveSDTemplate()throws Exception{
251 		String templateFile = prepareData("svt/DarkBlue.otp");
252 		for (i = 1; i <= iterator; i++) {
253 			long start = System.currentTimeMillis();
254 			app.dispatch(".uno:Open");
255 			submitOpenDlg(templateFile);
256 			impress.waitForExistence(10, 2);
257 			sleep(5);
258 			saveAndReopenNewSD(i);
259 			long end = System.currentTimeMillis();
260 			addRecord(i, start, end);
261 		}
262 	}
263 
264 	@Test
265 	@Ignore
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 void addRecord(int i, long start, long end) {
374 		HashMap<String, Object>  perf = aoo.getPerfData();
375 		xmlResult.addRow("Data",testname.getMethodName(), i, (end - start),
376 				perf.get("vsz"), perf.get("rss"), perf.get("handles"));
377 	}
378 }
379