xref: /trunk/test/testuno/source/fvt/mix/MixedTest.java (revision 57caf934)
1 package testcase.mix;
2 
3 import org.junit.After;
4 import org.junit.Assert;
5 import org.junit.Before;
6 import org.junit.Test;
7 import org.openoffice.test.OpenOffice;
8 import org.openoffice.test.uno.UnoApp;
9 import org.openoffice.test.vcl.widgets.VclApp;
10 import org.openoffice.test.vcl.widgets.VclListBox;
11 import org.openoffice.test.vcl.widgets.VclTabPage;
12 import org.openoffice.test.vcl.widgets.VclWindow;
13 
14 import com.sun.star.beans.XPropertySet;
15 import com.sun.star.text.XText;
16 import com.sun.star.text.XTextCursor;
17 import com.sun.star.text.XTextDocument;
18 import com.sun.star.uno.UnoRuntime;
19 
20 /**
21  * Demo for testing with both UNO and VCLAuto
22  * @author test
23  *
24  */
25 public class MixedTest {
26 	OpenOffice aoo;
27 	UnoApp unoApp;
28 	VclApp vclApp;
29 	VclWindow writer;
30 	VclTabPage effectsPage;
31 	VclListBox colorList;
32 	XTextDocument textDocument;
33 	/**
34 	 * @throws java.lang.Exception
35 	 */
36 	@Before
37 	public void setUp() throws Exception {
38 		OpenOffice aoo = new OpenOffice();
39 		aoo.setAutomationPort(OpenOffice.DEFAULT_AUTOMATION_PORT);
40 		aoo.setUnoUrl(OpenOffice.DEFAULT_UNO_URL);
41 		unoApp = new UnoApp(aoo);
42 		vclApp = new VclApp(aoo);
43 		writer = new VclWindow(vclApp, "SW_HID_EDIT_WIN");
44 		effectsPage = new VclTabPage(vclApp, "CUI_HID_SVXPAGE_CHAR_EFFECTS");
45 		colorList = new VclListBox(vclApp, "cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR");
46 		unoApp.start();
47 	}
48 
49 	@After
50 	public void tearDown() throws Exception {
51 		unoApp.closeDocument(textDocument);
52 		unoApp.close();
53 	}
54 
55 	@Test
56 	public void testUseBothUNOAndGuiAPI()  throws Exception  {
57 		//Use UNO API to create a new document
58 		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter"));
59 		XText xText = textDocument.getText();
60 		xText.setString("UNO: Hello World!");
61 		//Input something by typing keyboard
62 		writer.typeKeys("GUI: Hello world!");
63 		//Set text color to green via GUI
64 		writer.drag(10, 10, 300, 400);
65 		writer.menuItem("Format->Character...").select();
66 		effectsPage.select();
67 		colorList.select("Light green");
68 		effectsPage.ok();
69 		//Verify the result via UNO API
70 		XTextCursor xTextCursor = xText.createTextCursor();
71 		XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
72 		Assert.assertEquals("Text Color", 0x0000FF00, xps.getPropertyValue("CharColor"));
73 	}
74 }
75