1*f5a7bb7cSJürgen Schmidt /************************************************************** 2*f5a7bb7cSJürgen Schmidt * 3*f5a7bb7cSJürgen Schmidt * Licensed to the Apache Software Foundation (ASF) under one 4*f5a7bb7cSJürgen Schmidt * or more contributor license agreements. See the NOTICE file 5*f5a7bb7cSJürgen Schmidt * distributed with this work for additional information 6*f5a7bb7cSJürgen Schmidt * regarding copyright ownership. The ASF licenses this file 7*f5a7bb7cSJürgen Schmidt * to you under the Apache License, Version 2.0 (the 8*f5a7bb7cSJürgen Schmidt * "License"); you may not use this file except in compliance 9*f5a7bb7cSJürgen Schmidt * with the License. You may obtain a copy of the License at 10*f5a7bb7cSJürgen Schmidt * 11*f5a7bb7cSJürgen Schmidt * http://www.apache.org/licenses/LICENSE-2.0 12*f5a7bb7cSJürgen Schmidt * 13*f5a7bb7cSJürgen Schmidt * Unless required by applicable law or agreed to in writing, 14*f5a7bb7cSJürgen Schmidt * software distributed under the License is distributed on an 15*f5a7bb7cSJürgen Schmidt * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f5a7bb7cSJürgen Schmidt * KIND, either express or implied. See the License for the 17*f5a7bb7cSJürgen Schmidt * specific language governing permissions and limitations 18*f5a7bb7cSJürgen Schmidt * under the License. 19*f5a7bb7cSJürgen Schmidt * 20*f5a7bb7cSJürgen Schmidt *************************************************************/ 211ff9903bSLi Feng Wang package fvt.uno.sw.frame; 221ff9903bSLi Feng Wang 231ff9903bSLi Feng Wang import static org.junit.Assert.*; 241ff9903bSLi Feng Wang 251ff9903bSLi Feng Wang import org.junit.After; 261ff9903bSLi Feng Wang import org.junit.Before; 271ff9903bSLi Feng Wang import org.junit.Test; 281ff9903bSLi Feng Wang import org.openoffice.test.common.Testspace; 291ff9903bSLi Feng Wang import org.openoffice.test.uno.UnoApp; 301ff9903bSLi Feng Wang 311ff9903bSLi Feng Wang import testlib.uno.SWUtil; 321ff9903bSLi Feng Wang 331ff9903bSLi Feng Wang import com.sun.star.uno.UnoRuntime; 341ff9903bSLi Feng Wang import com.sun.star.text.*; 351ff9903bSLi Feng Wang import com.sun.star.lang.XMultiServiceFactory; 361ff9903bSLi Feng Wang import com.sun.star.beans.XPropertySet; 371ff9903bSLi Feng Wang import com.sun.star.container.XNameAccess; 381ff9903bSLi Feng Wang 391ff9903bSLi Feng Wang 401ff9903bSLi Feng Wang public class FrameBorderSpacingtoContent { 411ff9903bSLi Feng Wang 421ff9903bSLi Feng Wang private static final UnoApp app = new UnoApp(); 431ff9903bSLi Feng Wang private XTextDocument xTextDocument=null; 441ff9903bSLi Feng Wang private XMultiServiceFactory xWriterFactory=null; 451ff9903bSLi Feng Wang private XText xText=null; 461ff9903bSLi Feng Wang @Before setUp()471ff9903bSLi Feng Wang public void setUp() throws Exception { 481ff9903bSLi Feng Wang app.start(); 491ff9903bSLi Feng Wang } 501ff9903bSLi Feng Wang 511ff9903bSLi Feng Wang @After tearDown()521ff9903bSLi Feng Wang public void tearDown() throws Exception { 531ff9903bSLi Feng Wang app.close(); 541ff9903bSLi Feng Wang } 551ff9903bSLi Feng Wang @Test testFrameBorderSpacingtoContent()561ff9903bSLi Feng Wang public void testFrameBorderSpacingtoContent() throws Exception { 571ff9903bSLi Feng Wang xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 581ff9903bSLi Feng Wang xText=xTextDocument.getText(); 591ff9903bSLi Feng Wang XTextCursor xTextCursor = xText.createTextCursor(); 601ff9903bSLi Feng Wang // get internal service factory of the document 611ff9903bSLi Feng Wang xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 621ff9903bSLi Feng Wang // Create a new table from the document's factory 631ff9903bSLi Feng Wang XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 641ff9903bSLi Feng Wang xText.insertTextContent(xTextCursor,xTextFrame,false); 651ff9903bSLi Feng Wang //set frame border spacing to content 661ff9903bSLi Feng Wang XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTextFrame); 671ff9903bSLi Feng Wang xCursorProps.setPropertyValue("LeftBorderDistance",499); 681ff9903bSLi Feng Wang xCursorProps.setPropertyValue("RightBorderDistance",499); 691ff9903bSLi Feng Wang xCursorProps.setPropertyValue("TopBorderDistance",499); 701ff9903bSLi Feng Wang xCursorProps.setPropertyValue("BottomBorderDistance",499); 711ff9903bSLi Feng Wang //reopen the document 721ff9903bSLi Feng Wang XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app)); 731ff9903bSLi Feng Wang XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt); 741ff9903bSLi Feng Wang XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 751ff9903bSLi Feng Wang Object xTextFrame_obj_odt=xTextFrames_odt.getByName("Frame1"); 761ff9903bSLi Feng Wang XTextFrame xTextFrame_Assert_odt=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_odt); 771ff9903bSLi Feng Wang XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTextFrame_Assert_odt); 781ff9903bSLi Feng Wang assertEquals("assert table border spacing to content",499,xCursorProps_assert_odt.getPropertyValue("LeftBorderDistance")); 791ff9903bSLi Feng Wang assertEquals("assert table border spacing to content",499,xCursorProps_assert_odt.getPropertyValue("RightBorderDistance")); 801ff9903bSLi Feng Wang assertEquals("assert table border spacing to content",499,xCursorProps_assert_odt.getPropertyValue("TopBorderDistance")); 811ff9903bSLi Feng Wang assertEquals("assert table border spacing to content",499,xCursorProps_assert_odt.getPropertyValue("BottomBorderDistance")); 821ff9903bSLi Feng Wang 831ff9903bSLi Feng Wang //reopen the document 841ff9903bSLi Feng Wang XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "MS Word 97",Testspace.getPath("output/test.doc"), app)); 851ff9903bSLi Feng Wang XTextFramesSupplier xTFS_doc = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_doc); 861ff9903bSLi Feng Wang XNameAccess xTextFrames_doc = xTFS_doc.getTextFrames(); 871ff9903bSLi Feng Wang Object xTextFrame_obj_doc=xTextFrames_doc.getByName("Frame1"); 881ff9903bSLi Feng Wang XTextFrame xTextFrame_Assert_doc=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_doc); 891ff9903bSLi Feng Wang XPropertySet xCursorProps_assert_doc = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTextFrame_Assert_doc); 901ff9903bSLi Feng Wang assertEquals("assert table border spacing to content",499,xCursorProps_assert_doc.getPropertyValue("LeftBorderDistance")); 911ff9903bSLi Feng Wang assertEquals("assert table border spacing to content",499,xCursorProps_assert_doc.getPropertyValue("RightBorderDistance")); 921ff9903bSLi Feng Wang assertEquals("assert table border spacing to content",499,xCursorProps_assert_doc.getPropertyValue("TopBorderDistance")); 931ff9903bSLi Feng Wang assertEquals("assert table border spacing to content",499,xCursorProps_assert_doc.getPropertyValue("BottomBorderDistance")); 941ff9903bSLi Feng Wang } 951ff9903bSLi Feng Wang } 961ff9903bSLi Feng Wang 97