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.uno.UnoRuntime;
34 import com.sun.star.text.*;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.beans.XPropertySet;
37 import com.sun.star.container.XNameAccess;
38 
39 
40 public class FrameBorderSpacingtoContent {
41 
42 	private static final UnoApp app = new UnoApp();
43 	private XTextDocument xTextDocument=null;
44 	private XMultiServiceFactory xWriterFactory=null;
45 	private XText xText=null;
46 	@Before
setUp()47 	public void setUp() throws Exception {
48 		app.start();
49 	}
50 
51 	@After
tearDown()52 	public void tearDown() throws Exception {
53 		app.close();
54 	}
55 	@Test
testFrameBorderSpacingtoContent()56 	public void testFrameBorderSpacingtoContent() throws Exception {
57 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
58 		xText=xTextDocument.getText();
59 		XTextCursor xTextCursor = xText.createTextCursor();
60 		// get internal service factory of the document
61 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
62 		// Create a new table from the document's factory
63 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
64 		xText.insertTextContent(xTextCursor,xTextFrame,false);
65 		//set frame border spacing to content
66 		XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTextFrame);
67 		xCursorProps.setPropertyValue("LeftBorderDistance",499);
68 		xCursorProps.setPropertyValue("RightBorderDistance",499);
69 		xCursorProps.setPropertyValue("TopBorderDistance",499);
70 		xCursorProps.setPropertyValue("BottomBorderDistance",499);
71 		//reopen the document
72 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
73 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
74 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
75 		Object xTextFrame_obj_odt=xTextFrames_odt.getByName("Frame1");
76 		XTextFrame xTextFrame_Assert_odt=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_odt);
77 		XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTextFrame_Assert_odt);
78 		assertEquals("assert table border spacing to content",499,xCursorProps_assert_odt.getPropertyValue("LeftBorderDistance"));
79 		assertEquals("assert table border spacing to content",499,xCursorProps_assert_odt.getPropertyValue("RightBorderDistance"));
80 		assertEquals("assert table border spacing to content",499,xCursorProps_assert_odt.getPropertyValue("TopBorderDistance"));
81 		assertEquals("assert table border spacing to content",499,xCursorProps_assert_odt.getPropertyValue("BottomBorderDistance"));
82 
83 		//reopen the document
84 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "MS Word 97",Testspace.getPath("output/test.doc"), app));
85 		XTextFramesSupplier xTFS_doc = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_doc);
86 		XNameAccess xTextFrames_doc = xTFS_doc.getTextFrames();
87 		Object xTextFrame_obj_doc=xTextFrames_doc.getByName("Frame1");
88 		XTextFrame xTextFrame_Assert_doc=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrame_obj_doc);
89 		XPropertySet xCursorProps_assert_doc = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTextFrame_Assert_doc);
90 		assertEquals("assert table border spacing to content",499,xCursorProps_assert_doc.getPropertyValue("LeftBorderDistance"));
91 		assertEquals("assert table border spacing to content",499,xCursorProps_assert_doc.getPropertyValue("RightBorderDistance"));
92 		assertEquals("assert table border spacing to content",499,xCursorProps_assert_doc.getPropertyValue("TopBorderDistance"));
93 		assertEquals("assert table border spacing to content",499,xCursorProps_assert_doc.getPropertyValue("BottomBorderDistance"));
94 	}
95 }
96 
97