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.Ignore;
29 import org.junit.Test;
30 import org.openoffice.test.common.FileUtil;
31 import org.openoffice.test.common.Testspace;
32 import org.openoffice.test.uno.UnoApp;
33 //import org.openoffice.test.vcl.Tester.*;
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 import com.sun.star.style.*;
39 
40 public class ParagraphLineSpacing {
41 	private static final UnoApp app = new UnoApp();
42 	XText xText = null;
43 
44 	@Before
setUp()45 	public void setUp() throws Exception {
46 		app.start();
47 
48 	}
49 
50 	@After
tearDown()51 	public void tearDown() throws Exception {
52 		app.close();
53 	}
54 	/*
55 	 * test paragraph line spacing is fix
56 	 * 1.new a text document
57 	 * 2.insert some text
58 	 * 3.set paragraph line spacing is fix
59 	 * 4.save and close the document
60 	 * 5.reload the saved document and check the paragraph line spacing
61 	 */
62 	@Test
testParagraphLineSpacingFix()63 	public void testParagraphLineSpacingFix() throws Exception {
64 
65 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
66 		xText = xTextDocument.getText();
67 		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!" +
68 				"Hello,world!Hello,world!");
69 		// create text cursor for selecting and formatting text
70 		XTextCursor xTextCursor = xText.createTextCursor();
71 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
72 		//set paragraph line spacing
73 		LineSpacing lineSpacing = new LineSpacing();
74 		lineSpacing.Mode = LineSpacingMode.FIX;
75 		lineSpacing.Height = 5000;
76 		xCursorProps.setPropertyValue("ParaLineSpacing",lineSpacing);
77 		//save to odt
78 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
79 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
80 		aStoreProperties_odt[0] = new PropertyValue();
81 		aStoreProperties_odt[1] = new PropertyValue();
82 		aStoreProperties_odt[0].Name = "Override";
83 		aStoreProperties_odt[0].Value = true;
84 		aStoreProperties_odt[1].Name = "FilterName";
85 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
86 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
87 		//save to doc
88 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
89 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
90 		aStoreProperties_doc[0] = new PropertyValue();
91 		aStoreProperties_doc[1] = new PropertyValue();
92 		aStoreProperties_doc[0].Name = "Override";
93 		aStoreProperties_doc[0].Value = true;
94 		aStoreProperties_doc[1].Name = "FilterName";
95 		aStoreProperties_doc[1].Value = "MS Word 97";
96 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
97 		app.closeDocument(xTextDocument);
98 
99 		//reopen the document and assert paragraph line spacing
100 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
101 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_odt.getText().createTextCursor());
102 		LineSpacing paraLineSpacing_assert_odt=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_odt.getPropertyValue("ParaLineSpacing"));
103 		assertEquals("assert first paragraph line spacing is fix",LineSpacingMode.FIX,paraLineSpacing_assert_odt.Mode);
104 		assertEquals("assert first paragraph line spacing is fix",5001,paraLineSpacing_assert_odt.Height);
105 
106 		//reopen the document and assert paragraph line spacing
107 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
108 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_doc.getText().createTextCursor());
109 		LineSpacing paraLineSpacing_assert_doc=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_doc.getPropertyValue("ParaLineSpacing"));
110 		assertEquals("assert first paragraph line spacing is fix",LineSpacingMode.FIX,paraLineSpacing_assert_doc.Mode);
111 		assertEquals("assert first paragraph line spacing is fix",5001,paraLineSpacing_assert_doc.Height);
112 	}
113 	/*
114 	 * test paragraph line spacing is leading
115 	 * 1.new a text document
116 	 * 2.insert some text
117 	 * 3.set paragraph line spacing is leading
118 	 * 4.save and close the document
119 	 * 5.reload the saved document and check the paragraph line spacing
120 	 */
121 	@Test@Ignore("Bug #120647 - [testUNO patch]line spacing leading setting change to at least when save to doc")
testParagraphLineSpacingLeading()122 	public void testParagraphLineSpacingLeading() throws Exception {
123 
124 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
125 		xText = xTextDocument.getText();
126 		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!" +
127 				"Hello,world!Hello,world!");
128 		// create text cursor for selecting and formatting text
129 		XTextCursor xTextCursor = xText.createTextCursor();
130 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
131 		//set paragraph line spacing
132 		LineSpacing lineSpacing = new LineSpacing();
133 		lineSpacing.Mode = LineSpacingMode.LEADING;
134 		lineSpacing.Height = 5000;
135 		xCursorProps.setPropertyValue("ParaLineSpacing",lineSpacing);
136 		//save to odt
137 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
138 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
139 		aStoreProperties_odt[0] = new PropertyValue();
140 		aStoreProperties_odt[1] = new PropertyValue();
141 		aStoreProperties_odt[0].Name = "Override";
142 		aStoreProperties_odt[0].Value = true;
143 		aStoreProperties_odt[1].Name = "FilterName";
144 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
145 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
146 		//save to doc
147 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
148 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
149 		aStoreProperties_doc[0] = new PropertyValue();
150 		aStoreProperties_doc[1] = new PropertyValue();
151 		aStoreProperties_doc[0].Name = "Override";
152 		aStoreProperties_doc[0].Value = true;
153 		aStoreProperties_doc[1].Name = "FilterName";
154 		aStoreProperties_doc[1].Value = "MS Word 97";
155 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
156 		app.closeDocument(xTextDocument);
157 
158 		//reopen the document
159 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
160 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_odt.getText().createTextCursor());
161 		LineSpacing paraLineSpacing_assert_odt=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_odt.getPropertyValue("ParaLineSpacing"));
162 		//verify paragraph line spacing property
163 		assertEquals("assert first paragraph line spacing is fix",LineSpacingMode.LEADING,paraLineSpacing_assert_odt.Mode);
164 		assertEquals("assert first paragraph line spacing is fix",5001,paraLineSpacing_assert_odt.Height);
165 
166 		//reopen the document
167 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
168 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_doc.getText().createTextCursor());
169 		LineSpacing paraLineSpacing_assert_doc=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_doc.getPropertyValue("ParaLineSpacing"));
170 		//verify paragraph line spacing property
171 		assertEquals("assert first paragraph line spacing is fix",LineSpacingMode.LEADING,paraLineSpacing_assert_doc.Mode);
172 		assertEquals("assert first paragraph line spacing is fix",5001,paraLineSpacing_assert_doc.Height);
173 	}
174 	/*
175 	 * test paragraph line spacing is minimum
176 	 * 1.new a text document
177 	 * 2.insert some text
178 	 * 3.set paragraph line spacing is minimum
179 	 * 4.save and close the document
180 	 * 5.reload the saved document and check the paragraph line spacing
181 	 */
182 	@Test
testParagraphLineSpacingMinimum()183 	public void testParagraphLineSpacingMinimum() throws Exception {
184 
185 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
186 		xText = xTextDocument.getText();
187 		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!" +
188 				"Hello,world!Hello,world!");
189 		// create text cursor for selecting and formatting text
190 		XTextCursor xTextCursor = xText.createTextCursor();
191 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
192 		//set paragraph line spacing
193 		LineSpacing lineSpacing = new LineSpacing();
194 		lineSpacing.Mode = LineSpacingMode.MINIMUM;
195 		lineSpacing.Height = 5000;
196 		xCursorProps.setPropertyValue("ParaLineSpacing",lineSpacing);
197 		//save to odt
198 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
199 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
200 		aStoreProperties_odt[0] = new PropertyValue();
201 		aStoreProperties_odt[1] = new PropertyValue();
202 		aStoreProperties_odt[0].Name = "Override";
203 		aStoreProperties_odt[0].Value = true;
204 		aStoreProperties_odt[1].Name = "FilterName";
205 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
206 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
207 		//save to doc
208 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
209 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
210 		aStoreProperties_doc[0] = new PropertyValue();
211 		aStoreProperties_doc[1] = new PropertyValue();
212 		aStoreProperties_doc[0].Name = "Override";
213 		aStoreProperties_doc[0].Value = true;
214 		aStoreProperties_doc[1].Name = "FilterName";
215 		aStoreProperties_doc[1].Value = "MS Word 97";
216 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
217 		app.closeDocument(xTextDocument);
218 
219 		//reopen the document
220 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
221 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_odt.getText().createTextCursor());
222 		LineSpacing paraLineSpacing_assert_odt=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_odt.getPropertyValue("ParaLineSpacing"));
223 		//verify paragraph line spacing property
224 		assertEquals("assert first paragraph line spacing is fix",LineSpacingMode.MINIMUM,paraLineSpacing_assert_odt.Mode);
225 		assertEquals("assert first paragraph line spacing is fix",5001,paraLineSpacing_assert_odt.Height);
226 
227 		//reopen the document
228 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
229 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_doc.getText().createTextCursor());
230 		LineSpacing paraLineSpacing_assert_doc=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_doc.getPropertyValue("ParaLineSpacing"));
231 		//verify paragraph line spacing property
232 		assertEquals("assert first paragraph line spacing is fix",LineSpacingMode.MINIMUM,paraLineSpacing_assert_doc.Mode);
233 		assertEquals("assert first paragraph line spacing is fix",5001,paraLineSpacing_assert_doc.Height);
234 	}
235 	/*
236 	 * test paragraph line spacing is prop
237 	 * 1.new a text document
238 	 * 2.insert some text
239 	 * 3.set paragraph alignment is prop
240 	 * 4.save and close the document
241 	 * 5.reload the saved document and check the paragraph line spacing
242 	 */
243 	@Test
testParagraphLineSpacingProp()244 	public void testParagraphLineSpacingProp() throws Exception {
245 
246 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
247 		xText = xTextDocument.getText();
248 		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!" +
249 				"Hello,world!Hello,world!");
250 		// create text cursor for selecting and formatting text
251 		XTextCursor xTextCursor = xText.createTextCursor();
252 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
253 		//set paragraph line spacing
254 		LineSpacing lineSpacing = new LineSpacing();
255 		lineSpacing.Mode = LineSpacingMode.PROP;
256 		lineSpacing.Height = 150;
257 		xCursorProps.setPropertyValue("ParaLineSpacing",lineSpacing);
258 		//save to odt
259 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
260 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
261 		aStoreProperties_odt[0] = new PropertyValue();
262 		aStoreProperties_odt[1] = new PropertyValue();
263 		aStoreProperties_odt[0].Name = "Override";
264 		aStoreProperties_odt[0].Value = true;
265 		aStoreProperties_odt[1].Name = "FilterName";
266 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
267 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
268 		//save to doc
269 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
270 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
271 		aStoreProperties_doc[0] = new PropertyValue();
272 		aStoreProperties_doc[1] = new PropertyValue();
273 		aStoreProperties_doc[0].Name = "Override";
274 		aStoreProperties_doc[0].Value = true;
275 		aStoreProperties_doc[1].Name = "FilterName";
276 		aStoreProperties_doc[1].Value = "MS Word 97";
277 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
278 		app.closeDocument(xTextDocument);
279 
280 		//reopen the document
281 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
282 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_odt.getText().createTextCursor());
283 		LineSpacing paraLineSpacing_assert_odt=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_odt.getPropertyValue("ParaLineSpacing"));
284 		//verify paragraph line spacing property
285 		assertEquals("assert line spacing is prop",LineSpacingMode.PROP,paraLineSpacing_assert_odt.Mode);
286 		assertEquals("assert line spacing height is 150",150,paraLineSpacing_assert_odt.Height);
287 
288 		//reopen the document
289 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
290 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_doc.getText().createTextCursor());
291 		LineSpacing paraLineSpacing_assert_doc=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_doc.getPropertyValue("ParaLineSpacing"));
292 		//verify paragraph line spacing property
293 		assertEquals("assert line spacing is prop",LineSpacingMode.PROP,paraLineSpacing_assert_doc.Mode);
294 		assertEquals("assert line spacing height is 150",150,paraLineSpacing_assert_doc.Height);
295 	}
296 	/*
297 	 * test paragraph line spacing is single
298 	 * 1.new a text document
299 	 * 2.insert some text
300 	 * 3.set paragraph line spacing is single
301 	 * 4.save and close the document
302 	 * 5.reload the saved document and check the paragraph line spacing
303 	 */
304 	@Test@Ignore("Bug #120649 - [testUNO patch]single line spacing change to at least of 0.07 when save to doc")
testParagraphLineSpacingSingle()305 	public void testParagraphLineSpacingSingle() throws Exception {
306 
307 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
308 		xText = xTextDocument.getText();
309 		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!" +
310 				"Hello,world!Hello,world!");
311 		// create text cursor for selecting and formatting text
312 		XTextCursor xTextCursor = xText.createTextCursor();
313 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
314 		//set paragraph line spacing
315 		LineSpacing lineSpacing = new LineSpacing();
316 		lineSpacing.Height = 100;
317 		xCursorProps.setPropertyValue("ParaLineSpacing",lineSpacing);
318 		//save to odt
319 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
320 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
321 		aStoreProperties_odt[0] = new PropertyValue();
322 		aStoreProperties_odt[1] = new PropertyValue();
323 		aStoreProperties_odt[0].Name = "Override";
324 		aStoreProperties_odt[0].Value = true;
325 		aStoreProperties_odt[1].Name = "FilterName";
326 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
327 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
328 		//save to doc
329 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
330 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
331 		aStoreProperties_doc[0] = new PropertyValue();
332 		aStoreProperties_doc[1] = new PropertyValue();
333 		aStoreProperties_doc[0].Name = "Override";
334 		aStoreProperties_doc[0].Value = true;
335 		aStoreProperties_doc[1].Name = "FilterName";
336 		aStoreProperties_doc[1].Value = "MS Word 97";
337 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
338 		app.closeDocument(xTextDocument);
339 
340 		//reopen the document
341 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
342 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_odt.getText().createTextCursor());
343 		LineSpacing paraLineSpacing_assert_odt=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_odt.getPropertyValue("ParaLineSpacing"));
344 		//verify paragraph line spacing property
345 		assertEquals("assert first paragraph line spacing is single",100,paraLineSpacing_assert_odt.Height);
346 
347 		//reopen the document
348 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
349 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_doc.getText().createTextCursor());
350 		LineSpacing paraLineSpacing_assert_doc=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_doc.getPropertyValue("ParaLineSpacing"));
351 		//verify paragraph line spacing property
352 		assertEquals("assert first paragraph line spacing is single",100,paraLineSpacing_assert_doc.Height);
353 	}
354 	/*
355 	 * test paragraph line spacing is double
356 	 * 1.new a text document
357 	 * 2.insert some text
358 	 * 3.set paragraph line spacing is double
359 	 * 4.save and close the document
360 	 * 5.reload the saved document and check the paragraph line spacing
361 	 */
362 	@Test
testParagraphLineSpacingDouble()363 	public void testParagraphLineSpacingDouble() throws Exception {
364 
365 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
366 		xText = xTextDocument.getText();
367 		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!" +
368 				"Hello,world!Hello,world!");
369 		// create text cursor for selecting and formatting text
370 		XTextCursor xTextCursor = xText.createTextCursor();
371 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
372 		//set paragraph line spacing
373 		LineSpacing lineSpacing = new LineSpacing();
374 		lineSpacing.Height = 200;
375 		xCursorProps.setPropertyValue("ParaLineSpacing",lineSpacing);
376 		//save to odt
377 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
378 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
379 		aStoreProperties_odt[0] = new PropertyValue();
380 		aStoreProperties_odt[1] = new PropertyValue();
381 		aStoreProperties_odt[0].Name = "Override";
382 		aStoreProperties_odt[0].Value = true;
383 		aStoreProperties_odt[1].Name = "FilterName";
384 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
385 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
386 		//save to doc
387 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
388 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
389 		aStoreProperties_doc[0] = new PropertyValue();
390 		aStoreProperties_doc[1] = new PropertyValue();
391 		aStoreProperties_doc[0].Name = "Override";
392 		aStoreProperties_doc[0].Value = true;
393 		aStoreProperties_doc[1].Name = "FilterName";
394 		aStoreProperties_doc[1].Value = "MS Word 97";
395 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
396 		app.closeDocument(xTextDocument);
397 
398 		//reopen the document and assert line spacing
399 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
400 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_odt.getText().createTextCursor());
401 		LineSpacing paraLineSpacing_assert_odt=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_odt.getPropertyValue("ParaLineSpacing"));
402 		//verify paragraph line spacing property
403 		assertEquals("assert first paragraph line spacing is single",200,paraLineSpacing_assert_odt.Height);
404 
405 		//reopen the document and assert line spacing
406 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
407 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_doc.getText().createTextCursor());
408 		LineSpacing paraLineSpacing_assert_doc=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_doc.getPropertyValue("ParaLineSpacing"));
409 		//verify paragraph line spacing property
410 		assertEquals("assert first paragraph line spacing is single",200,paraLineSpacing_assert_doc.Height);
411 	}
412 	/*
413 	 * test paragraph line spacing is 1.5line
414 	 * 1.new a text document
415 	 * 2.insert some text
416 	 * 3.set paragraph line spacing is 1.5line
417 	 * 4.save and close the document
418 	 * 5.reload the saved document and check the paragraph line spacing
419 	 */
420 	@Test
testParagraphLineSpacingUserDefine()421 	public void testParagraphLineSpacingUserDefine() throws Exception {
422 
423 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
424 		xText = xTextDocument.getText();
425 		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!" +
426 				"Hello,world!Hello,world!");
427 		// create text cursor for selecting and formatting text
428 		XTextCursor xTextCursor = xText.createTextCursor();
429 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
430 		//set paragraph line spacing
431 		LineSpacing lineSpacing = new LineSpacing();
432 		lineSpacing.Height = 150;
433 		xCursorProps.setPropertyValue("ParaLineSpacing",lineSpacing);
434 		//save to odt
435 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
436 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
437 		aStoreProperties_odt[0] = new PropertyValue();
438 		aStoreProperties_odt[1] = new PropertyValue();
439 		aStoreProperties_odt[0].Name = "Override";
440 		aStoreProperties_odt[0].Value = true;
441 		aStoreProperties_odt[1].Name = "FilterName";
442 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
443 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
444 		//save to doc
445 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
446 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
447 		aStoreProperties_doc[0] = new PropertyValue();
448 		aStoreProperties_doc[1] = new PropertyValue();
449 		aStoreProperties_doc[0].Name = "Override";
450 		aStoreProperties_doc[0].Value = true;
451 		aStoreProperties_doc[1].Name = "FilterName";
452 		aStoreProperties_doc[1].Value = "MS Word 97";
453 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
454 		app.closeDocument(xTextDocument);
455 
456 		//reopen the document
457 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
458 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_odt.getText().createTextCursor());
459 		LineSpacing paraLineSpacing_assert_odt=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_odt.getPropertyValue("ParaLineSpacing"));
460 		//verify paragraph line spacing property
461 		assertEquals("assert first paragraph line spacing is single",150,paraLineSpacing_assert_odt.Height);
462 
463 		//reopen the document
464 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
465 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,assertDocument_doc.getText().createTextCursor());
466 		LineSpacing paraLineSpacing_assert_doc=(LineSpacing) UnoRuntime.queryInterface(LineSpacing.class, xCursorProps_assert_doc.getPropertyValue("ParaLineSpacing"));
467 		//verify paragraph line spacing property
468 		assertEquals("assert first paragraph line spacing is single",150,paraLineSpacing_assert_doc.Height);
469 	}
470 }
471