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 
22 package fvt.uno.sw.paragraph;
23 
24 import static org.junit.Assert.*;
25 
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.openoffice.test.common.FileUtil;
30 import org.openoffice.test.common.Testspace;
31 import org.openoffice.test.uno.UnoApp;
32 
33 import com.sun.star.table.BorderLine;
34 import com.sun.star.text.*;
35 import com.sun.star.beans.*;
36 import com.sun.star.frame.XStorable;
37 import com.sun.star.uno.UnoRuntime;
38 
39 public class ParagraphSpacingtoBorder {
40 	private static final UnoApp app = new UnoApp();
41 	XText xText = null;
42 
43 	@Before
setUp()44 	public void setUp() throws Exception {
45 		app.start();
46 
47 	}
48 
49 	@After
tearDown()50 	public void tearDown() throws Exception {
51 		app.close();
52 	}
53 	/*
54 	 * test paragraph background color
55 	 * 1.new a text document
56 	 * 2.insert some text
57 	 * 3.set paragraph border
58 	 * 4.save and close the document
59 	 * 5.reload the saved document and check the paragraph border
60 	 */
61 	@Test
testParagraphSpacingtoBorderSetting()62 	public void testParagraphSpacingtoBorderSetting() throws Exception {
63 
64 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
65 		xText = xTextDocument.getText();
66 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
67 				"Hello,world!Hello,world!");
68 		// create text cursor for selecting and formatting text
69 		XTextCursor xTextCursor = xText.createTextCursor();
70 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
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 		xCursorProps.setPropertyValue("LeftBorder", borderLine[0]);
89 		xCursorProps.setPropertyValue("RightBorder", borderLine[1]);
90 		xCursorProps.setPropertyValue("TopBorder", borderLine[2]);
91 		xCursorProps.setPropertyValue("BottomBorder", borderLine[3]);
92 		xCursorProps.setPropertyValue("LeftBorderDistance",499);
93 		xCursorProps.setPropertyValue("RightBorderDistance",499);
94 		xCursorProps.setPropertyValue("TopBorderDistance",499);
95 		xCursorProps.setPropertyValue("BottomBorderDistance",499);
96 		//save to odt
97 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
98 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
99 		aStoreProperties_odt[0] = new PropertyValue();
100 		aStoreProperties_odt[1] = new PropertyValue();
101 		aStoreProperties_odt[0].Name = "Override";
102 		aStoreProperties_odt[0].Value = true;
103 		aStoreProperties_odt[1].Name = "FilterName";
104 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
105 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
106 		//save to doc
107 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
108 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
109 		aStoreProperties_doc[0] = new PropertyValue();
110 		aStoreProperties_doc[1] = new PropertyValue();
111 		aStoreProperties_doc[0].Name = "Override";
112 		aStoreProperties_doc[0].Value = true;
113 		aStoreProperties_doc[1].Name = "FilterName";
114 		aStoreProperties_doc[1].Value = "MS Word 97";
115 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
116 		app.closeDocument(xTextDocument);
117 
118 		//reopen the document
119 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
120 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
121 		//verify paragraph border
122 		//verify paragraph border
123 		assertEquals("assert paragraph left border spacing",499,xCursorProps_Assert_odt.getPropertyValue("LeftBorderDistance"));
124 		assertEquals("assert paragraph right border spacing",499,xCursorProps_Assert_odt.getPropertyValue("RightBorderDistance"));
125 		assertEquals("assert paragraph top border spacing",499,xCursorProps_Assert_odt.getPropertyValue("TopBorderDistance"));
126 		assertEquals("assert paragraph bottom border spacing",499,xCursorProps_Assert_odt.getPropertyValue("BottomBorderDistance"));
127 
128 		//reopen the document
129 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
130 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
131 		//verify paragraph border
132 		assertEquals("assert paragraph left border spacing",494,xCursorProps_Assert_doc.getPropertyValue("LeftBorderDistance"));
133 		assertEquals("assert paragraph right border spacing",494,xCursorProps_Assert_doc.getPropertyValue("RightBorderDistance"));
134 		assertEquals("assert paragraph top border spacing",494,xCursorProps_Assert_doc.getPropertyValue("TopBorderDistance"));
135 		assertEquals("assert paragraph bottom border spacing",494,xCursorProps_Assert_doc.getPropertyValue("BottomBorderDistance"));
136 
137 	}
138 }
139