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