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 org.junit.After; 26 import org.junit.Before; 27 import org.junit.Test; 28 import org.openoffice.test.common.Testspace; 29 import org.openoffice.test.uno.UnoApp; 30 31 import testlib.uno.SWUtil; 32 33 import com.sun.star.beans.XPropertySet; 34 import com.sun.star.container.XNameAccess; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.table.BorderLine; 37 import com.sun.star.text.XText; 38 import com.sun.star.text.XTextCursor; 39 import com.sun.star.text.XTextDocument; 40 import com.sun.star.text.XTextFrame; 41 import com.sun.star.text.XTextFramesSupplier; 42 import com.sun.star.uno.UnoRuntime; 43 44 public class FrameBorder { 45 private static final UnoApp app = new UnoApp(); 46 private XTextDocument xTextDocument=null; 47 private XMultiServiceFactory xWriterFactory=null; 48 private XText xText=null; 49 @Before setUp()50 public void setUp() throws Exception { 51 app.start(); 52 } 53 54 @After tearDown()55 public void tearDown() throws Exception { 56 app.close(); 57 } 58 59 @Test testInsertFrame()60 public void testInsertFrame() throws Exception { 61 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 62 xText=xTextDocument.getText(); 63 XTextCursor xTextCursor = xText.createTextCursor(); 64 // get internal service factory of the document 65 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 66 // Create a new table from the document's factory 67 XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 68 xText.insertTextContent(xTextCursor,xTextFrame,false); 69 XPropertySet xTextFramerops = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame); 70 //set frame border 71 BorderLine[]borderLine=new BorderLine[] {new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine()}; 72 borderLine[0].Color=0x00FF0000; 73 borderLine[0].InnerLineWidth=101; 74 borderLine[0].OuterLineWidth=19; 75 borderLine[0].LineDistance=100; 76 borderLine[1].Color =0x00FFFF00; 77 borderLine[1].InnerLineWidth=101; 78 borderLine[1].OuterLineWidth=19; 79 borderLine[1].LineDistance=101; 80 borderLine[2].Color =0x0000FF00; 81 borderLine[2].InnerLineWidth=150; 82 borderLine[2].OuterLineWidth=19; 83 borderLine[2].LineDistance=101; 84 borderLine[3].Color =0x0000FF00; 85 borderLine[3].InnerLineWidth=150; 86 borderLine[3].OuterLineWidth=19; 87 borderLine[3].LineDistance=101; 88 xTextFramerops.setPropertyValue("LeftBorder", borderLine[0]); 89 xTextFramerops.setPropertyValue("RightBorder", borderLine[1]); 90 xTextFramerops.setPropertyValue("TopBorder", borderLine[2]); 91 xTextFramerops.setPropertyValue("BottomBorder", borderLine[3]); 92 //reopen the document 93 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, SWUtil.saveTo_Override_reload(xTextDocument,"writer8", Testspace.getPath("output/test.odt"),app)); 94 XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt); 95 XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 96 XPropertySet xFrameProps_Assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrames_odt.getByName("Frame1")); 97 BorderLine LeftBorder_Assert_odt=(BorderLine) UnoRuntime.queryInterface(BorderLine.class, xFrameProps_Assert_odt.getPropertyValue("LeftBorder")); 98 assertEquals("assert topline color as setting",0x00FF0000,LeftBorder_Assert_odt.Color); 99 assertEquals("assert topline innerline width as setting",101,LeftBorder_Assert_odt.InnerLineWidth); 100 assertEquals("assert topline outerlinewidth as setting",19,LeftBorder_Assert_odt.OuterLineWidth); 101 assertEquals("assert topline linedistance as setting",101,LeftBorder_Assert_odt.LineDistance); 102 BorderLine RightBorder_Assert_odt=(BorderLine) UnoRuntime.queryInterface(BorderLine.class, xFrameProps_Assert_odt.getPropertyValue("RightBorder")); 103 assertEquals("assert bottomline color as setting",0x00FFFF00,RightBorder_Assert_odt.Color); 104 assertEquals("assert bottomline innerline width as setting",101,RightBorder_Assert_odt.InnerLineWidth); 105 assertEquals("assert bottomline outerlinewidth as setting",19,RightBorder_Assert_odt.OuterLineWidth); 106 assertEquals("assert bottomline linedistance as setting",101,RightBorder_Assert_odt.LineDistance); 107 BorderLine TopBorder_Assert_odt=(BorderLine) UnoRuntime.queryInterface(BorderLine.class, xFrameProps_Assert_odt.getPropertyValue("TopBorder")); 108 assertEquals("assert leftline color as setting",0x0000FF00,TopBorder_Assert_odt.Color); 109 assertEquals("assert leftline innerline width as setting",150,TopBorder_Assert_odt.InnerLineWidth); 110 assertEquals("assert leftline outerlinewidth as setting",19,TopBorder_Assert_odt.OuterLineWidth); 111 assertEquals("assert leftline linedistance as setting",101,TopBorder_Assert_odt.LineDistance); 112 BorderLine BottomBorder_Assert_odt=(BorderLine) UnoRuntime.queryInterface(BorderLine.class, xFrameProps_Assert_odt.getPropertyValue("BottomBorder")); 113 assertEquals("assert rightline color as setting",0x0000FF00,BottomBorder_Assert_odt.Color); 114 assertEquals("assert rightline linedistance as setting",101,BottomBorder_Assert_odt.LineDistance); 115 assertEquals("assert rightline innerline width as setting",150,BottomBorder_Assert_odt.InnerLineWidth); 116 assertEquals("assert rightline outerlinewidth as setting",19,BottomBorder_Assert_odt.OuterLineWidth); 117 } 118 } 119