1b164ae3eSLei De Bin /**************************************************************
2b164ae3eSLei De Bin  *
3b164ae3eSLei De Bin  * Licensed to the Apache Software Foundation (ASF) under one
4b164ae3eSLei De Bin  * or more contributor license agreements.  See the NOTICE file
5b164ae3eSLei De Bin  * distributed with this work for additional information
6b164ae3eSLei De Bin  * regarding copyright ownership.  The ASF licenses this file
7b164ae3eSLei De Bin  * to you under the Apache License, Version 2.0 (the
8b164ae3eSLei De Bin  * "License"); you may not use this file except in compliance
9b164ae3eSLei De Bin  * with the License.  You may obtain a copy of the License at
10b164ae3eSLei De Bin  *
11b164ae3eSLei De Bin  *   http://www.apache.org/licenses/LICENSE-2.0
12b164ae3eSLei De Bin  *
13b164ae3eSLei De Bin  * Unless required by applicable law or agreed to in writing,
14b164ae3eSLei De Bin  * software distributed under the License is distributed on an
15b164ae3eSLei De Bin  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b164ae3eSLei De Bin  * KIND, either express or implied.  See the License for the
17b164ae3eSLei De Bin  * specific language governing permissions and limitations
18b164ae3eSLei De Bin  * under the License.
19b164ae3eSLei De Bin  *
20b164ae3eSLei De Bin  *************************************************************/
21b164ae3eSLei De Bin 
22faa4b864SLei De Bin /**
23faa4b864SLei De Bin  *
24faa4b864SLei De Bin  */
25*80a6f5c5SLiu Zhe package bvt.gui;
2632c31156SLiu Zhe 
2722a14f28SLiu Zhe import static org.junit.Assert.*;
2822a14f28SLiu Zhe import static org.openoffice.test.common.Testspace.*;
2922a14f28SLiu Zhe import static org.openoffice.test.vcl.Tester.*;
30b4d2d410SLiu Zhe import static testlib.gui.AppTool.*;
3122a14f28SLiu Zhe import static testlib.gui.UIMap.*;
32faa4b864SLei De Bin 
33faa4b864SLei De Bin import java.awt.Rectangle;
34faa4b864SLei De Bin 
35faa4b864SLei De Bin import org.junit.Before;
36b4d2d410SLiu Zhe import org.junit.BeforeClass;
37faa4b864SLei De Bin import org.junit.Rule;
38faa4b864SLei De Bin import org.junit.Test;
39faa4b864SLei De Bin import org.openoffice.test.common.FileUtil;
40faa4b864SLei De Bin import org.openoffice.test.common.GraphicsUtil;
4122a14f28SLiu Zhe import org.openoffice.test.common.Logger;
42faa4b864SLei De Bin 
43b4d2d410SLiu Zhe import testlib.gui.SCTool;
44faa4b864SLei De Bin 
45faa4b864SLei De Bin /**
46faa4b864SLei De Bin  *
47faa4b864SLei De Bin  */
4809c344eeSLiu Zhe public class BasicFunctionTest {
49faa4b864SLei De Bin 
50faa4b864SLei De Bin 	@Rule
5122a14f28SLiu Zhe 	public Logger log = Logger.getLogger(this);
5232c31156SLiu Zhe 
53b4d2d410SLiu Zhe 	@BeforeClass
54b4d2d410SLiu Zhe 	public static void beforeClass() throws Exception {
55b4d2d410SLiu Zhe 		app.clean();
562fc12ec5SLiu Zhe 	}
572fc12ec5SLiu Zhe 
58b4d2d410SLiu Zhe 	@Before
59b4d2d410SLiu Zhe 	public void before() {
609d278195SLiu Zhe 		app.close();
61b4d2d410SLiu Zhe 		app.start();
62faa4b864SLei De Bin 	}
6332c31156SLiu Zhe 
64faa4b864SLei De Bin 	@Test
6532c31156SLiu Zhe 	public void testExportAsPDF() throws Exception {
66b4d2d410SLiu Zhe 		String file = prepareData("bvt/pdf.odt");
67b4d2d410SLiu Zhe 		String exportTo1 = getPath("temp/1.pdf");
68b4d2d410SLiu Zhe 		String exportTo2 = getPath("temp/2.pdf");
69b4d2d410SLiu Zhe 		deleteFile(exportTo1);
70b4d2d410SLiu Zhe 		deleteFile(exportTo2);
71b4d2d410SLiu Zhe 		open(file);
72b4d2d410SLiu Zhe 		writer.waitForExistence(10, 1);
73cb6199d5SLiu Zhe 		app.dispatch(".uno:ExportToPDF");
74b4d2d410SLiu Zhe 		pdfGeneralPage.ok();
75b4d2d410SLiu Zhe 		submitSaveDlg(exportTo1);
76b4d2d410SLiu Zhe 		sleep(1);
77b4d2d410SLiu Zhe 		String magic = FileUtil.readFileAsString(exportTo1).substring(0, 4);
78b4d2d410SLiu Zhe 		assertEquals("PDF is exported?", "%PDF", magic);
79b4d2d410SLiu Zhe 
80b4d2d410SLiu Zhe 		button(".uno:ExportDirectToPDF").click();//Click via toolbar
81b4d2d410SLiu Zhe 		submitSaveDlg(exportTo2);
82b4d2d410SLiu Zhe 		sleep(1);
83b4d2d410SLiu Zhe 		magic = FileUtil.readFileAsString(exportTo2).substring(0, 4);
84b4d2d410SLiu Zhe 		assertEquals("PDF is exported directly?", "%PDF", magic);
85faa4b864SLei De Bin 	}
8632c31156SLiu Zhe 
87faa4b864SLei De Bin 	/**
8832c31156SLiu Zhe 	 * Test the File -- Print Dialog show
89faa4b864SLei De Bin 	 *
9032c31156SLiu Zhe 	 */
91faa4b864SLei De Bin 	@Test
92b4d2d410SLiu Zhe 	public void testPrinter() {
9332c31156SLiu Zhe 		// Create a new text document
94b4d2d410SLiu Zhe 		newTextDocument();
95b4d2d410SLiu Zhe 		app.dispatch(".uno:PrinterSetup");
96b4d2d410SLiu Zhe 		if (activeMsgBox.exists(2))
97b4d2d410SLiu Zhe 			activeMsgBox.ok();
98b4d2d410SLiu Zhe 
99b4d2d410SLiu Zhe //		PrintService[] ps = PrintServiceLookup.lookupPrintServices(null, null);
100b4d2d410SLiu Zhe //		String[] names = new String[ps.length];
101b4d2d410SLiu Zhe //		for (int i = 0; i < ps.length; i++) {
102b4d2d410SLiu Zhe //			names[i] = ps[i].getName();
103b4d2d410SLiu Zhe //		}
104b4d2d410SLiu Zhe //
105b4d2d410SLiu Zhe //		assertArrayEquals("Printers Names", names, printerSetUpDlgPrinterNames.getItemsText());
106b4d2d410SLiu Zhe 		assertTrue("Printer Setup dialog appears", printerSetUpDlg.exists(3));
107b4d2d410SLiu Zhe 		printerSetUpDlg.cancel();
10832c31156SLiu Zhe 	}
10932c31156SLiu Zhe 
110faa4b864SLei De Bin 	/**
11132c31156SLiu Zhe 	 * Test the File -- Java Dialog show
112faa4b864SLei De Bin 	 *
11332c31156SLiu Zhe 	 */
114b4d2d410SLiu Zhe //	@Test
115b4d2d410SLiu Zhe //	public void testJavaDialog() {
116b4d2d410SLiu Zhe //
117b4d2d410SLiu Zhe //		// Create a new text document and launch a Wizards dialog which need JVM
118b4d2d410SLiu Zhe //		// work correctly.
119b4d2d410SLiu Zhe //		app.dispatch("private:factory/swriter");
120b4d2d410SLiu Zhe //		File tempfile = new File(oo.getUserInstallation(), "user/template/myAgendaTemplate.ott");
121b4d2d410SLiu Zhe //		FileUtil.deleteFile(tempfile);
122b4d2d410SLiu Zhe //		sleep(3);
123b4d2d410SLiu Zhe //		app.dispatch("service:com.sun.star.wizards.agenda.CallWizard?start");
124b4d2d410SLiu Zhe //		sleep(5);
125b4d2d410SLiu Zhe //		assertTrue(Wizards_AgendaDialog.exists(10));
126b4d2d410SLiu Zhe //		Wizards_AgendaDialog_FinishButton.click();
127b4d2d410SLiu Zhe //		sleep(10);
128b4d2d410SLiu Zhe //		writer.focus();
129b4d2d410SLiu Zhe //		sleep(1);
130b4d2d410SLiu Zhe //		app.dispatch(".uno:SelectAll");
131b4d2d410SLiu Zhe //		typeKeys("<$copy>");
132b4d2d410SLiu Zhe //		// System.out.println("now txt:"+app.getClipboard());
133b4d2d410SLiu Zhe //		// assertTrue(app.getClipboard().startsWith("<Name>"));
134b4d2d410SLiu Zhe //		assertNotNull(app.getClipboard());
135b4d2d410SLiu Zhe //	}
13632c31156SLiu Zhe 
137faa4b864SLei De Bin 	/**
13832c31156SLiu Zhe 	 * Test the Tools / Macros / Organize Dialogs" show
139faa4b864SLei De Bin 	 *
14032c31156SLiu Zhe 	 */
141faa4b864SLei De Bin 	@Test
142b4d2d410SLiu Zhe 	public void testRunMacro() {
143b4d2d410SLiu Zhe 		open(prepareData("bvt/macro.ods"));
144b4d2d410SLiu Zhe 		calc.waitForExistence(10, 2);
145b4d2d410SLiu Zhe 		app.dispatch(".uno:RunMacro");
146b4d2d410SLiu Zhe 		runMacroDlgCategories.expand("macro.ods");
147b4d2d410SLiu Zhe 		runMacroDlgCategories.expand("Standard");
148b4d2d410SLiu Zhe 		runMacroDlgCategories.select("Module1");
149b4d2d410SLiu Zhe 		runMacroDlgCommands.select(0);
150b4d2d410SLiu Zhe 		runMacroDlg.ok();
151b4d2d410SLiu Zhe 		assertEquals("A3 should be =1+3", "4", SCTool.getCellText("A3"));
152b4d2d410SLiu Zhe 		discard();
153faa4b864SLei De Bin 	}
15432c31156SLiu Zhe 
155faa4b864SLei De Bin 	/**
15632c31156SLiu Zhe 	 * Test the About Dialog show
157faa4b864SLei De Bin 	 *
15832c31156SLiu Zhe 	 */
159faa4b864SLei De Bin 	@Test
160b4d2d410SLiu Zhe 	public void testHelp() {
161cb6199d5SLiu Zhe 		app.dispatch(".uno:About");
162b4d2d410SLiu Zhe 		assertTrue(aboutDialog.exists(5));
163b4d2d410SLiu Zhe 		aboutDialog.ok();
164b4d2d410SLiu Zhe 		sleep(1);
165b4d2d410SLiu Zhe 		typeKeys("<F1>");
166b4d2d410SLiu Zhe 		assertTrue(helpWindow.exists(5));
167b4d2d410SLiu Zhe 		helpWindow.close();
168faa4b864SLei De Bin 	}
16932c31156SLiu Zhe 
170faa4b864SLei De Bin 	/**
171faa4b864SLei De Bin 	 * Test inserting a picture in text document
17232c31156SLiu Zhe 	 *
173faa4b864SLei De Bin 	 * @throws Exception
174faa4b864SLei De Bin 	 */
17532c31156SLiu Zhe 
176faa4b864SLei De Bin 	@Test
177faa4b864SLei De Bin 	public void testInsertPictureInDocument() throws Exception {
1786b55ece7SLiu Zhe 		String bmp_green = prepareData("image/green_256x256.bmp");
1796b55ece7SLiu Zhe 		String bmp_red = prepareData("image/red_256x256.bmp");
18032c31156SLiu Zhe 
18132c31156SLiu Zhe 		// Create a new text document
182b4d2d410SLiu Zhe 		newTextDocument();
18332c31156SLiu Zhe 		// Insert a picture fully filled with green
18432c31156SLiu Zhe 		app.dispatch(".uno:InsertGraphic");
185faa4b864SLei De Bin 		submitOpenDlg(bmp_green);
186b4d2d410SLiu Zhe 		writer.click(5,200);
187faa4b864SLei De Bin 		sleep(1);
18832c31156SLiu Zhe 
189faa4b864SLei De Bin 		// Verify if the picture is inserted successfully
19022a14f28SLiu Zhe 		Rectangle rectangle = GraphicsUtil.findRectangle(writer.getScreenRectangle(), 0xFF00FF00);
191b4d2d410SLiu Zhe 		assertTrue("Green Picture is inserted?" + rectangle, rectangle != null && rectangle.getWidth() > 10);
19232c31156SLiu Zhe 		// insert another picture
19332c31156SLiu Zhe 		app.dispatch(".uno:InsertGraphic");
194faa4b864SLei De Bin 		submitOpenDlg(bmp_red);
195b4d2d410SLiu Zhe 		writer.click(5, 200);
196faa4b864SLei De Bin 		sleep(1);
197faa4b864SLei De Bin 		// Verify if the picture is inserted successfully
19822a14f28SLiu Zhe 		rectangle = GraphicsUtil.findRectangle(writer.getScreenRectangle(), 0xFFFF0000);
199b4d2d410SLiu Zhe 		assertTrue("Green Picture is inserted? " + rectangle, rectangle != null && rectangle.getWidth() > 10);
200b4d2d410SLiu Zhe 		discard();
201faa4b864SLei De Bin 	}
202faa4b864SLei De Bin 
203faa4b864SLei De Bin 	@Test
204faa4b864SLei De Bin 	public void testInsertPictureInSpreadsheet() throws Exception {
205b4d2d410SLiu Zhe 		String bmp_green = prepareData("image/green_64x64.png");
206b4d2d410SLiu Zhe 		String bmp_red = prepareData("image/red_64x64.png");
207b4d2d410SLiu Zhe 		newSpreadsheet();
20832c31156SLiu Zhe 		// Insert a picture fully filled with green
20932c31156SLiu Zhe 		app.dispatch(".uno:InsertGraphic");
210faa4b864SLei De Bin 		submitOpenDlg(bmp_green);
211b4d2d410SLiu Zhe 		calc.click(5, 150);
212faa4b864SLei De Bin 		sleep(1);
21332c31156SLiu Zhe 
214faa4b864SLei De Bin 		// Verify if the picture is inserted successfully
21522a14f28SLiu Zhe 		Rectangle rectangle = GraphicsUtil.findRectangle(calc.getScreenRectangle(), 0xFF00FF00);
216b4d2d410SLiu Zhe 		assertTrue("Green Picture is inserted?" + rectangle, rectangle != null && rectangle.getWidth() > 10);
217b4d2d410SLiu Zhe 
218b4d2d410SLiu Zhe 		SCTool.selectRange("C1");
21932c31156SLiu Zhe 		// insert another picture
22032c31156SLiu Zhe 		app.dispatch(".uno:InsertGraphic");
221faa4b864SLei De Bin 		submitOpenDlg(bmp_red);
222b4d2d410SLiu Zhe 		calc.click(5, 150);
223faa4b864SLei De Bin 		sleep(1);
224faa4b864SLei De Bin 		// Verify if the picture is inserted successfully
22522a14f28SLiu Zhe 		rectangle = GraphicsUtil.findRectangle(calc.getScreenRectangle(), 0xFFFF0000);
226b4d2d410SLiu Zhe 		assertTrue("Red Picture is inserted? " + rectangle, rectangle != null && rectangle.getWidth() > 10);
227b4d2d410SLiu Zhe 		discard();
228faa4b864SLei De Bin 	}
22932c31156SLiu Zhe 
230faa4b864SLei De Bin 	@Test
231faa4b864SLei De Bin 	public void testInsertPictureInPresentation() throws Exception {
2326b55ece7SLiu Zhe 		String bmp_green = prepareData("image/green_256x256.bmp");
2336b55ece7SLiu Zhe 		String bmp_red = prepareData("image/red_256x256.bmp");
234b4d2d410SLiu Zhe 		newPresentation();
23532c31156SLiu Zhe 		// Insert a picture fully filled with green
23632c31156SLiu Zhe 		app.dispatch(".uno:InsertGraphic");
237faa4b864SLei De Bin 		submitOpenDlg(bmp_green);
23832c31156SLiu Zhe 		impress.click(5, 5);
239faa4b864SLei De Bin 		sleep(1);
24032c31156SLiu Zhe 
241faa4b864SLei De Bin 		// Verify if the picture is inserted successfully
24222a14f28SLiu Zhe 		Rectangle rectangle = GraphicsUtil.findRectangle(impress.getScreenRectangle(), 0xFF00FF00);
243b4d2d410SLiu Zhe 		assertTrue("Green Picture is inserted?" + rectangle, rectangle != null && rectangle.getWidth() > 10);
24432c31156SLiu Zhe 		// insert another picture
24532c31156SLiu Zhe 		app.dispatch(".uno:InsertGraphic");
246faa4b864SLei De Bin 		submitOpenDlg(bmp_red);
247faa4b864SLei De Bin 		impress.click(1, 1);
248faa4b864SLei De Bin 		sleep(1);
249faa4b864SLei De Bin 		// Verify if the picture is inserted successfully
25022a14f28SLiu Zhe 		rectangle = GraphicsUtil.findRectangle(impress.getScreenRectangle(), 0xFFFF0000);
251b4d2d410SLiu Zhe 		assertTrue("Red Picture is inserted? " + rectangle, rectangle != null && rectangle.getWidth() > 10);
252b4d2d410SLiu Zhe 		discard();
253faa4b864SLei De Bin 	}
25432c31156SLiu Zhe 
255faa4b864SLei De Bin 	@Test
256faa4b864SLei De Bin 	public void testSlideShow() throws Exception {
257b4d2d410SLiu Zhe 		open(prepareData("bvt/slideshow.odp"));
258faa4b864SLei De Bin 		impress.waitForExistence(10, 2);
259b4d2d410SLiu Zhe 		sleep(1);
260b4d2d410SLiu Zhe 		impress.typeKeys("<F5>");
261faa4b864SLei De Bin 		sleep(3);
262b4d2d410SLiu Zhe 		Rectangle rectangle = GraphicsUtil.findRectangle(slideShow.getScreenRectangle(), 0xFFFF0000);
263faa4b864SLei De Bin 		assertNotNull("1st slide appears", rectangle);
264b4d2d410SLiu Zhe 		slideShow.click(0.5, 0.5);
265faa4b864SLei De Bin 		sleep(2);
266b4d2d410SLiu Zhe 		rectangle = GraphicsUtil.findRectangle(slideShow.getScreenRectangle(), 0xFF00FF00);
267faa4b864SLei De Bin 		assertNotNull("2nd slide appears", rectangle);
268faa4b864SLei De Bin 		typeKeys("<enter>");
269faa4b864SLei De Bin 		sleep(2);
270b4d2d410SLiu Zhe 		rectangle = GraphicsUtil.findRectangle(slideShow.getScreenRectangle(), 0xFF0000FF);
271faa4b864SLei De Bin 		assertNotNull("3rd slide appears", rectangle);
272b4d2d410SLiu Zhe 		slideShow.click(0.5, 0.5);
273faa4b864SLei De Bin 		sleep(2);
274b4d2d410SLiu Zhe 		rectangle = GraphicsUtil.findRectangle(slideShow.getScreenRectangle(), 0xFF0000FF);
275faa4b864SLei De Bin 		assertNull("The end", rectangle);
276b4d2d410SLiu Zhe 		slideShow.click(0.5, 0.5);
277faa4b864SLei De Bin 		sleep(3);
278b4d2d410SLiu Zhe 		assertFalse("Quit", slideShow.exists());
279faa4b864SLei De Bin 	}
28032c31156SLiu Zhe 
281faa4b864SLei De Bin 	@Test
282faa4b864SLei De Bin 	public void testFind() {
283b4d2d410SLiu Zhe 		open(prepareData("bvt/find.odt"));
284faa4b864SLei De Bin 		writer.waitForExistence(10, 2);
28532c31156SLiu Zhe 		app.dispatch(".uno:SearchDialog");
286b4d2d410SLiu Zhe 		findDlgFor.setText("OpenOffice");
287b4d2d410SLiu Zhe 		findDlgFind.click();
288faa4b864SLei De Bin 		sleep(1);
289b4d2d410SLiu Zhe 		writer.typeKeys("<$copy>");
290faa4b864SLei De Bin 		assertEquals("OpenOffice", app.getClipboard());
291b4d2d410SLiu Zhe 		findDlgFindAll.click();
292faa4b864SLei De Bin 		sleep(1);
293b4d2d410SLiu Zhe 		writer.typeKeys("<$copy>");
294faa4b864SLei De Bin 		assertEquals("OpenOfficeOpenOfficeOpenOffice", app.getClipboard());
295b4d2d410SLiu Zhe 		findDlgReplaceWith.setText("Awesome OpenOffice");
296b4d2d410SLiu Zhe 		findDlgReplaceAll.click();
297faa4b864SLei De Bin 		sleep(1);
298faa4b864SLei De Bin 		msgbox("Search key replaced 3 times.").ok();
299b4d2d410SLiu Zhe 		findDlg.close();
300faa4b864SLei De Bin 		sleep(1);
30132c31156SLiu Zhe 		assertEquals(
30232c31156SLiu Zhe 				"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. ",
303b4d2d410SLiu Zhe 				copyAll());
304faa4b864SLei De Bin 	}
30532c31156SLiu Zhe 
306faa4b864SLei De Bin 	@Test
307faa4b864SLei De Bin 	public void testFillInSpreadsheet() {
30822a14f28SLiu Zhe 		String[][] expected1 = new String[][] { { "1" }, { "1" }, { "1" }, { "1" }, { "1" }, { "1" }, };
30922a14f28SLiu Zhe 		String[][] expected2 = new String[][] { { "2" }, { "2" }, { "2" }, { "2" }, { "2" }, { "2" }, };
31022a14f28SLiu Zhe 		String[][] expected3 = new String[][] { { "Hi friends", "Hi friends", "Hi friends", "Hi friends" } };
31122a14f28SLiu Zhe 		String[][] expected4 = new String[][] { { "99999.999", "99999.999", "99999.999", "99999.999" } };
312faa4b864SLei De Bin 		String[][] expected5 = new String[][] {
31322a14f28SLiu Zhe 		{ "99999.999", "-10" }, { "100000.999", "-9" }, { "100001.999", "-8" }, { "100002.999", "-7" }, { "100003.999", "-6" }
314faa4b864SLei De Bin 		};
315b4d2d410SLiu Zhe 		newSpreadsheet();
316b4d2d410SLiu Zhe 		SCTool.selectRange("C5");
317faa4b864SLei De Bin 		typeKeys("1<enter>");
318b4d2d410SLiu Zhe 		SCTool.selectRange("C5:C10");
31932c31156SLiu Zhe 		app.dispatch(".uno:FillDown");
320b4d2d410SLiu Zhe 		assertArrayEquals("Fill Down:", expected1, SCTool.getCellTexts("C5:C10"));
32132c31156SLiu Zhe 
322b4d2d410SLiu Zhe 		SCTool.selectRange("D10");
323faa4b864SLei De Bin 		typeKeys("2<enter>");
324b4d2d410SLiu Zhe 		SCTool.selectRange("D5:D10");
32532c31156SLiu Zhe 		app.dispatch(".uno:FillUp");
326b4d2d410SLiu Zhe 		assertArrayEquals("Fill Up:", expected2, SCTool.getCellTexts("D5:D10"));
32732c31156SLiu Zhe 
328b4d2d410SLiu Zhe 		SCTool.selectRange("A1");
329faa4b864SLei De Bin 		typeKeys("Hi friends<enter>");
330b4d2d410SLiu Zhe 		SCTool.selectRange("A1:D1");
33132c31156SLiu Zhe 		app.dispatch(".uno:FillRight");
332b4d2d410SLiu Zhe 		assertArrayEquals("Fill Right:", expected3, SCTool.getCellTexts("A1:D1"));
33332c31156SLiu Zhe 
334b4d2d410SLiu Zhe 		SCTool.selectRange("D2");
335faa4b864SLei De Bin 		typeKeys("99999.999<enter>");
336b4d2d410SLiu Zhe 		SCTool.selectRange("A2:D2");
33732c31156SLiu Zhe 		app.dispatch(".uno:FillLeft");
338b4d2d410SLiu Zhe 		assertArrayEquals("Fill left:", expected4, SCTool.getCellTexts("A2:D2"));
339faa4b864SLei De Bin 
340b4d2d410SLiu Zhe 		SCTool.selectRange("E1");
341faa4b864SLei De Bin 		typeKeys("99999.999<tab>-10<enter>");
34232c31156SLiu Zhe 
343b4d2d410SLiu Zhe 		SCTool.selectRange("E1:F5");
34432c31156SLiu Zhe 		app.dispatch(".uno:FillSeries");
345b4d2d410SLiu Zhe 		fillSeriesDlg.ok();
346faa4b864SLei De Bin 		sleep(1);
347b4d2d410SLiu Zhe 		assertArrayEquals("Fill series..", expected5, SCTool.getCellTexts("E1:F5"));
348b4d2d410SLiu Zhe 		discard();
349faa4b864SLei De Bin 	}
35032c31156SLiu Zhe 
351faa4b864SLei De Bin 	@Test
352faa4b864SLei De Bin 	public void testSort() {
35322a14f28SLiu Zhe 		String[][] expected1 = new String[][] { { "-9999999" }, { "-1.1" }, { "-1.1" }, { "0" }, { "0" }, { "0.1" }, { "10" }, { "12" }, { "9999999" }, { "9999999" },
354faa4b864SLei De Bin 
355faa4b864SLei De Bin 		};
35622a14f28SLiu Zhe 		String[][] expected2 = new String[][] { { "TRUE", "Oracle" }, { "TRUE", "OpenOffice" }, { "FALSE", "OpenOffice" }, { "TRUE", "IBM" }, { "FALSE", "IBM" },
35722a14f28SLiu Zhe 				{ "TRUE", "Google" }, { "FALSE", "facebook " }, { "TRUE", "Apache" }, { "TRUE", "!yahoo" }, { "TRUE", "" },
358faa4b864SLei De Bin 
359faa4b864SLei De Bin 		};
360faa4b864SLei De Bin 
36122a14f28SLiu Zhe 		String[][] expected3 = new String[][] { { "Sunday" }, { "Monday" }, { "Tuesday" }, { "Wednesday" }, { "Thursday" }, { "Friday" }, { "Saturday" },
362faa4b864SLei De Bin 
363faa4b864SLei De Bin 		};
36432c31156SLiu Zhe 
36522a14f28SLiu Zhe 		String[][] expected4 = new String[][] { { "-$10.00" }, { "$0.00" }, { "$0.00" }, { "$1.00" }, { "$3.00" }, { "$9.00" }, { "$123.00" }, { "$200.00" }, { "$400.00" },
36622a14f28SLiu Zhe 				{ "$10,000.00" },
367faa4b864SLei De Bin 
368faa4b864SLei De Bin 		};
369b4d2d410SLiu Zhe 		open(prepareData("bvt/sort.ods"));
370faa4b864SLei De Bin 		calc.waitForExistence(10, 2);
371b4d2d410SLiu Zhe 		SCTool.selectRange("A1:A10");
372cb6199d5SLiu Zhe 		app.dispatch(".uno:DataSort");
373b4d2d410SLiu Zhe 		sortWarningDlgCurrent.click();
374b4d2d410SLiu Zhe 		assertEquals(1, sortPageBy1.getSelIndex());
375b4d2d410SLiu Zhe 		sortPage.ok();
376faa4b864SLei De Bin 		sleep(1);
377b4d2d410SLiu Zhe 		assertArrayEquals("Sorted Data", expected1, SCTool.getCellTexts("A1:A10"));
378b4d2d410SLiu Zhe 		SCTool.selectRange("B1:C10");
379cb6199d5SLiu Zhe 		app.dispatch(".uno:DataSort");
3807dd7871fSLei De Bin 
381b4d2d410SLiu Zhe 		sortPageBy1.select(2);
382b4d2d410SLiu Zhe 		sortPageDescending1.check();
383b4d2d410SLiu Zhe 		assertFalse(sortPageBy3.isEnabled());
384b4d2d410SLiu Zhe 		assertFalse(sortPageAscending3.isEnabled());
385b4d2d410SLiu Zhe 		assertFalse(sortPageDescending3.isEnabled());
386b4d2d410SLiu Zhe 		sortPageBy2.select(1);
387b4d2d410SLiu Zhe 		assertTrue(sortPageBy3.isEnabled());
388b4d2d410SLiu Zhe 		assertTrue(sortPageAscending3.isEnabled());
389b4d2d410SLiu Zhe 		assertTrue(sortPageDescending3.isEnabled());
390b4d2d410SLiu Zhe 		sortPageDescending2.check();
391b4d2d410SLiu Zhe 		sortPageBy2.select(0);
392b4d2d410SLiu Zhe 		assertFalse(sortPageBy3.isEnabled());
393b4d2d410SLiu Zhe 		assertFalse(sortPageAscending3.isEnabled());
394b4d2d410SLiu Zhe 		assertFalse(sortPageDescending3.isEnabled());
395b4d2d410SLiu Zhe 		sortPageBy2.select(1);
396b4d2d410SLiu Zhe 		sortPage.ok();
397faa4b864SLei De Bin 		sleep(1);
39832c31156SLiu Zhe 
399b4d2d410SLiu Zhe 		assertArrayEquals("Sorted Data", expected2, SCTool.getCellTexts("B1:C10"));
400b4d2d410SLiu Zhe 		SCTool.selectRange("D1:D7");
401cb6199d5SLiu Zhe 		app.dispatch(".uno:DataSort");
402b4d2d410SLiu Zhe 		sortWarningDlgCurrent.click();
403b4d2d410SLiu Zhe 		sortOptionsPage.select();
404b4d2d410SLiu Zhe 		sortOptionsPageRangeContainsColumnLabels.uncheck();
405b4d2d410SLiu Zhe 		sortOptionsPageCustomSortOrder.check();
406b4d2d410SLiu Zhe 		sortOptionsPageCustomSortOrderList.select("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday");
407b4d2d410SLiu Zhe 		sortOptionsPage.ok();
408faa4b864SLei De Bin 		sleep(1);
409b4d2d410SLiu Zhe 		assertArrayEquals("Sorted Data", expected3, SCTool.getCellTexts("D1:D7"));
41032c31156SLiu Zhe 
411b4d2d410SLiu Zhe 		SCTool.selectRange("E1:E10");
412cb6199d5SLiu Zhe 		app.dispatch(".uno:DataSort");
413b4d2d410SLiu Zhe 		sortWarningDlgCurrent.click();
414b4d2d410SLiu Zhe 		sortPage.ok();
415faa4b864SLei De Bin 		sleep(1);
416b4d2d410SLiu Zhe 		assertArrayEquals("Sorted Data", expected4, SCTool.getCellTexts("E1:E10"));
417b4d2d410SLiu Zhe 		discard();
418faa4b864SLei De Bin 	}
41932c31156SLiu Zhe 
4207dd2b5bbSLiu Zhe 	/**
42132c31156SLiu Zhe 	 * Test insert a chart in a draw document 1. New a draw document 2. Insert a
42232c31156SLiu Zhe 	 * chart 3. Check if the chart is inserted successfully
42332c31156SLiu Zhe 	 *
4247dd2b5bbSLiu Zhe 	 * @throws Exception
4257dd2b5bbSLiu Zhe 	 */
4267dd2b5bbSLiu Zhe 	@Test
42732c31156SLiu Zhe 	public void testInsertChartInDraw() throws Exception {
4287dd2b5bbSLiu Zhe 		// Create a new drawing document
429b4d2d410SLiu Zhe 		newDrawing();
4307dd2b5bbSLiu Zhe 		// Insert a chart
43132c31156SLiu Zhe 		app.dispatch(".uno:InsertObjectChart");
4327dd2b5bbSLiu Zhe 		sleep(3);
43332c31156SLiu Zhe 
4347dd2b5bbSLiu Zhe 		// Verify if the chart is inserted successfully
435b4d2d410SLiu Zhe 		assertTrue("Chart Editor appears", chart.exists(3));
4367dd2b5bbSLiu Zhe 		// Focus on edit pane
43732c31156SLiu Zhe 		draw.click(5, 5);
4387dd2b5bbSLiu Zhe 		sleep(1);
439b4d2d410SLiu Zhe 		assertFalse("Chart Editor appears", chart.exists());
440b4d2d410SLiu Zhe 		discard();
4417dd2b5bbSLiu Zhe 	}
44232c31156SLiu Zhe 
4437dd2b5bbSLiu Zhe 	/**
44432c31156SLiu Zhe 	 * Test insert a chart in a text document 1. New a text document 2. Insert a
44532c31156SLiu Zhe 	 * chart 3. Check if the chart is inserted successfully
44632c31156SLiu Zhe 	 *
4477dd2b5bbSLiu Zhe 	 * @throws Exception
4487dd2b5bbSLiu Zhe 	 */
4497dd2b5bbSLiu Zhe 	@Test
45032c31156SLiu Zhe 	public void testInsertChartInDocument() throws Exception {
4517dd2b5bbSLiu Zhe 		// Create a new text document
452b4d2d410SLiu Zhe 		newTextDocument();
4537dd2b5bbSLiu Zhe 		// Insert a chart
45432c31156SLiu Zhe 		app.dispatch(".uno:InsertObjectChart");
4557dd2b5bbSLiu Zhe 		sleep(3);
45632c31156SLiu Zhe 
4577dd2b5bbSLiu Zhe 		// Verify if the chart is inserted successfully
458b4d2d410SLiu Zhe 		assertTrue("Chart Editor appears", chart.exists(3));
4597dd2b5bbSLiu Zhe 		// Focus on edit pane
46032c31156SLiu Zhe 		writer.click(5, 5);
4617dd2b5bbSLiu Zhe 		sleep(1);
462b4d2d410SLiu Zhe 		assertFalse("Chart Editor appears", chart.exists());
463b4d2d410SLiu Zhe 		discard();
4647dd2b5bbSLiu Zhe 	}
46532c31156SLiu Zhe 
4667dd2b5bbSLiu Zhe 	/**
46732c31156SLiu Zhe 	 * Test insert a chart in a spreadsheet document 1. New a spreadsheet
46832c31156SLiu Zhe 	 * document 2. Insert a chart 3. Check if the chart is inserted successfully
46932c31156SLiu Zhe 	 *
4707dd2b5bbSLiu Zhe 	 * @throws Exception
4717dd2b5bbSLiu Zhe 	 */
4727dd2b5bbSLiu Zhe 	@Test
47332c31156SLiu Zhe 	public void testInsertChartInSpreadsheet() throws Exception {
4747dd2b5bbSLiu Zhe 		// Create a new spreadsheet document
475b4d2d410SLiu Zhe 		newSpreadsheet();
4767dd2b5bbSLiu Zhe 		// Insert a chart
47732c31156SLiu Zhe 		app.dispatch(".uno:InsertObjectChart");
4787dd2b5bbSLiu Zhe 		sleep(3);
479b4d2d410SLiu Zhe 		chartWizard.ok();
48032c31156SLiu Zhe 
4817dd2b5bbSLiu Zhe 		// Verify if the chart is inserted successfully
482b4d2d410SLiu Zhe 		assertTrue("Chart Editor appears", chart.exists(3));
4837dd2b5bbSLiu Zhe 		// Focus on edit pane
48432c31156SLiu Zhe 		calc.click(5, 5);
48532c31156SLiu Zhe 		sleep(1);
486b4d2d410SLiu Zhe 		assertFalse("Chart Editor appears", chart.exists());
487b4d2d410SLiu Zhe 		discard();
4887dd2b5bbSLiu Zhe 	}
48932c31156SLiu Zhe 
4907dd2b5bbSLiu Zhe 	/**
49132c31156SLiu Zhe 	 * Test insert a chart in a presentation document 1. New a presentation
49232c31156SLiu Zhe 	 * document 2. Insert a chart 3. Check if the chart is inserted successfully
49332c31156SLiu Zhe 	 *
4947dd2b5bbSLiu Zhe 	 * @throws Exception
4957dd2b5bbSLiu Zhe 	 */
4962aaec72aSLiu Zhe 	@Test
49732c31156SLiu Zhe 	public void testInsertChartInPresentation() throws Exception {
4987dd2b5bbSLiu Zhe 		// Create a new presentation document
499b4d2d410SLiu Zhe 		newPresentation();
5007dd2b5bbSLiu Zhe 		// Insert a chart
50132c31156SLiu Zhe 		app.dispatch(".uno:InsertObjectChart");
5027dd2b5bbSLiu Zhe 		sleep(3);
5037dd2b5bbSLiu Zhe 		// Verify if the chart is inserted successfully
504b4d2d410SLiu Zhe 		assertTrue("Chart Editor appears", chart.exists(3));
5057dd2b5bbSLiu Zhe 		// Focus on edit pane
50632c31156SLiu Zhe 		impress.click(5, 5);
50732c31156SLiu Zhe 		sleep(1);
508b4d2d410SLiu Zhe 		assertFalse("Chart Editor appears", chart.exists());
509b4d2d410SLiu Zhe 		discard();
5107dd2b5bbSLiu Zhe 	}
51132c31156SLiu Zhe 
5127dd2b5bbSLiu Zhe 	/**
51332c31156SLiu Zhe 	 * Test insert a table in a draw document 1. New a draw document 2. Insert a
51432c31156SLiu Zhe 	 * default table 3. Check if the table is inserted successfully
51532c31156SLiu Zhe 	 *
5167dd2b5bbSLiu Zhe 	 * @throws Exception
5177dd2b5bbSLiu Zhe 	 */
5187dd2b5bbSLiu Zhe 	@Test
51932c31156SLiu Zhe 	public void testInsertTableInDraw() throws Exception {
5207dd2b5bbSLiu Zhe 		// Create a new drawing document
521b4d2d410SLiu Zhe 		newDrawing();
5227dd2b5bbSLiu Zhe 		// Insert a table
52332c31156SLiu Zhe 		app.dispatch(".uno:InsertTable");
524b4d2d410SLiu Zhe 		insertTable.ok();
5257dd2b5bbSLiu Zhe 		sleep(1);
526b4d2d410SLiu Zhe 		draw.typeKeys("3");
527b4d2d410SLiu Zhe 		assertTrue("Table Toolbar appears", tableToolbar.exists(3));
528b4d2d410SLiu Zhe //		assertEquals("The cell content", "3", copyAll());
529b4d2d410SLiu Zhe 		discard();
5307dd2b5bbSLiu Zhe 	}
53132c31156SLiu Zhe 
5327dd2b5bbSLiu Zhe 	/**
53332c31156SLiu Zhe 	 * Test insert a table in a text document 1. New a text document 2. Insert a
53432c31156SLiu Zhe 	 * default table 3. Check if the table is inserted successfully
53532c31156SLiu Zhe 	 *
5367dd2b5bbSLiu Zhe 	 * @throws Exception
5377dd2b5bbSLiu Zhe 	 */
5387dd2b5bbSLiu Zhe 	@Test
53932c31156SLiu Zhe 	public void testInsertTableInDocument() throws Exception {
5407dd2b5bbSLiu Zhe 		// Create a new text document
541b4d2d410SLiu Zhe 		newTextDocument();
5427dd2b5bbSLiu Zhe 		// Insert a table
54332c31156SLiu Zhe 		app.dispatch(".uno:InsertTable");
544b4d2d410SLiu Zhe 		writerInsertTable.ok();
5457dd2b5bbSLiu Zhe 		sleep(1);
546b4d2d410SLiu Zhe 		writer.typeKeys("3");
547b4d2d410SLiu Zhe 		// Verify if the table toolbar is active
548b4d2d410SLiu Zhe 		assertTrue("Table Toolbar appears", tableToolbar.exists(3));
549b4d2d410SLiu Zhe //		assertEquals("The cell content", "3", copyAll());
550b4d2d410SLiu Zhe 		discard();
5517dd2b5bbSLiu Zhe 	}
55232c31156SLiu Zhe 
5537dd2b5bbSLiu Zhe 	/**
55432c31156SLiu Zhe 	 * Test insert a table in a presentation document 1. New a presentation
55532c31156SLiu Zhe 	 * document 2. Insert a default table 3. Check if the table is inserted
55632c31156SLiu Zhe 	 * successfully
55732c31156SLiu Zhe 	 *
5587dd2b5bbSLiu Zhe 	 * @throws Exception
5597dd2b5bbSLiu Zhe 	 */
5607dd2b5bbSLiu Zhe 	@Test
56132c31156SLiu Zhe 	public void testInsertTableInPresentation() throws Exception {
5627dd2b5bbSLiu Zhe 		// Create a new presentation document
563b4d2d410SLiu Zhe 		newPresentation();
56432c31156SLiu Zhe 
5657dd2b5bbSLiu Zhe 		// Insert a table
56632c31156SLiu Zhe 		app.dispatch(".uno:InsertTable");
567b4d2d410SLiu Zhe 		insertTable.ok();
5687dd2b5bbSLiu Zhe 		sleep(1);
569b4d2d410SLiu Zhe 		impress.typeKeys("3");
570b4d2d410SLiu Zhe 		assertTrue("Table Toolbar appears", tableToolbar.exists(3));
571b4d2d410SLiu Zhe //		assertEquals("The cell content", "3", copyAll());
572b4d2d410SLiu Zhe 		discard();
5737dd2b5bbSLiu Zhe 	}
5747dd2b5bbSLiu Zhe 
5757dd2b5bbSLiu Zhe 	/**
57632c31156SLiu Zhe 	 * Test insert a function in a spreadsheet document via Sum button 1. New a
57732c31156SLiu Zhe 	 * spreadsheet document 2. Insert a function via Sum button 3. Check if the
57832c31156SLiu Zhe 	 * result is correct
57932c31156SLiu Zhe 	 *
5807dd2b5bbSLiu Zhe 	 * @throws Exception
5817dd2b5bbSLiu Zhe 	 */
5827dd2b5bbSLiu Zhe 	@Test
583b4d2d410SLiu Zhe 	public void testSumInFormulaBar() throws Exception {
5847dd2b5bbSLiu Zhe 		// Create a new spreadsheet document
585b4d2d410SLiu Zhe 		newSpreadsheet();
5867dd2b5bbSLiu Zhe 		// Insert source numbers
5877dd2b5bbSLiu Zhe 		String sourceNumber1 = "5";
5887dd2b5bbSLiu Zhe 		String sourceNumber2 = "3";
5897dd2b5bbSLiu Zhe 		String expectedResult = "8";
590b4d2d410SLiu Zhe 		SCTool.selectRange("A1");
5917dd2b5bbSLiu Zhe 		typeKeys(sourceNumber1);
592b4d2d410SLiu Zhe 		SCTool.selectRange("B1");
59332c31156SLiu Zhe 		typeKeys(sourceNumber2);
5947dd2b5bbSLiu Zhe 		// Insert a function via Sum button
595b4d2d410SLiu Zhe 		SCTool.selectRange("C1");
596b4d2d410SLiu Zhe 		scInputBarSum.click();
5977dd2b5bbSLiu Zhe 		typeKeys("<enter>");
5987dd2b5bbSLiu Zhe 		// Verify if the calculated result is equal to the expected result
599b4d2d410SLiu Zhe 		assertEquals("The calculated result", expectedResult, SCTool.getCellText("C1"));
600b4d2d410SLiu Zhe 		discard();
6017dd2b5bbSLiu Zhe 	}
60232c31156SLiu Zhe 
6037dd2b5bbSLiu Zhe 	/**
60432c31156SLiu Zhe 	 * Test insert a function in a spreadsheet document via inputbar 1. New a
60532c31156SLiu Zhe 	 * spreadsheet document 2. Insert a function via inputbar: COS 3. Check if
60632c31156SLiu Zhe 	 * the result is correct
60732c31156SLiu Zhe 	 *
6087dd2b5bbSLiu Zhe 	 * @throws Exception
6097dd2b5bbSLiu Zhe 	 */
6107dd2b5bbSLiu Zhe 	@Test
611b4d2d410SLiu Zhe 	public void testInsertFunctionViaFormulaBar() throws Exception {
6127dd2b5bbSLiu Zhe 		// Create a new spreadsheet document
613b4d2d410SLiu Zhe 		newSpreadsheet();
6147dd2b5bbSLiu Zhe 		// Insert source numbers and expected result
61532c31156SLiu Zhe 		String sourceData = "0";
61632c31156SLiu Zhe 		String expectedResult = "1";
617b4d2d410SLiu Zhe 		SCTool.selectRange("A1");
61832c31156SLiu Zhe 		typeKeys(sourceData);
61932c31156SLiu Zhe 
62032c31156SLiu Zhe 		// Insert a function via inputbar: COS
621b4d2d410SLiu Zhe 		SCTool.selectRange("D1");
622b4d2d410SLiu Zhe 		scInputBarInput.inputKeys("=COS(A1)");
6237dd2b5bbSLiu Zhe 		typeKeys("<enter>");
62432c31156SLiu Zhe 
6257dd2b5bbSLiu Zhe 		// Verify if the calculated result is equal to the expected result
626b4d2d410SLiu Zhe 		assertEquals("The calculated result", expectedResult, SCTool.getCellText("D1"));
627b4d2d410SLiu Zhe 		discard();
6287dd2b5bbSLiu Zhe 	}
62932c31156SLiu Zhe 
6307dd2b5bbSLiu Zhe 	/**
63132c31156SLiu Zhe 	 * Test insert a function in a spreadsheet document via Function Wizard
63232c31156SLiu Zhe 	 * Dialog 1. New a spreadsheet document 2. Insert a function via Function
63332c31156SLiu Zhe 	 * Wizard Dialog: ABS 3. Check if the result is correct
63432c31156SLiu Zhe 	 *
6357dd2b5bbSLiu Zhe 	 * @throws Exception
6367dd2b5bbSLiu Zhe 	 */
6377dd2b5bbSLiu Zhe 	@Test
638b4d2d410SLiu Zhe 	public void testFunctionWizardInFormulaBar() throws Exception {
6397dd2b5bbSLiu Zhe 		// Create a new spreadsheet document
640b4d2d410SLiu Zhe 		newSpreadsheet();
6417dd2b5bbSLiu Zhe 		// Insert source number
6427dd2b5bbSLiu Zhe 		String sourceNumber = "-5";
6437dd2b5bbSLiu Zhe 		String expectedResult = "5";
644b4d2d410SLiu Zhe 		SCTool.selectRange("A1");
6457dd2b5bbSLiu Zhe 		typeKeys(sourceNumber);
6467dd2b5bbSLiu Zhe 		typeKeys("<enter>");
6477dd2b5bbSLiu Zhe 		// Insert a function via Function Wizard Dialog: ABS
648b4d2d410SLiu Zhe 		SCTool.selectRange("B1");
64932c31156SLiu Zhe 		app.dispatch(".uno:FunctionDialog");
65022a14f28SLiu Zhe 		// SC_FunctionWizardDlg_FunctionList.doubleClick(5, 5);
651b4d2d410SLiu Zhe 		scFunctionWizardDlgFunctionList.select("ABS");
652b4d2d410SLiu Zhe 		scFunctionWizardDlgNext.click(); // Use "Next" button
653b4d2d410SLiu Zhe 		scFunctionWizardDlgEdit1.inputKeys("A1");
654b4d2d410SLiu Zhe 		scFunctionWizardDlg.ok();
6557dd2b5bbSLiu Zhe 		// Verify if the calculated result is equal to the expected result
656b4d2d410SLiu Zhe 		assertEquals("The calculated result", expectedResult, SCTool.getCellText("B1"));
657b4d2d410SLiu Zhe 		discard();
6587dd2b5bbSLiu Zhe 	}
659faa4b864SLei De Bin }
660