1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski package fvt.uno.sw.frame; 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski import static org.junit.Assert.*; 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski import org.junit.After; 26*b1cdbd2cSJim Jagielski import org.junit.Before; 27*b1cdbd2cSJim Jagielski import org.junit.Test; 28*b1cdbd2cSJim Jagielski import org.openoffice.test.common.Testspace; 29*b1cdbd2cSJim Jagielski import org.openoffice.test.uno.UnoApp; 30*b1cdbd2cSJim Jagielski 31*b1cdbd2cSJim Jagielski import testlib.uno.SWUtil; 32*b1cdbd2cSJim Jagielski 33*b1cdbd2cSJim Jagielski import com.sun.star.beans.XPropertySet; 34*b1cdbd2cSJim Jagielski import com.sun.star.container.XNameAccess; 35*b1cdbd2cSJim Jagielski import com.sun.star.lang.XMultiServiceFactory; 36*b1cdbd2cSJim Jagielski import com.sun.star.text.XText; 37*b1cdbd2cSJim Jagielski import com.sun.star.text.XTextCursor; 38*b1cdbd2cSJim Jagielski import com.sun.star.text.XTextDocument; 39*b1cdbd2cSJim Jagielski import com.sun.star.text.XTextFrame; 40*b1cdbd2cSJim Jagielski import com.sun.star.text.XTextFramesSupplier; 41*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 42*b1cdbd2cSJim Jagielski 43*b1cdbd2cSJim Jagielski public class FrameBackColor { 44*b1cdbd2cSJim Jagielski private static final UnoApp app = new UnoApp(); 45*b1cdbd2cSJim Jagielski private XTextDocument xTextDocument=null; 46*b1cdbd2cSJim Jagielski private XMultiServiceFactory xWriterFactory=null; 47*b1cdbd2cSJim Jagielski private XText xText=null; 48*b1cdbd2cSJim Jagielski @Before setUp()49*b1cdbd2cSJim Jagielski public void setUp() throws Exception { 50*b1cdbd2cSJim Jagielski app.start(); 51*b1cdbd2cSJim Jagielski } 52*b1cdbd2cSJim Jagielski 53*b1cdbd2cSJim Jagielski @After tearDown()54*b1cdbd2cSJim Jagielski public void tearDown() throws Exception { 55*b1cdbd2cSJim Jagielski app.close(); 56*b1cdbd2cSJim Jagielski } 57*b1cdbd2cSJim Jagielski 58*b1cdbd2cSJim Jagielski @Test testFrameBackColor()59*b1cdbd2cSJim Jagielski public void testFrameBackColor() throws Exception { 60*b1cdbd2cSJim Jagielski xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 61*b1cdbd2cSJim Jagielski xText=xTextDocument.getText(); 62*b1cdbd2cSJim Jagielski XTextCursor xTextCursor = xText.createTextCursor(); 63*b1cdbd2cSJim Jagielski // get internal service factory of the document 64*b1cdbd2cSJim Jagielski xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 65*b1cdbd2cSJim Jagielski // Create a new table from the document's factory 66*b1cdbd2cSJim Jagielski XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 67*b1cdbd2cSJim Jagielski xText.insertTextContent(xTextCursor,xTextFrame,false); 68*b1cdbd2cSJim Jagielski XPropertySet xFrameProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame); 69*b1cdbd2cSJim Jagielski xFrameProps.setPropertyValue("BackColor",0x0000FF00); 70*b1cdbd2cSJim Jagielski //reopen the document 71*b1cdbd2cSJim Jagielski XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app)); 72*b1cdbd2cSJim Jagielski XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt); 73*b1cdbd2cSJim Jagielski XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 74*b1cdbd2cSJim Jagielski Object xTextFrame_obj_odt=xTextFrames_odt.getByName("Frame1"); 75*b1cdbd2cSJim Jagielski XTextFrame xTextFrame_Assert_odt=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_odt); 76*b1cdbd2cSJim Jagielski XPropertySet xFrameProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert_odt); 77*b1cdbd2cSJim Jagielski assertEquals("verify Frame background color",0x0000FF00,xFrameProps_assert_odt.getPropertyValue("BackColor")); 78*b1cdbd2cSJim Jagielski 79*b1cdbd2cSJim Jagielski //reopen the document 80*b1cdbd2cSJim Jagielski XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "MS Word 97",Testspace.getPath("output/test.doc"), app)); 81*b1cdbd2cSJim Jagielski XTextFramesSupplier xTFS_doc = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_doc); 82*b1cdbd2cSJim Jagielski XNameAccess xTextFrames_doc = xTFS_doc.getTextFrames(); 83*b1cdbd2cSJim Jagielski Object xTextFrame_obj_doc=xTextFrames_doc.getByName("Frame1"); 84*b1cdbd2cSJim Jagielski XTextFrame xTextFrame_Assert_doc=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_doc); 85*b1cdbd2cSJim Jagielski XPropertySet xFrameProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert_doc); 86*b1cdbd2cSJim Jagielski assertEquals("verify frame background color",0x0000FF00,xFrameProps_assert_doc.getPropertyValue("BackColor")); 87*b1cdbd2cSJim Jagielski } 88*b1cdbd2cSJim Jagielski } 89