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 bvt.gui;
26 
27 import static org.junit.Assert.*;
28 import static org.openoffice.test.common.Testspace.*;
29 import static org.openoffice.test.vcl.Tester.*;
30 import static testlib.gui.AppTool.*;
31 import static testlib.gui.UIMap.*;
32 
33 import java.awt.Rectangle;
34 import java.io.File;
35 
36 import org.junit.AfterClass;
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Rule;
40 import org.junit.Test;
41 import org.openoffice.test.common.FileUtil;
42 import org.openoffice.test.common.GraphicsUtil;
43 import org.openoffice.test.common.Logger;
44 
45 import testlib.gui.SCTool;
46 
47 /**
48  *
49  */
50 public class BasicFunctionTest {
51 
52 	@Rule
53 	public Logger log = Logger.getLogger(this);
54 
55 	@BeforeClass
56 	public static void beforeClass() {
57 		app.clean();
58 	}
59 
60 	@AfterClass
61 	public static void afterClass() {
62 		app.stop();
63 	}
64 
65 	@Before
66 	public void before() {
67 		app.stop();
68 		app.start();
69 	}
70 
71 
72 	@Test
73 	public void smokeTest() {
74 		File smoketestOutput = new File(aoo.getUserInstallation(), "user/temp");
75 		prepareData("TestExtension.oxt");
76 		// Open sample file smoketestdoc.sxw
77 		open(prepareData("smoketestdoc.sxw"));
78 		writer.waitForEnabled(10, 2);
79 		// Run test cases
80 		app.dispatch("vnd.sun.star.script:Standard.Global.StartTestWithDefaultOptions?language=Basic&location=document", 120);
81 		String smoketestlog = FileUtil.readFileAsString(new File(smoketestOutput, "smoketest.log"));
82 		String testclosurelog = FileUtil.readFileAsString(new File(smoketestOutput, "testclosure.log"));
83 		log.info(smoketestlog + "\n" + testclosurelog);
84 		assertTrue("No Error", !smoketestlog.contains("error") && !testclosurelog.contains("error"));
85 
86 	}
87 
88 	@Test
89 	public void testExportAsPDF() throws Exception {
90 		String file = prepareData("bvt/pdf.odt");
91 		String exportTo1 = getPath("temp/1.pdf");
92 		String exportTo2 = getPath("temp/2.pdf");
93 		deleteFile(exportTo1);
94 		deleteFile(exportTo2);
95 		open(file);
96 		writer.waitForExistence(10, 1);
97 		app.dispatch(".uno:ExportToPDF");
98 		pdfGeneralPage.ok();
99 		submitSaveDlg(exportTo1);
100 		sleep(1);
101 		String magic = FileUtil.readFileAsString(exportTo1).substring(0, 4);
102 		assertEquals("PDF is exported?", "%PDF", magic);
103 
104 		button(".uno:ExportDirectToPDF").click();//Click via toolbar
105 		submitSaveDlg(exportTo2);
106 		sleep(1);
107 		magic = FileUtil.readFileAsString(exportTo2).substring(0, 4);
108 		assertEquals("PDF is exported directly?", "%PDF", magic);
109 	}
110 
111 	/**
112 	 * Test the File -- Print Dialog show
113 	 *
114 	 */
115 	@Test
116 	public void testPrinter() {
117 		// Create a new text document
118 		newTextDocument();
119 		app.dispatch(".uno:PrinterSetup");
120 		if (activeMsgBox.exists(2))
121 			activeMsgBox.ok();
122 
123 //		PrintService[] ps = PrintServiceLookup.lookupPrintServices(null, null);
124 //		String[] names = new String[ps.length];
125 //		for (int i = 0; i < ps.length; i++) {
126 //			names[i] = ps[i].getName();
127 //		}
128 //
129 //		assertArrayEquals("Printers Names", names, printerSetUpDlgPrinterNames.getItemsText());
130 		assertTrue("Printer Setup dialog appears", printerSetUpDlg.exists(3));
131 		printerSetUpDlg.cancel();
132 	}
133 
134 	/**
135 	 * Test the File -- Java Dialog show
136 	 *
137 	 */
138 //	@Test
139 //	public void testJavaDialog() {
140 //
141 //		// Create a new text document and launch a Wizards dialog which need JVM
142 //		// work correctly.
143 //		app.dispatch("private:factory/swriter");
144 //		File tempfile = new File(oo.getUserInstallation(), "user/template/myAgendaTemplate.ott");
145 //		FileUtil.deleteFile(tempfile);
146 //		sleep(3);
147 //		app.dispatch("service:com.sun.star.wizards.agenda.CallWizard?start");
148 //		sleep(5);
149 //		assertTrue(Wizards_AgendaDialog.exists(10));
150 //		Wizards_AgendaDialog_FinishButton.click();
151 //		sleep(10);
152 //		writer.focus();
153 //		sleep(1);
154 //		app.dispatch(".uno:SelectAll");
155 //		typeKeys("<$copy>");
156 //		// System.out.println("now txt:"+app.getClipboard());
157 //		// assertTrue(app.getClipboard().startsWith("<Name>"));
158 //		assertNotNull(app.getClipboard());
159 //	}
160 
161 	/**
162 	 * Test the Tools / Macros / Organize Dialogs" show
163 	 *
164 	 */
165 	@Test
166 	public void testRunMacro() {
167 		open(prepareData("bvt/macro.ods"));
168 		calc.waitForExistence(10, 2);
169 		app.dispatch(".uno:RunMacro");
170 		runMacroDlgCategories.expand("macro.ods");
171 		runMacroDlgCategories.expand("Standard");
172 		runMacroDlgCategories.select("Module1");
173 		runMacroDlgCommands.select(0);
174 		runMacroDlg.ok();
175 		assertEquals("A3 should be =1+3", "4", SCTool.getCellText("A3"));
176 		discard();
177 	}
178 
179 	/**
180 	 * Test the About Dialog show
181 	 *
182 	 */
183 	@Test
184 	public void testHelp() {
185 		app.dispatch(".uno:About");
186 		assertTrue(aboutDialog.exists(5));
187 		aboutDialog.ok();
188 		sleep(1);
189 		typeKeys("<F1>");
190 		assertTrue(helpWindow.exists(5));
191 		helpWindow.close();
192 	}
193 
194 	/**
195 	 * Test inserting a picture in text document
196 	 *
197 	 * @throws Exception
198 	 */
199 
200 	@Test
201 	public void testInsertPictureInDocument() throws Exception {
202 		String bmp_green = prepareData("image/green_256x256.bmp");
203 		String bmp_red = prepareData("image/red_256x256.bmp");
204 
205 		// Create a new text document
206 		newTextDocument();
207 		// Insert a picture fully filled with green
208 		app.dispatch(".uno:InsertGraphic");
209 		submitOpenDlg(bmp_green);
210 		writer.click(5,200);
211 		sleep(1);
212 
213 		// Verify if the picture is inserted successfully
214 		Rectangle rectangle = GraphicsUtil.findRectangle(writer.getScreenRectangle(), 0xFF00FF00);
215 		assertTrue("Green Picture is inserted?" + rectangle, rectangle != null && rectangle.getWidth() > 10);
216 		// insert another picture
217 		app.dispatch(".uno:InsertGraphic");
218 		submitOpenDlg(bmp_red);
219 		writer.click(5, 200);
220 		sleep(1);
221 		// Verify if the picture is inserted successfully
222 		rectangle = GraphicsUtil.findRectangle(writer.getScreenRectangle(), 0xFFFF0000);
223 		assertTrue("Green Picture is inserted? " + rectangle, rectangle != null && rectangle.getWidth() > 10);
224 		discard();
225 	}
226 
227 	@Test
228 	public void testInsertPictureInSpreadsheet() throws Exception {
229 		String bmp_green = prepareData("image/green_64x64.png");
230 		String bmp_red = prepareData("image/red_64x64.png");
231 		newSpreadsheet();
232 		// Insert a picture fully filled with green
233 		app.dispatch(".uno:InsertGraphic");
234 		submitOpenDlg(bmp_green);
235 		calc.click(5, 150);
236 		sleep(1);
237 
238 		// Verify if the picture is inserted successfully
239 		Rectangle rectangle = GraphicsUtil.findRectangle(calc.getScreenRectangle(), 0xFF00FF00);
240 		assertTrue("Green Picture is inserted?" + rectangle, rectangle != null && rectangle.getWidth() > 10);
241 
242 		SCTool.selectRange("C1");
243 		// insert another picture
244 		app.dispatch(".uno:InsertGraphic");
245 		submitOpenDlg(bmp_red);
246 		calc.click(5, 150);
247 		sleep(1);
248 		// Verify if the picture is inserted successfully
249 		rectangle = GraphicsUtil.findRectangle(calc.getScreenRectangle(), 0xFFFF0000);
250 		assertTrue("Red Picture is inserted? " + rectangle, rectangle != null && rectangle.getWidth() > 10);
251 		discard();
252 	}
253 
254 	@Test
255 	public void testInsertPictureInPresentation() throws Exception {
256 		String bmp_green = prepareData("image/green_256x256.bmp");
257 		String bmp_red = prepareData("image/red_256x256.bmp");
258 		newPresentation();
259 		// Insert a picture fully filled with green
260 		app.dispatch(".uno:InsertGraphic");
261 		submitOpenDlg(bmp_green);
262 		impress.click(5, 5);
263 		sleep(1);
264 
265 		// Verify if the picture is inserted successfully
266 		Rectangle rectangle = GraphicsUtil.findRectangle(impress.getScreenRectangle(), 0xFF00FF00);
267 		assertTrue("Green Picture is inserted?" + rectangle, rectangle != null && rectangle.getWidth() > 10);
268 		// insert another picture
269 		app.dispatch(".uno:InsertGraphic");
270 		submitOpenDlg(bmp_red);
271 		impress.click(1, 1);
272 		sleep(1);
273 		// Verify if the picture is inserted successfully
274 		rectangle = GraphicsUtil.findRectangle(impress.getScreenRectangle(), 0xFFFF0000);
275 		assertTrue("Red Picture is inserted? " + rectangle, rectangle != null && rectangle.getWidth() > 10);
276 		discard();
277 	}
278 
279 	@Test
280 	public void testSlideShow() throws Exception {
281 		open(prepareData("bvt/slideshow.odp"));
282 		impress.waitForExistence(10, 2);
283 		sleep(1);
284 		impress.typeKeys("<F5>");
285 		sleep(3);
286 		Rectangle rectangle = GraphicsUtil.findRectangle(slideShow.getScreenRectangle(), 0xFFFF0000);
287 		assertNotNull("1st slide appears", rectangle);
288 		slideShow.click(0.5, 0.5);
289 		sleep(2);
290 		rectangle = GraphicsUtil.findRectangle(slideShow.getScreenRectangle(), 0xFF00FF00);
291 		assertNotNull("2nd slide appears", rectangle);
292 		typeKeys("<enter>");
293 		sleep(2);
294 		rectangle = GraphicsUtil.findRectangle(slideShow.getScreenRectangle(), 0xFF0000FF);
295 		assertNotNull("3rd slide appears", rectangle);
296 		slideShow.click(0.5, 0.5);
297 		sleep(2);
298 		rectangle = GraphicsUtil.findRectangle(slideShow.getScreenRectangle(), 0xFF0000FF);
299 		assertNull("The end", rectangle);
300 		slideShow.click(0.5, 0.5);
301 		sleep(3);
302 		assertFalse("Quit", slideShow.exists());
303 	}
304 
305 	@Test
306 	public void testFind() {
307 		open(prepareData("bvt/find.odt"));
308 		writer.waitForExistence(10, 2);
309 		app.dispatch(".uno:SearchDialog");
310 		findDlgFor.setText("OpenOffice");
311 		findDlgFind.click();
312 		sleep(1);
313 		writer.typeKeys("<$copy>");
314 		assertEquals("OpenOffice", app.getClipboard());
315 		findDlgFindAll.click();
316 		sleep(1);
317 		writer.typeKeys("<$copy>");
318 		assertEquals("OpenOfficeOpenOfficeOpenOffice", app.getClipboard());
319 		findDlgReplaceWith.setText("Awesome OpenOffice");
320 		findDlgReplaceAll.click();
321 		sleep(1);
322 		msgbox("Search key replaced 3 times.").ok();
323 		findDlg.close();
324 		sleep(1);
325 		assertEquals(
326 				"Apache Awesome OpenOffice is comprised of six personal productivity applications: a word processor (and its web-authoring component), spreadsheet, presentation graphics, drawing, equation editor, and database. Awesome OpenOffice is released on Windows, Solaris, Linux and Macintosh operation systems, with more communities joining, including a mature FreeBSD port. Awesome OpenOffice is localized, supporting over 110 languages worldwide. ",
327 				copyAll());
328 	}
329 
330 	@Test
331 	public void testFillInSpreadsheet() {
332 		String[][] expected1 = new String[][] { { "1" }, { "1" }, { "1" }, { "1" }, { "1" }, { "1" }, };
333 		String[][] expected2 = new String[][] { { "2" }, { "2" }, { "2" }, { "2" }, { "2" }, { "2" }, };
334 		String[][] expected3 = new String[][] { { "Hi friends", "Hi friends", "Hi friends", "Hi friends" } };
335 		String[][] expected4 = new String[][] { { "99999.999", "99999.999", "99999.999", "99999.999" } };
336 		String[][] expected5 = new String[][] {
337 		{ "99999.999", "-10" }, { "100000.999", "-9" }, { "100001.999", "-8" }, { "100002.999", "-7" }, { "100003.999", "-6" }
338 		};
339 		newSpreadsheet();
340 		SCTool.selectRange("C5");
341 		typeKeys("1<enter>");
342 		SCTool.selectRange("C5:C10");
343 		app.dispatch(".uno:FillDown");
344 		assertArrayEquals("Fill Down:", expected1, SCTool.getCellTexts("C5:C10"));
345 
346 		SCTool.selectRange("D10");
347 		typeKeys("2<enter>");
348 		SCTool.selectRange("D5:D10");
349 		app.dispatch(".uno:FillUp");
350 		assertArrayEquals("Fill Up:", expected2, SCTool.getCellTexts("D5:D10"));
351 
352 		SCTool.selectRange("A1");
353 		typeKeys("Hi friends<enter>");
354 		SCTool.selectRange("A1:D1");
355 		app.dispatch(".uno:FillRight");
356 		assertArrayEquals("Fill Right:", expected3, SCTool.getCellTexts("A1:D1"));
357 
358 		SCTool.selectRange("D2");
359 		typeKeys("99999.999<enter>");
360 		SCTool.selectRange("A2:D2");
361 		app.dispatch(".uno:FillLeft");
362 		assertArrayEquals("Fill left:", expected4, SCTool.getCellTexts("A2:D2"));
363 
364 		SCTool.selectRange("E1");
365 		typeKeys("99999.999<tab>-10<enter>");
366 
367 		SCTool.selectRange("E1:F5");
368 		app.dispatch(".uno:FillSeries");
369 		fillSeriesDlg.ok();
370 		sleep(1);
371 		assertArrayEquals("Fill series..", expected5, SCTool.getCellTexts("E1:F5"));
372 		discard();
373 	}
374 
375 	@Test
376 	public void testSort() {
377 		String[][] expected1 = new String[][] { { "-9999999" }, { "-1.1" }, { "-1.1" }, { "0" }, { "0" }, { "0.1" }, { "10" }, { "12" }, { "9999999" }, { "9999999" },
378 
379 		};
380 		String[][] expected2 = new String[][] { { "TRUE", "Oracle" }, { "TRUE", "OpenOffice" }, { "FALSE", "OpenOffice" }, { "TRUE", "IBM" }, { "FALSE", "IBM" },
381 				{ "TRUE", "Google" }, { "FALSE", "facebook " }, { "TRUE", "Apache" }, { "TRUE", "!yahoo" }, { "TRUE", "" },
382 
383 		};
384 
385 		String[][] expected3 = new String[][] { { "Sunday" }, { "Monday" }, { "Tuesday" }, { "Wednesday" }, { "Thursday" }, { "Friday" }, { "Saturday" },
386 
387 		};
388 
389 		String[][] expected4 = new String[][] { { "-$10.00" }, { "$0.00" }, { "$0.00" }, { "$1.00" }, { "$3.00" }, { "$9.00" }, { "$123.00" }, { "$200.00" }, { "$400.00" },
390 				{ "$10,000.00" },
391 
392 		};
393 		open(prepareData("bvt/sort.ods"));
394 		calc.waitForExistence(10, 2);
395 		SCTool.selectRange("A1:A10");
396 		app.dispatch(".uno:DataSort");
397 		sortWarningDlgCurrent.click();
398 		assertEquals(1, sortPageBy1.getSelIndex());
399 		sortPage.ok();
400 		sleep(1);
401 		assertArrayEquals("Sorted Data", expected1, SCTool.getCellTexts("A1:A10"));
402 		SCTool.selectRange("B1:C10");
403 		app.dispatch(".uno:DataSort");
404 
405 		sortPageBy1.select(2);
406 		sortPageDescending1.check();
407 		assertFalse(sortPageBy3.isEnabled());
408 		assertFalse(sortPageAscending3.isEnabled());
409 		assertFalse(sortPageDescending3.isEnabled());
410 		sortPageBy2.select(1);
411 		assertTrue(sortPageBy3.isEnabled());
412 		assertTrue(sortPageAscending3.isEnabled());
413 		assertTrue(sortPageDescending3.isEnabled());
414 		sortPageDescending2.check();
415 		sortPageBy2.select(0);
416 		assertFalse(sortPageBy3.isEnabled());
417 		assertFalse(sortPageAscending3.isEnabled());
418 		assertFalse(sortPageDescending3.isEnabled());
419 		sortPageBy2.select(1);
420 		sortPage.ok();
421 		sleep(1);
422 
423 		assertArrayEquals("Sorted Data", expected2, SCTool.getCellTexts("B1:C10"));
424 		SCTool.selectRange("D1:D7");
425 		app.dispatch(".uno:DataSort");
426 		sortWarningDlgCurrent.click();
427 		sortOptionsPage.select();
428 		sortOptionsPageRangeContainsColumnLabels.uncheck();
429 		sortOptionsPageCustomSortOrder.check();
430 		sortOptionsPageCustomSortOrderList.select("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday");
431 		sortOptionsPage.ok();
432 		sleep(1);
433 		assertArrayEquals("Sorted Data", expected3, SCTool.getCellTexts("D1:D7"));
434 
435 		SCTool.selectRange("E1:E10");
436 		app.dispatch(".uno:DataSort");
437 		sortWarningDlgCurrent.click();
438 		sortPage.ok();
439 		sleep(1);
440 		assertArrayEquals("Sorted Data", expected4, SCTool.getCellTexts("E1:E10"));
441 		discard();
442 	}
443 
444 	/**
445 	 * Test insert a chart in a draw document 1. New a draw document 2. Insert a
446 	 * chart 3. Check if the chart is inserted successfully
447 	 *
448 	 * @throws Exception
449 	 */
450 	@Test
451 	public void testInsertChartInDraw() throws Exception {
452 		// Create a new drawing document
453 		newDrawing();
454 		// Insert a chart
455 		app.dispatch(".uno:InsertObjectChart");
456 		sleep(3);
457 
458 		// Verify if the chart is inserted successfully
459 		assertTrue("Chart Editor appears", chart.exists(3));
460 		// Focus on edit pane
461 		draw.click(5, 5);
462 		sleep(1);
463 		assertFalse("Chart Editor appears", chart.exists());
464 		discard();
465 	}
466 
467 	/**
468 	 * Test insert a chart in a text document 1. New a text document 2. Insert a
469 	 * chart 3. Check if the chart is inserted successfully
470 	 *
471 	 * @throws Exception
472 	 */
473 	@Test
474 	public void testInsertChartInDocument() throws Exception {
475 		// Create a new text document
476 		newTextDocument();
477 		// Insert a chart
478 		app.dispatch(".uno:InsertObjectChart");
479 		sleep(3);
480 
481 		// Verify if the chart is inserted successfully
482 		assertTrue("Chart Editor appears", chart.exists(3));
483 		// Focus on edit pane
484 		writer.click(5, 5);
485 		sleep(1);
486 		assertFalse("Chart Editor appears", chart.exists());
487 		discard();
488 	}
489 
490 	/**
491 	 * Test insert a chart in a spreadsheet document 1. New a spreadsheet
492 	 * document 2. Insert a chart 3. Check if the chart is inserted successfully
493 	 *
494 	 * @throws Exception
495 	 */
496 	@Test
497 	public void testInsertChartInSpreadsheet() throws Exception {
498 		// Create a new spreadsheet document
499 		newSpreadsheet();
500 		// Insert a chart
501 		app.dispatch(".uno:InsertObjectChart");
502 		sleep(3);
503 		chartWizard.ok();
504 
505 		// Verify if the chart is inserted successfully
506 		assertTrue("Chart Editor appears", chart.exists(3));
507 		// Focus on edit pane
508 		calc.click(5, 5);
509 		sleep(1);
510 		assertFalse("Chart Editor appears", chart.exists());
511 		discard();
512 	}
513 
514 	/**
515 	 * Test insert a chart in a presentation document 1. New a presentation
516 	 * document 2. Insert a chart 3. Check if the chart is inserted successfully
517 	 *
518 	 * @throws Exception
519 	 */
520 	@Test
521 	public void testInsertChartInPresentation() throws Exception {
522 		// Create a new presentation document
523 		newPresentation();
524 		// Insert a chart
525 		app.dispatch(".uno:InsertObjectChart");
526 		sleep(3);
527 		// Verify if the chart is inserted successfully
528 		assertTrue("Chart Editor appears", chart.exists(3));
529 		// Focus on edit pane
530 		impress.click(5, 5);
531 		sleep(1);
532 		assertFalse("Chart Editor appears", chart.exists());
533 		discard();
534 	}
535 
536 	/**
537 	 * Test insert a table in a draw document 1. New a draw document 2. Insert a
538 	 * default table 3. Check if the table is inserted successfully
539 	 *
540 	 * @throws Exception
541 	 */
542 	@Test
543 	public void testInsertTableInDraw() throws Exception {
544 		// Create a new drawing document
545 		newDrawing();
546 		// Insert a table
547 		app.dispatch(".uno:InsertTable");
548 		insertTable.ok();
549 		sleep(1);
550 		draw.typeKeys("3");
551 		assertTrue("Table Toolbar appears", tableToolbar.exists(3));
552 //		assertEquals("The cell content", "3", copyAll());
553 		discard();
554 	}
555 
556 	/**
557 	 * Test insert a table in a text document 1. New a text document 2. Insert a
558 	 * default table 3. Check if the table is inserted successfully
559 	 *
560 	 * @throws Exception
561 	 */
562 	@Test
563 	public void testInsertTableInDocument() throws Exception {
564 		// Create a new text document
565 		newTextDocument();
566 		// Insert a table
567 		app.dispatch(".uno:InsertTable");
568 		writerInsertTable.ok();
569 		sleep(1);
570 		writer.typeKeys("3");
571 		// Verify if the table toolbar is active
572 		assertTrue("Table Toolbar appears", tableToolbar.exists(3));
573 //		assertEquals("The cell content", "3", copyAll());
574 		discard();
575 	}
576 
577 	/**
578 	 * Test insert a table in a presentation document 1. New a presentation
579 	 * document 2. Insert a default table 3. Check if the table is inserted
580 	 * successfully
581 	 *
582 	 * @throws Exception
583 	 */
584 	@Test
585 	public void testInsertTableInPresentation() throws Exception {
586 		// Create a new presentation document
587 		newPresentation();
588 
589 		// Insert a table
590 		app.dispatch(".uno:InsertTable");
591 		insertTable.ok();
592 		sleep(1);
593 		impress.typeKeys("3");
594 		assertTrue("Table Toolbar appears", tableToolbar.exists(3));
595 //		assertEquals("The cell content", "3", copyAll());
596 		discard();
597 	}
598 
599 	/**
600 	 * Test insert a function in a spreadsheet document via Sum button 1. New a
601 	 * spreadsheet document 2. Insert a function via Sum button 3. Check if the
602 	 * result is correct
603 	 *
604 	 * @throws Exception
605 	 */
606 	@Test
607 	public void testSumInFormulaBar() throws Exception {
608 		// Create a new spreadsheet document
609 		newSpreadsheet();
610 		// Insert source numbers
611 		String sourceNumber1 = "5";
612 		String sourceNumber2 = "3";
613 		String expectedResult = "8";
614 		SCTool.selectRange("A1");
615 		typeKeys(sourceNumber1);
616 		SCTool.selectRange("B1");
617 		typeKeys(sourceNumber2);
618 		// Insert a function via Sum button
619 		SCTool.selectRange("C1");
620 		scInputBarSum.click();
621 		typeKeys("<enter>");
622 		// Verify if the calculated result is equal to the expected result
623 		assertEquals("The calculated result", expectedResult, SCTool.getCellText("C1"));
624 		discard();
625 	}
626 
627 	/**
628 	 * Test insert a function in a spreadsheet document via inputbar 1. New a
629 	 * spreadsheet document 2. Insert a function via inputbar: COS 3. Check if
630 	 * the result is correct
631 	 *
632 	 * @throws Exception
633 	 */
634 	@Test
635 	public void testInsertFunctionViaFormulaBar() throws Exception {
636 		// Create a new spreadsheet document
637 		newSpreadsheet();
638 		// Insert source numbers and expected result
639 		String sourceData = "0";
640 		String expectedResult = "1";
641 		SCTool.selectRange("A1");
642 		typeKeys(sourceData);
643 
644 		// Insert a function via inputbar: COS
645 		SCTool.selectRange("D1");
646 		scInputBarInput.inputKeys("=COS(A1)");
647 		typeKeys("<enter>");
648 
649 		// Verify if the calculated result is equal to the expected result
650 		assertEquals("The calculated result", expectedResult, SCTool.getCellText("D1"));
651 		discard();
652 	}
653 
654 	/**
655 	 * Test insert a function in a spreadsheet document via Function Wizard
656 	 * Dialog 1. New a spreadsheet document 2. Insert a function via Function
657 	 * Wizard Dialog: ABS 3. Check if the result is correct
658 	 *
659 	 * @throws Exception
660 	 */
661 	@Test
662 	public void testFunctionWizardInFormulaBar() throws Exception {
663 		// Create a new spreadsheet document
664 		newSpreadsheet();
665 		// Insert source number
666 		String sourceNumber = "-5";
667 		String expectedResult = "5";
668 		SCTool.selectRange("A1");
669 		typeKeys(sourceNumber);
670 		typeKeys("<enter>");
671 		// Insert a function via Function Wizard Dialog: ABS
672 		SCTool.selectRange("B1");
673 		app.dispatch(".uno:FunctionDialog");
674 		// SC_FunctionWizardDlg_FunctionList.doubleClick(5, 5);
675 		scFunctionWizardDlgFunctionList.select("ABS");
676 		scFunctionWizardDlgNext.click(); // Use "Next" button
677 		scFunctionWizardDlgEdit1.inputKeys("A1");
678 		scFunctionWizardDlg.ok();
679 		// Verify if the calculated result is equal to the expected result
680 		assertEquals("The calculated result", expectedResult, SCTool.getCellText("B1"));
681 		discard();
682 	}
683 }
684