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 package fvt.uno.sw.frame; 22 23 import static org.junit.Assert.*; 24 25 import java.util.Arrays; 26 import java.util.Collection; 27 28 import org.junit.After; 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.junit.runners.Parameterized; 33 import org.junit.runners.Parameterized.Parameters; 34 import org.openoffice.test.common.Testspace; 35 import org.openoffice.test.uno.UnoApp; 36 37 import testlib.uno.SWUtil; 38 39 import com.sun.star.beans.XPropertySet; 40 import com.sun.star.container.XNameAccess; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.text.XText; 43 import com.sun.star.text.XTextCursor; 44 import com.sun.star.text.XTextDocument; 45 import com.sun.star.text.XTextFrame; 46 import com.sun.star.text.XTextFramesSupplier; 47 import com.sun.star.uno.UnoRuntime; 48 @RunWith(value = Parameterized.class) 49 public class FrameAnchorType { 50 private static final UnoApp app = new UnoApp(); 51 private XTextDocument xTextDocument=null; 52 private XMultiServiceFactory xWriterFactory=null; 53 private XText xText=null; 54 private com.sun.star.text.TextContentAnchorType FrameAnchorType; FrameAnchorType(com.sun.star.text.TextContentAnchorType FrameAnchorType)55 public FrameAnchorType(com.sun.star.text.TextContentAnchorType FrameAnchorType){ 56 this.FrameAnchorType=FrameAnchorType; 57 } 58 @Parameters data()59 public static Collection<Object[]> data(){ 60 Object[][] params = new Object[][]{ 61 {com.sun.star.text.TextContentAnchorType.AS_CHARACTER}, 62 {com.sun.star.text.TextContentAnchorType.AT_CHARACTER}, 63 {com.sun.star.text.TextContentAnchorType.AT_PAGE}, 64 {com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH}, 65 }; 66 return Arrays.asList(params); 67 } 68 @Before setUp()69 public void setUp() throws Exception { 70 app.start(); 71 } 72 @After tearDown()73 public void tearDown() throws Exception { 74 app.close(); 75 } 76 77 @Test testFrameAnchorType()78 public void testFrameAnchorType() throws Exception { 79 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 80 xText=xTextDocument.getText(); 81 XTextCursor xTextCursor = xText.createTextCursor(); 82 // get internal service factory of the document 83 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 84 // Create a new table from the document's factory 85 XTextFrame xTextFrame1 = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 86 xText.insertTextContent(xTextCursor,xTextFrame1,false); 87 XPropertySet xTextFrameProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame1); 88 xTextFrameProps1.setPropertyValue("AnchorType",FrameAnchorType); 89 //reopen the document 90 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, SWUtil.saveTo_Override_reload(xTextDocument,"writer8", Testspace.getPath("output/test.odt"),app)); 91 XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt); 92 XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 93 XTextFrame xTextFrame_Assert1=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrames_odt.getByName("Frame1")); 94 XPropertySet xTextFrameProps_assert1 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert1); 95 assertEquals("assert shadow anchor type",FrameAnchorType,xTextFrameProps_assert1.getPropertyValue("AnchorType")); 96 } 97 } 98