xref: /AOO41X/test/testuno/source/fvt/uno/sw/paragraph/ParagraphIndentAndSpacing.java (revision 07d7dbdcb8e526dfaf85923a181c45494526d79d)
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;
23eba4d44aSLiu Zhe 
24eba4d44aSLiu Zhe import static org.junit.Assert.*;
25eba4d44aSLiu Zhe 
26eba4d44aSLiu Zhe import org.junit.After;
27eba4d44aSLiu Zhe import org.junit.Before;
28eba4d44aSLiu Zhe import org.junit.Ignore;
29eba4d44aSLiu Zhe import org.junit.Test;
30eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil;
31eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace;
32eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
33eba4d44aSLiu Zhe import com.sun.star.text.*;
34eba4d44aSLiu Zhe import com.sun.star.beans.*;
35eba4d44aSLiu Zhe import com.sun.star.frame.XStorable;
36eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
37eba4d44aSLiu Zhe 
38eba4d44aSLiu Zhe public class ParagraphIndentAndSpacing {
39eba4d44aSLiu Zhe 	private static final UnoApp app = new UnoApp();
40eba4d44aSLiu Zhe 	XText xText = null;
41eba4d44aSLiu Zhe 
42eba4d44aSLiu Zhe 	@Before
setUp()43eba4d44aSLiu Zhe 	public void setUp() throws Exception {
44eba4d44aSLiu Zhe 		app.start();
45eba4d44aSLiu Zhe 
46eba4d44aSLiu Zhe 	}
47eba4d44aSLiu Zhe 
48eba4d44aSLiu Zhe 	@After
tearDown()49eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
50eba4d44aSLiu Zhe 		app.close();
51eba4d44aSLiu Zhe 	}
52eba4d44aSLiu Zhe     /*
53eba4d44aSLiu Zhe      * test paragraph spacing
54eba4d44aSLiu Zhe      * 1.new a text document
55eba4d44aSLiu Zhe      * 2.insert some text
56eba4d44aSLiu Zhe      * 3.set paragraph spacing:before text,after text,above paragraph,below paragraph
57eba4d44aSLiu Zhe      * 4.save to odt and close it
58eba4d44aSLiu Zhe      * 5.reopen the saved document and check the paragraph spacing
59eba4d44aSLiu Zhe      */
60eba4d44aSLiu Zhe 	@Test
testParagraphSpacingSetting()61eba4d44aSLiu Zhe 	public void testParagraphSpacingSetting() throws Exception {
62eba4d44aSLiu Zhe 
63eba4d44aSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
64eba4d44aSLiu Zhe 		xText = xTextDocument.getText();
65eba4d44aSLiu 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!" +
66eba4d44aSLiu Zhe 				"Hello,world!Hello,world!");
67eba4d44aSLiu Zhe 		// create text cursor for selecting and formatting text
68eba4d44aSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
69eba4d44aSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
70eba4d44aSLiu Zhe 		//set paragraph margin with page border
71eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("ParaLeftMargin",2000);
72eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("ParaRightMargin",3000);
73eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("ParaTopMargin",1000);
74eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("ParaBottomMargin",4000);
75eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("ParaFirstLineIndent",4000);
76eba4d44aSLiu Zhe 
77eba4d44aSLiu Zhe 		//save to odt
78eba4d44aSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
79eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
80eba4d44aSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
81eba4d44aSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
82eba4d44aSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
83eba4d44aSLiu Zhe 		aStoreProperties_odt[0].Value = true;
84eba4d44aSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
85eba4d44aSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
86eba4d44aSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
87eba4d44aSLiu Zhe 		//save to doc
88eba4d44aSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
89eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
90eba4d44aSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
91eba4d44aSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
92eba4d44aSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
93eba4d44aSLiu Zhe 		aStoreProperties_doc[0].Value = true;
94eba4d44aSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
95eba4d44aSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
96eba4d44aSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
97eba4d44aSLiu Zhe 		app.closeDocument(xTextDocument);
98eba4d44aSLiu Zhe 
99eba4d44aSLiu Zhe 		//reopen the document and assert line spacing
100eba4d44aSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
101eba4d44aSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
102eba4d44aSLiu Zhe 		//verify paragraph indent and spacing
103eba4d44aSLiu Zhe 		assertEquals("assert before text margin",2000,xCursorProps_Assert_odt.getPropertyValue("ParaLeftMargin"));
104eba4d44aSLiu Zhe 		assertEquals("assert after text margin",3000,xCursorProps_Assert_odt.getPropertyValue("ParaRightMargin"));
105eba4d44aSLiu Zhe 		assertEquals("assert above paragraph margin",1000,xCursorProps_Assert_odt.getPropertyValue("ParaTopMargin"));
106eba4d44aSLiu Zhe 		assertEquals("assert below paragraph margin",4001,xCursorProps_Assert_odt.getPropertyValue("ParaBottomMargin"));
107eba4d44aSLiu Zhe 		assertEquals("assert first line indent",4001,xCursorProps_Assert_odt.getPropertyValue("ParaFirstLineIndent"));
108eba4d44aSLiu Zhe 		assertEquals("assert paragraph first line is no autoindent",false,xCursorProps_Assert_odt.getPropertyValue("ParaIsAutoFirstLineIndent"));
109eba4d44aSLiu Zhe 
110eba4d44aSLiu Zhe 		//reopen the document and assert line spacing
111eba4d44aSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
112eba4d44aSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
113eba4d44aSLiu Zhe 		//verify paragraph indent and spacing
114eba4d44aSLiu Zhe 		assertEquals("assert before text margin",2000,xCursorProps_Assert_doc.getPropertyValue("ParaLeftMargin"));
115eba4d44aSLiu Zhe 		assertEquals("assert after text margin",3000,xCursorProps_Assert_doc.getPropertyValue("ParaRightMargin"));
116eba4d44aSLiu Zhe 		assertEquals("assert above paragraph margin",1000,xCursorProps_Assert_doc.getPropertyValue("ParaTopMargin"));
117eba4d44aSLiu Zhe 		assertEquals("assert below paragraph margin",4001,xCursorProps_Assert_doc.getPropertyValue("ParaBottomMargin"));
118eba4d44aSLiu Zhe 		assertEquals("assert first line indent",4001,xCursorProps_Assert_doc.getPropertyValue("ParaFirstLineIndent"));
119eba4d44aSLiu Zhe 		assertEquals("assert paragraph first line is no autoindent",false,xCursorProps_Assert_doc.getPropertyValue("ParaIsAutoFirstLineIndent"));
120eba4d44aSLiu Zhe 	}
121eba4d44aSLiu Zhe 	@Test@Ignore("Bug #120646 - [testUNO patch]the auto indent effect of first line lost when save to doc")
testParagraphIndent()122eba4d44aSLiu Zhe 	public void testParagraphIndent() throws Exception {
123eba4d44aSLiu Zhe 
124eba4d44aSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
125eba4d44aSLiu Zhe 		xText = xTextDocument.getText();
126eba4d44aSLiu 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!" +
127eba4d44aSLiu Zhe 				"Hello,world!Hello,world!");
128eba4d44aSLiu Zhe 		// create text cursor for selecting and formatting text
129eba4d44aSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
130eba4d44aSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
131eba4d44aSLiu Zhe 		//set paragraph margin with page border
132eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("ParaIsAutoFirstLineIndent",true);
133eba4d44aSLiu Zhe 
134eba4d44aSLiu Zhe 		//save to odt
135eba4d44aSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
136eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
137eba4d44aSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
138eba4d44aSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
139eba4d44aSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
140eba4d44aSLiu Zhe 		aStoreProperties_odt[0].Value = true;
141eba4d44aSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
142eba4d44aSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
143eba4d44aSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
144eba4d44aSLiu Zhe 		//save to doc
145eba4d44aSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
146eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
147eba4d44aSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
148eba4d44aSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
149eba4d44aSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
150eba4d44aSLiu Zhe 		aStoreProperties_doc[0].Value = true;
151eba4d44aSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
152eba4d44aSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
153eba4d44aSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
154eba4d44aSLiu Zhe 		app.closeDocument(xTextDocument);
155eba4d44aSLiu Zhe 
156eba4d44aSLiu Zhe 
157eba4d44aSLiu Zhe 		//reopen the document and assert paragraph indent
158eba4d44aSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
159eba4d44aSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
160eba4d44aSLiu Zhe 		//verify paragraph auto indent
161eba4d44aSLiu Zhe 		assertEquals("assert paragraph first line is autoindent",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsAutoFirstLineIndent"));
162eba4d44aSLiu Zhe 
163eba4d44aSLiu Zhe 		//reopen the document and assert paragraph indent
164eba4d44aSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
165eba4d44aSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
166eba4d44aSLiu Zhe 		//verify paragraph auto indent
167eba4d44aSLiu Zhe 		assertEquals("assert paragraph first line is autoindent",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsAutoFirstLineIndent"));
168eba4d44aSLiu Zhe 	}
169eba4d44aSLiu Zhe 
170eba4d44aSLiu Zhe }
171