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 setUp()58 public void setUp() throws Exception { 59 OpenOffice aoo = OpenOffice.getDefault(); 60 unoApp = new UnoApp(aoo); 61 vclApp = new VclApp(aoo); 62 writer = new VclWindow(vclApp, "SW_HID_EDIT_WIN"); 63 effectsPage = new VclTabPage(vclApp, "CUI_HID_SVXPAGE_CHAR_EFFECTS"); 64 colorList = new VclListBox(vclApp, "cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR"); 65 unoApp.start(); 66 } 67 68 @After tearDown()69 public void tearDown() throws Exception { 70 unoApp.closeDocument(textDocument); 71 unoApp.close(); 72 } 73 74 @Test testUseBothUNOAndGuiAPI()75 public void testUseBothUNOAndGuiAPI() throws Exception { 76 //Use UNO API to create a new document 77 textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter")); 78 XText xText = textDocument.getText(); 79 xText.setString("UNO: Hello World!"); 80 //Input something by typing keyboard 81 writer.typeKeys("GUI: Hello world!"); 82 //Set text color to green via GUI 83 writer.drag(10, 10, 300, 400); 84 writer.menuItem("Format->Character...").select(); 85 effectsPage.select(); 86 colorList.select("Green 3"); 87 effectsPage.ok(); 88 //Verify the result via UNO API 89 XTextCursor xTextCursor = xText.createTextCursor(); 90 XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 91 Assert.assertEquals("Text Color", 0x00CC00, xps.getPropertyValue("CharColor")); 92 } 93 } 94