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 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.OpenOffice;
48 import org.openoffice.test.common.DataSheet;
49 import org.openoffice.test.common.FileUtil;
50 import org.openoffice.test.common.Logger;
51 import org.openoffice.test.common.SystemUtil;
52 import org.openoffice.test.common.Testspace;
53 
54 import testlib.gui.SCTool;
55 
56 public class BasicFuncOnImpress {
57 	@Rule
58 	public Logger log = Logger.getLogger(this);
59 
60 	@Rule
61 	public TestName testname = new TestName();
62 
63 	private static DataSheet xmlResult;
64 
65 	private String pid = null;
66 
67 	private static int iterator = 100;
68 
69 	private int i = 0;
70 
71 	/**
72 	 * @throws java.lang.Exception
73 	 */
74 	@BeforeClass
beforeClass()75 	public static void beforeClass() throws Exception {
76 		xmlResult = new DataSheet(getFile("output/svt_impress.xml"));
77 		xmlResult.addRow("Data", "Method", "No", "Consumed Time(MS)", "Memory(VSZ)", "Memory(RSS)", "Handles(Windows Only)");
78 	}
79 
80 	@AfterClass
afterClass()81 	public static void afterClass() throws Exception {
82 		app.stop();
83 	}
84 
85 	@Before
before()86 	public void before() throws Exception{
87 		app.start(true);
88 	}
89 
90 	@Test
saveNewSDWithNewSlides()91 	public void saveNewSDWithNewSlides() throws Exception {
92 		for (i = 1; i <= iterator; i++) {
93 			long start = System.currentTimeMillis();
94 			createNewSD();
95 			impress.menuItem("Insert->Slide").select();
96 			sleep(2);
97 			saveAndReopenNewSD(i);
98 			long end = System.currentTimeMillis();
99 			addRecord(i, start, end);
100 		}
101 	}
102 
103 	@Test
saveNewSDWithTable()104 	public void saveNewSDWithTable() throws Exception {
105 		for (i = 1; i <= iterator; i++) {
106 			long start = System.currentTimeMillis();
107 			createNewSD();
108 			app.dispatch(".uno:InsertTable", 3);
109 			sleep(2);
110 			numberofCol.setText("5");
111 			numberofRow.setText("4");
112 			sleep(2);
113 			insertTable.ok();
114 			impress.typeKeys("<enter>");
115 			impress.typeKeys("2");
116 			impress.typeKeys("<right>");
117 			impress.typeKeys("2");
118 			impress.typeKeys("<right>");
119 			impress.typeKeys("<ctrl end>");
120 			impress.typeKeys("2");
121 			sleep(2);
122 			saveAndReopenNewSD(i);
123 			long end = System.currentTimeMillis();
124 			addRecord(i, start, end);
125 		}
126 	}
127 
128 	@Test
saveNewSDWithPic()129 	public void saveNewSDWithPic() throws Exception {
130 		String pic = prepareData("image/blue_256x256.jpg");
131 		for (i = 1; i <= iterator; i++) {
132 			long start = System.currentTimeMillis();
133 			createNewSD();
134 			app.dispatch(".uno:InsertGraphic");
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
saveNewSDWithTextbox()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
saveNewSDWithExternalSlides()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
saveNewSDWithAnimation()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
saveNewSDWithShowSettings()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
saveSDTemplate()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 	@Ignore
opChartOnOpenedSD()267 	public void opChartOnOpenedSD() throws Exception {
268 		String file = prepareData("svt/OLEinODP.odp");
269 		for (i = 1; i <= iterator; i++) {
270 			long start = System.currentTimeMillis();
271 			app.dispatch(".uno:Open");
272 			submitOpenDlg(file);
273 			impress.waitForExistence(10, 2);
274 			sleep(5);
275 			if (!sdNavigatorDlg.exists()) {
276 				app.dispatch(".uno:Navigator");
277 			}
278 			impress.focus();
279 			sdNavigator.focus();
280 			sdNavigator.collapseAll();
281 			sdNavigator.expand(0);
282 			sdNavigator.select(1);
283 			typeKeys("<enter>");
284 			impress.menuItem("Edit->Copy").select();
285 			sleep(2);
286 			impress.menuItem("Edit->Paste").select();
287 			sleep(2);
288 
289 			sdNavigator.focus();
290 			sdNavigator.collapseAll();
291 			sdNavigator.expand(0);
292 			sdNavigator.select(2);
293 			typeKeys("<enter>");
294 			impress.menuItem("Edit->Copy").select();
295 			sleep(2);
296 			impress.menuItem("Edit->Paste").select();
297 			sleep(2);
298 
299 			sdNavigator.focus();
300 			sdNavigator.collapseAll();
301 			sdNavigator.expand(0);
302 			sdNavigator.select(3);
303 			typeKeys("<enter>");
304 			impress.menuItem("Edit->Copy").select();
305 			sleep(2);
306 			impress.menuItem("Edit->Paste").select();
307 			sleep(2);
308 			closeWithoutSaveSD();
309 			long end = System.currentTimeMillis();
310 			addRecord(i, start, end);
311 		}
312 	}
313 
314 	@Test
switchViewOfOpenedSD()315 	public void switchViewOfOpenedSD() throws Exception {
316 		String file = prepareData("pvt/plain_200p.odp");
317 		for (i = 1; i <= iterator; i++) {
318 			long start = System.currentTimeMillis();
319 			app.dispatch(".uno:Open");
320 			submitOpenDlg(file);
321 			impress.waitForExistence(10, 2);
322 			sleep(5);
323 
324 			impress.menuItem("View->Outline").select();
325 			sleep(2);
326 			impressOutline.menuItem("View->Slide Sorter").select();
327 			sleep(10);
328 			impressSlideSorter.menuItem("View->Notes Page").select();
329 			sleep(2);
330 			impressHandoutView.menuItem("View->Master->Slide Master").select();
331 			sleep(2);
332 			impress.menuItem("View->Master->Notes Master").select();
333 			sleep(2);
334 
335 			impressHandoutView.menuItem("View->Normal").select();
336 			sleep(2);
337 			closeWithoutSaveSD();
338 			long end = System.currentTimeMillis();
339 			addRecord(i, start, end);
340 		}
341 	}
342 
createNewSD()343 	private void createNewSD() {
344 		app.dispatch("private:factory/simpress?slot=6686");
345 		presentationWizard.ok();
346 	}
347 
saveAndReopenNewSD(int iterator)348 	private void saveAndReopenNewSD(int iterator) {
349 		String saveTo = getPath("temp/" + "tempSD_New" + iterator + ".odp");
350 		impress.menuItem("File->Save As...").select();
351 		FileUtil.deleteFile(saveTo);
352 		submitSaveDlg(saveTo);
353 		if (activeMsgBox.exists()) {
354 			activeMsgBox.yes();
355 			sleep(2);
356 		}
357 		sleep(5);
358 		app.dispatch(".uno:CloseDoc");
359 		startCenterOpenButton.waitForExistence(30, 2);
360 		startCenterOpenButton.click();
361 		submitOpenDlg(saveTo);
362 		sleep(2);
363 		app.dispatch(".uno:CloseDoc");
364 	}
365 
closeWithoutSaveSD()366 	private void closeWithoutSaveSD() {
367 		impress.menuItem("File->Close").select();
368 		if (activeMsgBox.exists()) {
369 			activeMsgBox.no();
370 			sleep(2);
371 		}
372 	}
373 
addRecord(int i, long start, long end)374 	private void addRecord(int i, long start, long end) {
375 		HashMap<String, Object>  perf = aoo.getPerfData();
376 		xmlResult.addRow("Data",testname.getMethodName(), i, (end - start),
377 				perf.get("vsz"), perf.get("rss"), perf.get("handles"));
378 		log.log( Level.INFO, "\t"+testname.getMethodName()+"["+i+"] took "+(end-start)+"ms");
379 	}
380 }
381