xref: /trunk/test/testuno/source/fvt/mix/MixedTest.java (revision 33a969aa)
1 package testcase.uno;
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.uno.UnoApp;
8 import org.openoffice.test.vcl.widgets.VclListBox;
9 import org.openoffice.test.vcl.widgets.VclTabPage;
10 import org.openoffice.test.vcl.widgets.VclWindow;
11 
12 import com.sun.star.beans.XPropertySet;
13 import com.sun.star.frame.XComponentLoader;
14 import com.sun.star.lang.XComponent;
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 	UnoApp unoApp = new UnoApp();
27 	VclWindow writer = new VclWindow("SW_HID_EDIT_WIN");
28 	VclTabPage effectsPage = new VclTabPage("CUI_HID_SVXPAGE_CHAR_EFFECTS");
29 	VclListBox colorList = new VclListBox("cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR");
30 	XTextDocument textDocument = null;
31 	/**
32 	 * @throws java.lang.Exception
33 	 */
34 	@Before
35 	public void setUp() throws Exception {
36 		unoApp.start();
37 	}
38 
39 	@After
40 	public void tearDown() throws Exception {
41 		unoApp.closeDocument(textDocument);
42 		unoApp.close();
43 	}
44 
45 	@Test
46 	public void testUseBothUNOAndGuiAPI()  throws Exception  {
47 		//Use UNO API to create a new document
48 		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter"));
49 		XText xText = textDocument.getText();
50 		xText.setString("UNO: Hello World!");
51 		//Input something by typing keyboard
52 		writer.typeKeys("GUI: Hello world!");
53 		//Set text color to green via GUI
54 		writer.drag(10, 10, 300, 400);
55 		writer.menuItem("Format->Character...").select();
56 		effectsPage.select();
57 		colorList.select("Light green");
58 		effectsPage.ok();
59 		//Verify the result via UNO API
60 		XTextCursor xTextCursor = xText.createTextCursor();
61 		XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
62 		Assert.assertEquals("Text Color", 0x0000FF00, xps.getPropertyValue("CharColor"));
63 	}
64 }
65