xref: /trunk/test/testuno/source/fvt/mix/MixedTest.java (revision 07d7dbdc)
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 package fvt.mix;
23 
24 import org.junit.After;
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.openoffice.test.OpenOffice;
29 import org.openoffice.test.uno.UnoApp;
30 import org.openoffice.test.vcl.widgets.VclApp;
31 import org.openoffice.test.vcl.widgets.VclListBox;
32 import org.openoffice.test.vcl.widgets.VclTabPage;
33 import org.openoffice.test.vcl.widgets.VclWindow;
34 
35 import com.sun.star.beans.XPropertySet;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextCursor;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.uno.UnoRuntime;
40 
41 /**
42  * Demo for testing with both UNO and VCLAuto
43  * @author test
44  *
45  */
46 public class MixedTest {
47 	OpenOffice aoo;
48 	UnoApp unoApp;
49 	VclApp vclApp;
50 	VclWindow writer;
51 	VclTabPage effectsPage;
52 	VclListBox colorList;
53 	XTextDocument textDocument;
54 	/**
55 	 * @throws java.lang.Exception
56 	 */
57 	@Before
58 	public void setUp() throws Exception {
59 		OpenOffice aoo = new OpenOffice();
60 		aoo.setAutomationPort(OpenOffice.DEFAULT_AUTOMATION_PORT);
61 		aoo.setUnoUrl(OpenOffice.DEFAULT_UNO_URL);
62 		unoApp = new UnoApp(aoo);
63 		vclApp = new VclApp(aoo);
64 		writer = new VclWindow(vclApp, "SW_HID_EDIT_WIN");
65 		effectsPage = new VclTabPage(vclApp, "CUI_HID_SVXPAGE_CHAR_EFFECTS");
66 		colorList = new VclListBox(vclApp, "cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR");
67 		unoApp.start();
68 	}
69 
70 	@After
71 	public void tearDown() throws Exception {
72 		unoApp.closeDocument(textDocument);
73 		unoApp.close();
74 	}
75 
76 	@Test
77 	public void testUseBothUNOAndGuiAPI()  throws Exception  {
78 		//Use UNO API to create a new document
79 		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter"));
80 		XText xText = textDocument.getText();
81 		xText.setString("UNO: Hello World!");
82 		//Input something by typing keyboard
83 		writer.typeKeys("GUI: Hello world!");
84 		//Set text color to green via GUI
85 		writer.drag(10, 10, 300, 400);
86 		writer.menuItem("Format->Character...").select();
87 		effectsPage.select();
88 		colorList.select("Light green");
89 		effectsPage.ok();
90 		//Verify the result via UNO API
91 		XTextCursor xTextCursor = xText.createTextCursor();
92 		XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
93 		Assert.assertEquals("Text Color", 0x0000FF00, xps.getPropertyValue("CharColor"));
94 	}
95 }
96