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;
2333a969aaSLiu Zhe 
2433a969aaSLiu Zhe import org.junit.After;
2533a969aaSLiu Zhe import org.junit.Assert;
2633a969aaSLiu Zhe import org.junit.Before;
2733a969aaSLiu Zhe import org.junit.Test;
2857caf934SLiu Zhe import org.openoffice.test.OpenOffice;
2933a969aaSLiu Zhe import org.openoffice.test.uno.UnoApp;
30f0480a3dSLiu Zhe import org.openoffice.test.vcl.widgets.VclApp;
3133a969aaSLiu Zhe import org.openoffice.test.vcl.widgets.VclListBox;
3233a969aaSLiu Zhe import org.openoffice.test.vcl.widgets.VclTabPage;
3333a969aaSLiu Zhe import org.openoffice.test.vcl.widgets.VclWindow;
3433a969aaSLiu Zhe 
3533a969aaSLiu Zhe import com.sun.star.beans.XPropertySet;
3633a969aaSLiu Zhe import com.sun.star.text.XText;
3733a969aaSLiu Zhe import com.sun.star.text.XTextCursor;
3833a969aaSLiu Zhe import com.sun.star.text.XTextDocument;
3933a969aaSLiu Zhe import com.sun.star.uno.UnoRuntime;
4033a969aaSLiu Zhe 
4133a969aaSLiu Zhe /**
4233a969aaSLiu Zhe  * Demo for testing with both UNO and VCLAuto
4333a969aaSLiu Zhe  * @author test
4433a969aaSLiu Zhe  *
4533a969aaSLiu Zhe  */
4633a969aaSLiu Zhe public class MixedTest {
4757caf934SLiu Zhe 	OpenOffice aoo;
4857caf934SLiu Zhe 	UnoApp unoApp;
4957caf934SLiu Zhe 	VclApp vclApp;
5057caf934SLiu Zhe 	VclWindow writer;
5157caf934SLiu Zhe 	VclTabPage effectsPage;
5257caf934SLiu Zhe 	VclListBox colorList;
5357caf934SLiu Zhe 	XTextDocument textDocument;
5433a969aaSLiu Zhe 	/**
5533a969aaSLiu Zhe 	 * @throws java.lang.Exception
5633a969aaSLiu Zhe 	 */
5733a969aaSLiu Zhe 	@Before
5833a969aaSLiu Zhe 	public void setUp() throws Exception {
59*7d4ea83aSHerbert Dürr 		OpenOffice aoo = OpenOffice.getDefault();
6057caf934SLiu Zhe 		unoApp = new UnoApp(aoo);
6157caf934SLiu Zhe 		vclApp = new VclApp(aoo);
6257caf934SLiu Zhe 		writer = new VclWindow(vclApp, "SW_HID_EDIT_WIN");
6357caf934SLiu Zhe 		effectsPage = new VclTabPage(vclApp, "CUI_HID_SVXPAGE_CHAR_EFFECTS");
6457caf934SLiu Zhe 		colorList = new VclListBox(vclApp, "cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR");
6533a969aaSLiu Zhe 		unoApp.start();
6633a969aaSLiu Zhe 	}
6733a969aaSLiu Zhe 
6833a969aaSLiu Zhe 	@After
6933a969aaSLiu Zhe 	public void tearDown() throws Exception {
7033a969aaSLiu Zhe 		unoApp.closeDocument(textDocument);
7133a969aaSLiu Zhe 		unoApp.close();
7233a969aaSLiu Zhe 	}
7333a969aaSLiu Zhe 
7433a969aaSLiu Zhe 	@Test
7533a969aaSLiu Zhe 	public void testUseBothUNOAndGuiAPI()  throws Exception  {
7633a969aaSLiu Zhe 		//Use UNO API to create a new document
7733a969aaSLiu Zhe 		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter"));
7833a969aaSLiu Zhe 		XText xText = textDocument.getText();
7933a969aaSLiu Zhe 		xText.setString("UNO: Hello World!");
8033a969aaSLiu Zhe 		//Input something by typing keyboard
8133a969aaSLiu Zhe 		writer.typeKeys("GUI: Hello world!");
8233a969aaSLiu Zhe 		//Set text color to green via GUI
8333a969aaSLiu Zhe 		writer.drag(10, 10, 300, 400);
8433a969aaSLiu Zhe 		writer.menuItem("Format->Character...").select();
8533a969aaSLiu Zhe 		effectsPage.select();
8633a969aaSLiu Zhe 		colorList.select("Light green");
8733a969aaSLiu Zhe 		effectsPage.ok();
8833a969aaSLiu Zhe 		//Verify the result via UNO API
8933a969aaSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
9033a969aaSLiu Zhe 		XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
9133a969aaSLiu Zhe 		Assert.assertEquals("Text Color", 0x0000FF00, xps.getPropertyValue("CharColor"));
9233a969aaSLiu Zhe 	}
9333a969aaSLiu Zhe }
94