1*07d7dbdcSHerbert Dürr /************************************************************** 2*07d7dbdcSHerbert Dürr * 3*07d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 4*07d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 5*07d7dbdcSHerbert Dürr * distributed with this work for additional information 6*07d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 7*07d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 8*07d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 9*07d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 10*07d7dbdcSHerbert Dürr * 11*07d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 12*07d7dbdcSHerbert Dürr * 13*07d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 14*07d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 15*07d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*07d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 17*07d7dbdcSHerbert Dürr * specific language governing permissions and limitations 18*07d7dbdcSHerbert Dürr * under the License. 19*07d7dbdcSHerbert Dürr * 20*07d7dbdcSHerbert Dürr *************************************************************/ 21*07d7dbdcSHerbert 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 { 59eba4d44aSLiu Zhe OpenOffice aoo = new OpenOffice(); 60eba4d44aSLiu Zhe aoo.setAutomationPort(OpenOffice.DEFAULT_AUTOMATION_PORT); 61eba4d44aSLiu Zhe aoo.setUnoUrl(OpenOffice.DEFAULT_UNO_URL); 62eba4d44aSLiu Zhe unoApp = new UnoApp(aoo); 63eba4d44aSLiu Zhe vclApp = new VclApp(aoo); 64eba4d44aSLiu Zhe writer = new VclWindow(vclApp, "SW_HID_EDIT_WIN"); 65eba4d44aSLiu Zhe effectsPage = new VclTabPage(vclApp, "CUI_HID_SVXPAGE_CHAR_EFFECTS"); 66eba4d44aSLiu Zhe colorList = new VclListBox(vclApp, "cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR"); 67eba4d44aSLiu Zhe unoApp.start(); 68eba4d44aSLiu Zhe } 69eba4d44aSLiu Zhe 70eba4d44aSLiu Zhe @After 71eba4d44aSLiu Zhe public void tearDown() throws Exception { 72eba4d44aSLiu Zhe unoApp.closeDocument(textDocument); 73eba4d44aSLiu Zhe unoApp.close(); 74eba4d44aSLiu Zhe } 75eba4d44aSLiu Zhe 76eba4d44aSLiu Zhe @Test 77eba4d44aSLiu Zhe public void testUseBothUNOAndGuiAPI() throws Exception { 78eba4d44aSLiu Zhe //Use UNO API to create a new document 79eba4d44aSLiu Zhe textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter")); 80eba4d44aSLiu Zhe XText xText = textDocument.getText(); 81eba4d44aSLiu Zhe xText.setString("UNO: Hello World!"); 82eba4d44aSLiu Zhe //Input something by typing keyboard 83eba4d44aSLiu Zhe writer.typeKeys("GUI: Hello world!"); 84eba4d44aSLiu Zhe //Set text color to green via GUI 85eba4d44aSLiu Zhe writer.drag(10, 10, 300, 400); 86eba4d44aSLiu Zhe writer.menuItem("Format->Character...").select(); 87eba4d44aSLiu Zhe effectsPage.select(); 88eba4d44aSLiu Zhe colorList.select("Light green"); 89eba4d44aSLiu Zhe effectsPage.ok(); 90eba4d44aSLiu Zhe //Verify the result via UNO API 91eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 92eba4d44aSLiu Zhe XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 93eba4d44aSLiu Zhe Assert.assertEquals("Text Color", 0x0000FF00, xps.getPropertyValue("CharColor")); 94eba4d44aSLiu Zhe } 95eba4d44aSLiu Zhe } 96