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.AfterClass; 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.junit.runners.Parameterized; 34 import org.junit.runners.Parameterized.Parameters; 35 import org.openoffice.test.common.Testspace; 36 import org.openoffice.test.uno.UnoApp; 37 38 import testlib.uno.SWUtil; 39 40 import com.sun.star.beans.XPropertySet; 41 import com.sun.star.container.XNameAccess; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.text.WrapTextMode; 44 import com.sun.star.text.XText; 45 import com.sun.star.text.XTextCursor; 46 import com.sun.star.text.XTextDocument; 47 import com.sun.star.text.XTextFrame; 48 import com.sun.star.text.XTextFramesSupplier; 49 import com.sun.star.uno.UnoRuntime; 50 @RunWith(value = Parameterized.class) 51 public class FrameWrapType { 52 private static final UnoApp app = new UnoApp(); 53 private XTextDocument xTextDocument=null; 54 private XMultiServiceFactory xWriterFactory=null; 55 private XText xText=null; 56 private int FrameWrapType; FrameWrapType(int FrameWrapType)57 public FrameWrapType(int FrameWrapType){ 58 this.FrameWrapType=FrameWrapType; 59 } 60 /* 61 * 0:NONE 62 * 1:THROUGHT 63 * 2:PARALLEL 64 * 3:DYNAMIC 65 * 4:LEFT 66 * 5:RIGHT 67 */ 68 @Parameters data()69 public static Collection<Object[]> data(){ 70 Object[][] params = new Object[][]{ 71 {0},{1},{2},{3},{4},{5}, 72 }; 73 return Arrays.asList(params); 74 } 75 @Before setUp()76 public void setUp() throws Exception { 77 app.start(); 78 } 79 80 @After tearDown()81 public void tearDown() throws Exception { 82 app.close(); 83 } 84 85 @Test testFrameAnchorType()86 public void testFrameAnchorType() throws Exception { 87 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 88 xText=xTextDocument.getText(); 89 XTextCursor xTextCursor = xText.createTextCursor(); 90 // get internal service factory of the document 91 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 92 // Create a new table from the document's factory 93 XTextFrame xTextFrame1 = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 94 xText.insertTextContent(xTextCursor,xTextFrame1,false); 95 XPropertySet xTextFrameProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame1); 96 xTextFrameProps1.setPropertyValue("Surround",FrameWrapType); 97 //reopen the document 98 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, SWUtil.saveTo_Override_reload(xTextDocument,"writer8", Testspace.getPath("output/test.odt"),app)); 99 XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt); 100 XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 101 XTextFrame xTextFrame_Assert1=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrames_odt.getByName("Frame1")); 102 XPropertySet xTextFrameProps_assert1 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert1); 103 WrapTextMode surrond=(WrapTextMode)UnoRuntime.queryInterface(WrapTextMode.class,xTextFrameProps_assert1.getPropertyValue("Surround")); 104 assertEquals("assert frame wrap type",FrameWrapType,surrond.getValue()); 105 } 106 } 107