1 package testcase.uno.sw.paragraph;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Test;
8 import org.openoffice.test.common.FileUtil;
9 import org.openoffice.test.common.Testspace;
10 import org.openoffice.test.uno.UnoApp;
11 
12 import com.sun.star.table.BorderLine;
13 import com.sun.star.text.*;
14 import com.sun.star.beans.*;
15 import com.sun.star.frame.XStorable;
16 import com.sun.star.uno.UnoRuntime;
17 
18 public class ParagraphSpacingtoBorder {
19 	private static final UnoApp app = new UnoApp();
20 	XText xText = null;
21 
22 	@Before
23 	public void setUp() throws Exception {
24 		app.start();
25 
26 	}
27 
28 	@After
29 	public void tearDown() throws Exception {
30 		app.close();
31 	}
32 	/*
33 	 * test paragraph background color
34 	 * 1.new a text document
35 	 * 2.insert some text
36 	 * 3.set paragraph border
37 	 * 4.save and close the document
38 	 * 5.reload the saved document and check the paragraph border
39 	 */
40 	@Test
41 	public void testParagraphSpacingtoBorderSetting() throws Exception {
42 
43 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
44 		xText = xTextDocument.getText();
45 		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!" +
46 				"Hello,world!Hello,world!");
47 		// create text cursor for selecting and formatting text
48 		XTextCursor xTextCursor = xText.createTextCursor();
49 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
50 		BorderLine[]borderLine=new BorderLine[] {new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine()};
51 		borderLine[0].Color=0x00FF0000;
52 		borderLine[0].InnerLineWidth=101;
53 		borderLine[0].OuterLineWidth=19;
54 		borderLine[0].LineDistance=100;
55 		borderLine[1].Color =0x00FFFF00;
56 		borderLine[1].InnerLineWidth=101;
57 		borderLine[1].OuterLineWidth=19;
58 		borderLine[1].LineDistance=101;
59 		borderLine[2].Color =0x0000FF00;
60 		borderLine[2].InnerLineWidth=150;
61 		borderLine[2].OuterLineWidth=19;
62 		borderLine[2].LineDistance=101;
63 		borderLine[3].Color =0x0000FF00;
64 		borderLine[3].InnerLineWidth=150;
65 		borderLine[3].OuterLineWidth=19;
66 		borderLine[3].LineDistance=101;
67 		xCursorProps.setPropertyValue("LeftBorder", borderLine[0]);
68 		xCursorProps.setPropertyValue("RightBorder", borderLine[1]);
69 		xCursorProps.setPropertyValue("TopBorder", borderLine[2]);
70 		xCursorProps.setPropertyValue("BottomBorder", borderLine[3]);
71 		xCursorProps.setPropertyValue("LeftBorderDistance",499);
72 		xCursorProps.setPropertyValue("RightBorderDistance",499);
73 		xCursorProps.setPropertyValue("TopBorderDistance",499);
74 		xCursorProps.setPropertyValue("BottomBorderDistance",499);
75 		//save to odt
76 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
77 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
78 		aStoreProperties_odt[0] = new PropertyValue();
79 		aStoreProperties_odt[1] = new PropertyValue();
80 		aStoreProperties_odt[0].Name = "Override";
81 		aStoreProperties_odt[0].Value = true;
82 		aStoreProperties_odt[1].Name = "FilterName";
83 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
84 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
85 		//save to doc
86 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
87 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
88 		aStoreProperties_doc[0] = new PropertyValue();
89 		aStoreProperties_doc[1] = new PropertyValue();
90 		aStoreProperties_doc[0].Name = "Override";
91 		aStoreProperties_doc[0].Value = true;
92 		aStoreProperties_doc[1].Name = "FilterName";
93 		aStoreProperties_doc[1].Value = "MS Word 97";
94 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
95 		app.closeDocument(xTextDocument);
96 
97 		//reopen the document
98 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
99 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
100 		//verify paragraph border
101 		//verify paragraph border
102 		assertEquals("assert paragraph left border spacing",499,xCursorProps_Assert_odt.getPropertyValue("LeftBorderDistance"));
103 		assertEquals("assert paragraph right border spacing",499,xCursorProps_Assert_odt.getPropertyValue("RightBorderDistance"));
104 		assertEquals("assert paragraph top border spacing",499,xCursorProps_Assert_odt.getPropertyValue("TopBorderDistance"));
105 		assertEquals("assert paragraph bottom border spacing",499,xCursorProps_Assert_odt.getPropertyValue("BottomBorderDistance"));
106 
107 		//reopen the document
108 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
109 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
110 		//verify paragraph border
111 		assertEquals("assert paragraph left border spacing",494,xCursorProps_Assert_doc.getPropertyValue("LeftBorderDistance"));
112 		assertEquals("assert paragraph right border spacing",494,xCursorProps_Assert_doc.getPropertyValue("RightBorderDistance"));
113 		assertEquals("assert paragraph top border spacing",494,xCursorProps_Assert_doc.getPropertyValue("TopBorderDistance"));
114 		assertEquals("assert paragraph bottom border spacing",494,xCursorProps_Assert_doc.getPropertyValue("BottomBorderDistance"));
115 
116 	}
117 }
118