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; 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 { 5957caf934SLiu Zhe OpenOffice aoo = new OpenOffice(); 6057caf934SLiu Zhe aoo.setAutomationPort(OpenOffice.DEFAULT_AUTOMATION_PORT); 6157caf934SLiu Zhe aoo.setUnoUrl(OpenOffice.DEFAULT_UNO_URL); 6257caf934SLiu Zhe unoApp = new UnoApp(aoo); 6357caf934SLiu Zhe vclApp = new VclApp(aoo); 6457caf934SLiu Zhe writer = new VclWindow(vclApp, "SW_HID_EDIT_WIN"); 6557caf934SLiu Zhe effectsPage = new VclTabPage(vclApp, "CUI_HID_SVXPAGE_CHAR_EFFECTS"); 6657caf934SLiu Zhe colorList = new VclListBox(vclApp, "cui:ListBox:RID_SVXPAGE_CHAR_EFFECTS:LB_FONTCOLOR"); 6733a969aaSLiu Zhe unoApp.start(); 6833a969aaSLiu Zhe } 6933a969aaSLiu Zhe 7033a969aaSLiu Zhe @After 7133a969aaSLiu Zhe public void tearDown() throws Exception { 7233a969aaSLiu Zhe unoApp.closeDocument(textDocument); 7333a969aaSLiu Zhe unoApp.close(); 7433a969aaSLiu Zhe } 7533a969aaSLiu Zhe 7633a969aaSLiu Zhe @Test 7733a969aaSLiu Zhe public void testUseBothUNOAndGuiAPI() throws Exception { 7833a969aaSLiu Zhe //Use UNO API to create a new document 7933a969aaSLiu Zhe textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, unoApp.newDocument("swriter")); 8033a969aaSLiu Zhe XText xText = textDocument.getText(); 8133a969aaSLiu Zhe xText.setString("UNO: Hello World!"); 8233a969aaSLiu Zhe //Input something by typing keyboard 8333a969aaSLiu Zhe writer.typeKeys("GUI: Hello world!"); 8433a969aaSLiu Zhe //Set text color to green via GUI 8533a969aaSLiu Zhe writer.drag(10, 10, 300, 400); 8633a969aaSLiu Zhe writer.menuItem("Format->Character...").select(); 8733a969aaSLiu Zhe effectsPage.select(); 8833a969aaSLiu Zhe colorList.select("Light green"); 8933a969aaSLiu Zhe effectsPage.ok(); 9033a969aaSLiu Zhe //Verify the result via UNO API 9133a969aaSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 9233a969aaSLiu Zhe XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 9333a969aaSLiu Zhe Assert.assertEquals("Text Color", 0x0000FF00, xps.getPropertyValue("CharColor")); 9433a969aaSLiu Zhe } 9533a969aaSLiu Zhe } 96