1*07d7dbdcSHerbert Dürr /**************************************************************
2*07d7dbdcSHerbert Dürr  *
3*07d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
4*07d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
5*07d7dbdcSHerbert Dürr  * distributed with this work for additional information
6*07d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
7*07d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
8*07d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
9*07d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
10*07d7dbdcSHerbert Dürr  *
11*07d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
12*07d7dbdcSHerbert Dürr  *
13*07d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
14*07d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
15*07d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*07d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
17*07d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
18*07d7dbdcSHerbert Dürr  * under the License.
19*07d7dbdcSHerbert Dürr  *
20*07d7dbdcSHerbert Dürr  *************************************************************/
21*07d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
236194dbcdSLiu Zhe 
246194dbcdSLiu Zhe import static org.junit.Assert.*;
256194dbcdSLiu Zhe 
266194dbcdSLiu Zhe import org.junit.After;
276194dbcdSLiu Zhe import org.junit.Before;
286194dbcdSLiu Zhe import org.junit.Test;
296194dbcdSLiu Zhe import org.openoffice.test.common.FileUtil;
306194dbcdSLiu Zhe import org.openoffice.test.common.Testspace;
316194dbcdSLiu Zhe import org.openoffice.test.uno.UnoApp;
326194dbcdSLiu Zhe 
336194dbcdSLiu Zhe import com.sun.star.table.BorderLine;
346194dbcdSLiu Zhe import com.sun.star.text.*;
356194dbcdSLiu Zhe import com.sun.star.beans.*;
366194dbcdSLiu Zhe import com.sun.star.frame.XStorable;
376194dbcdSLiu Zhe import com.sun.star.uno.UnoRuntime;
386194dbcdSLiu Zhe 
396194dbcdSLiu Zhe public class ParagraphSpacingtoBorder {
406194dbcdSLiu Zhe 	private static final UnoApp app = new UnoApp();
416194dbcdSLiu Zhe 	XText xText = null;
426194dbcdSLiu Zhe 
436194dbcdSLiu Zhe 	@Before
setUp()446194dbcdSLiu Zhe 	public void setUp() throws Exception {
456194dbcdSLiu Zhe 		app.start();
466194dbcdSLiu Zhe 
476194dbcdSLiu Zhe 	}
486194dbcdSLiu Zhe 
496194dbcdSLiu Zhe 	@After
tearDown()506194dbcdSLiu Zhe 	public void tearDown() throws Exception {
516194dbcdSLiu Zhe 		app.close();
526194dbcdSLiu Zhe 	}
536194dbcdSLiu Zhe 	/*
546194dbcdSLiu Zhe 	 * test paragraph background color
556194dbcdSLiu Zhe 	 * 1.new a text document
566194dbcdSLiu Zhe 	 * 2.insert some text
576194dbcdSLiu Zhe 	 * 3.set paragraph border
586194dbcdSLiu Zhe 	 * 4.save and close the document
596194dbcdSLiu Zhe 	 * 5.reload the saved document and check the paragraph border
606194dbcdSLiu Zhe 	 */
616194dbcdSLiu Zhe 	@Test
testParagraphSpacingtoBorderSetting()626194dbcdSLiu Zhe 	public void testParagraphSpacingtoBorderSetting() throws Exception {
636194dbcdSLiu Zhe 
646194dbcdSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
656194dbcdSLiu Zhe 		xText = xTextDocument.getText();
666194dbcdSLiu Zhe 		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!" +
676194dbcdSLiu Zhe 				"Hello,world!Hello,world!");
686194dbcdSLiu Zhe 		// create text cursor for selecting and formatting text
696194dbcdSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
706194dbcdSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
716194dbcdSLiu Zhe 		BorderLine[]borderLine=new BorderLine[] {new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine()};
726194dbcdSLiu Zhe 		borderLine[0].Color=0x00FF0000;
736194dbcdSLiu Zhe 		borderLine[0].InnerLineWidth=101;
746194dbcdSLiu Zhe 		borderLine[0].OuterLineWidth=19;
756194dbcdSLiu Zhe 		borderLine[0].LineDistance=100;
766194dbcdSLiu Zhe 		borderLine[1].Color =0x00FFFF00;
776194dbcdSLiu Zhe 		borderLine[1].InnerLineWidth=101;
786194dbcdSLiu Zhe 		borderLine[1].OuterLineWidth=19;
796194dbcdSLiu Zhe 		borderLine[1].LineDistance=101;
806194dbcdSLiu Zhe 		borderLine[2].Color =0x0000FF00;
816194dbcdSLiu Zhe 		borderLine[2].InnerLineWidth=150;
826194dbcdSLiu Zhe 		borderLine[2].OuterLineWidth=19;
836194dbcdSLiu Zhe 		borderLine[2].LineDistance=101;
846194dbcdSLiu Zhe 		borderLine[3].Color =0x0000FF00;
856194dbcdSLiu Zhe 		borderLine[3].InnerLineWidth=150;
866194dbcdSLiu Zhe 		borderLine[3].OuterLineWidth=19;
876194dbcdSLiu Zhe 		borderLine[3].LineDistance=101;
886194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("LeftBorder", borderLine[0]);
896194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("RightBorder", borderLine[1]);
906194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("TopBorder", borderLine[2]);
916194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("BottomBorder", borderLine[3]);
926194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("LeftBorderDistance",499);
936194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("RightBorderDistance",499);
946194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("TopBorderDistance",499);
956194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("BottomBorderDistance",499);
966194dbcdSLiu Zhe 		//save to odt
976194dbcdSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
986194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
996194dbcdSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
1006194dbcdSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
1016194dbcdSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
1026194dbcdSLiu Zhe 		aStoreProperties_odt[0].Value = true;
1036194dbcdSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
1046194dbcdSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
1056194dbcdSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
1066194dbcdSLiu Zhe 		//save to doc
1076194dbcdSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1086194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
1096194dbcdSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
1106194dbcdSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
1116194dbcdSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
1126194dbcdSLiu Zhe 		aStoreProperties_doc[0].Value = true;
1136194dbcdSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
1146194dbcdSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
1156194dbcdSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
1166194dbcdSLiu Zhe 		app.closeDocument(xTextDocument);
1176194dbcdSLiu Zhe 
1186194dbcdSLiu Zhe 		//reopen the document
1196194dbcdSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
1206194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
1216194dbcdSLiu Zhe 		//verify paragraph border
1226194dbcdSLiu Zhe 		//verify paragraph border
1236194dbcdSLiu Zhe 		assertEquals("assert paragraph left border spacing",499,xCursorProps_Assert_odt.getPropertyValue("LeftBorderDistance"));
1246194dbcdSLiu Zhe 		assertEquals("assert paragraph right border spacing",499,xCursorProps_Assert_odt.getPropertyValue("RightBorderDistance"));
1256194dbcdSLiu Zhe 		assertEquals("assert paragraph top border spacing",499,xCursorProps_Assert_odt.getPropertyValue("TopBorderDistance"));
1266194dbcdSLiu Zhe 		assertEquals("assert paragraph bottom border spacing",499,xCursorProps_Assert_odt.getPropertyValue("BottomBorderDistance"));
1276194dbcdSLiu Zhe 
1286194dbcdSLiu Zhe 		//reopen the document
1296194dbcdSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
1306194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
1316194dbcdSLiu Zhe 		//verify paragraph border
1326194dbcdSLiu Zhe 		assertEquals("assert paragraph left border spacing",494,xCursorProps_Assert_doc.getPropertyValue("LeftBorderDistance"));
1336194dbcdSLiu Zhe 		assertEquals("assert paragraph right border spacing",494,xCursorProps_Assert_doc.getPropertyValue("RightBorderDistance"));
1346194dbcdSLiu Zhe 		assertEquals("assert paragraph top border spacing",494,xCursorProps_Assert_doc.getPropertyValue("TopBorderDistance"));
1356194dbcdSLiu Zhe 		assertEquals("assert paragraph bottom border spacing",494,xCursorProps_Assert_doc.getPropertyValue("BottomBorderDistance"));
1366194dbcdSLiu Zhe 
1376194dbcdSLiu Zhe 	}
1386194dbcdSLiu Zhe }
139