xref: /AOO41X/test/testuno/source/fvt/mix/MixedTest.java (revision 7d4ea83aa08939be7d4f71ce802ba5b3d52ffbca)
107d7dbdcSHerbert Dürr /**************************************************************
207d7dbdcSHerbert Dürr  *
307d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
407d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
507d7dbdcSHerbert Dürr  * distributed with this work for additional information
607d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
707d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
807d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
907d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
1007d7dbdcSHerbert Dürr  *
1107d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
1207d7dbdcSHerbert Dürr  *
1307d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
1407d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
1507d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1607d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
1707d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
1807d7dbdcSHerbert Dürr  * under the License.
1907d7dbdcSHerbert Dürr  *
2007d7dbdcSHerbert Dürr  *************************************************************/
2107d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.mix;
23eba4d44aSLiu Zhe 
24eba4d44aSLiu Zhe import org.junit.After;
25eba4d44aSLiu Zhe import org.junit.Assert;
26eba4d44aSLiu Zhe import org.junit.Before;
27eba4d44aSLiu Zhe import org.junit.Test;
28eba4d44aSLiu Zhe import org.openoffice.test.OpenOffice;
29eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
30eba4d44aSLiu Zhe import org.openoffice.test.vcl.widgets.VclApp;
31eba4d44aSLiu Zhe import org.openoffice.test.vcl.widgets.VclListBox;
32eba4d44aSLiu Zhe import org.openoffice.test.vcl.widgets.VclTabPage;
33eba4d44aSLiu Zhe import org.openoffice.test.vcl.widgets.VclWindow;
34eba4d44aSLiu Zhe 
35eba4d44aSLiu Zhe import com.sun.star.beans.XPropertySet;
36eba4d44aSLiu Zhe import com.sun.star.text.XText;
37eba4d44aSLiu Zhe import com.sun.star.text.XTextCursor;
38eba4d44aSLiu Zhe import com.sun.star.text.XTextDocument;
39eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
40eba4d44aSLiu Zhe 
41eba4d44aSLiu Zhe /**
42eba4d44aSLiu Zhe  * Demo for testing with both UNO and VCLAuto
43eba4d44aSLiu Zhe  * @author test
44eba4d44aSLiu Zhe  *
45eba4d44aSLiu Zhe  */
46eba4d44aSLiu Zhe public class MixedTest {
47eba4d44aSLiu Zhe 	OpenOffice aoo;
48eba4d44aSLiu Zhe 	UnoApp unoApp;
49eba4d44aSLiu Zhe 	VclApp vclApp;
50eba4d44aSLiu Zhe 	VclWindow writer;
51eba4d44aSLiu Zhe 	VclTabPage effectsPage;
52eba4d44aSLiu Zhe 	VclListBox colorList;
53eba4d44aSLiu Zhe 	XTextDocument textDocument;
54eba4d44aSLiu Zhe 	/**
55eba4d44aSLiu Zhe 	 * @throws java.lang.Exception
56eba4d44aSLiu Zhe 	 */
57eba4d44aSLiu Zhe 	@Before
58eba4d44aSLiu Zhe 	public void setUp() throws Exception {
59*7d4ea83aSHerbert Dürr 		OpenOffice aoo = OpenOffice.getDefault();
60eba4d44aSLiu Zhe 		unoApp = new UnoApp(aoo);
61eba4d44aSLiu Zhe 		vclApp = new VclApp(aoo);
62eba4d44aSLiu Zhe 		writer = new VclWindow(vclApp, "SW_HID_EDIT_WIN");
63eba4d44aSLiu Zhe 		effectsPage = new VclTabPage(vclApp, "CUI_HID_SVXPAGE_CHAR_EFFECTS");
64eba4d44aSLiu Zhe 		colorList = new VclListBox(vclApp, "cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR");
65eba4d44aSLiu Zhe 		unoApp.start();
66eba4d44aSLiu Zhe 	}
67eba4d44aSLiu Zhe 
68eba4d44aSLiu Zhe 	@After
69eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
70eba4d44aSLiu Zhe 		unoApp.closeDocument(textDocument);
71eba4d44aSLiu Zhe 		unoApp.close();
72eba4d44aSLiu Zhe 	}
73eba4d44aSLiu Zhe 
74eba4d44aSLiu Zhe 	@Test
75eba4d44aSLiu Zhe 	public void testUseBothUNOAndGuiAPI()  throws Exception  {
76eba4d44aSLiu Zhe 		//Use UNO API to create a new document
77eba4d44aSLiu Zhe 		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter"));
78eba4d44aSLiu Zhe 		XText xText = textDocument.getText();
79eba4d44aSLiu Zhe 		xText.setString("UNO: Hello World!");
80eba4d44aSLiu Zhe 		//Input something by typing keyboard
81eba4d44aSLiu Zhe 		writer.typeKeys("GUI: Hello world!");
82eba4d44aSLiu Zhe 		//Set text color to green via GUI
83eba4d44aSLiu Zhe 		writer.drag(10, 10, 300, 400);
84eba4d44aSLiu Zhe 		writer.menuItem("Format->Character...").select();
85eba4d44aSLiu Zhe 		effectsPage.select();
86eba4d44aSLiu Zhe 		colorList.select("Light green");
87eba4d44aSLiu Zhe 		effectsPage.ok();
88eba4d44aSLiu Zhe 		//Verify the result via UNO API
89eba4d44aSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
90eba4d44aSLiu Zhe 		XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
91eba4d44aSLiu Zhe 		Assert.assertEquals("Text Color", 0x0000FF00, xps.getPropertyValue("CharColor"));
92eba4d44aSLiu Zhe 	}
93eba4d44aSLiu Zhe }
94