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