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 com.sun.star.text.*;
34 import com.sun.star.beans.*;
35 import com.sun.star.frame.XStorable;
36 import com.sun.star.uno.UnoRuntime;
37 
38 public class ParagraphOutlineAndNumbering {
39 	private static final UnoApp app = new UnoApp();
40 	XText xText = null;
41 
42 	@Before
setUp()43 	public void setUp() throws Exception {
44 		app.start();
45 
46 	}
47 
48 	@After
tearDown()49 	public void tearDown() throws Exception {
50 		//app.close();
51 	}
52 	/*
53 	 * test paragraph background color
54 	 * 1.new a text document
55 	 * 2.insert some text
56 	 * 3.set paragraph outline and numbering
57 	 * 4.save and close the document
58 	 * 5.reload the saved document and check the paragraph outline and numbering
59 	 */
60 	@Test@Ignore("Bug #120753 - [testUNO patch]paragraph outline level and numbering style change when save to doc")
testOutlineAndNumbering_NumberStyle()61 	public void testOutlineAndNumbering_NumberStyle() throws Exception {
62 
63 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
64 		xText = xTextDocument.getText();
65 		xText.setString("we are Chinese,they are American.\nwe are all living in one earth!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!Hello,world!" +
66 				"Hello,world!Hello,world!");
67 		XTextCursor xTextCursor=xText.createTextCursor();
68 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
69 		xTextProps.setPropertyValue("OutlineLevel", (short)6);
70 		xTextProps.setPropertyValue("NumberingStyleName", "Numbering 2");
71 		xTextProps.setPropertyValue("ParaIsNumberingRestart", true);
72 		xTextProps.setPropertyValue("NumberingStartValue", (short)7);
73 		xTextProps.setPropertyValue("ParaLineNumberCount",true);
74 		xTextProps.setPropertyValue("ParaLineNumberStartValue",(long)4);
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 = "writer8";
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 outline and numbering
101 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_odt.getPropertyValue("OutlineLevel"));
102 		assertEquals("assert paragraph outline and numbering","Numbering 2",xCursorProps_Assert_odt.getPropertyValue("NumberingStyleName"));
103 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsNumberingRestart"));
104 		assertEquals("assert paragraph outline and numbering",(short)7,xCursorProps_Assert_odt.getPropertyValue("NumberingStartValue"));
105 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberCount"));
106 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberStartValue"));
107 
108 		//reopen the document
109 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
110 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
111 		//verify paragraph outline and numbering
112 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_doc.getPropertyValue("OutlineLevel"));
113 		assertEquals("assert paragraph outline and numbering","Numbering 2",xCursorProps_Assert_doc.getPropertyValue("NumberingStyleName"));
114 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsNumberingRestart"));
115 		assertEquals("assert paragraph outline and numbering",(short)7,xCursorProps_Assert_doc.getPropertyValue("NumberingStartValue"));
116 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberCount"));
117 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberStartValue"));
118 
119 	}
120 	@Test@Ignore("Bug #120753 - [testUNO patch]paragraph outline level and numbering style change when save to doc")
testOutlineAndNumbering_ListStyle()121 	public void testOutlineAndNumbering_ListStyle() throws Exception {
122 
123 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
124 		xText = xTextDocument.getText();
125 		xText.setString("we are Chinese,they are American.\nwe are all living in one earth!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!Hello,world!" +
126 				"Hello,world!Hello,world!");
127 		XTextCursor xTextCursor=xText.createTextCursor();
128 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
129 		xTextProps.setPropertyValue("OutlineLevel", (short)3);
130 		xTextProps.setPropertyValue("NumberingStyleName", "List 3");
131 		xTextProps.setPropertyValue("ParaIsNumberingRestart", true);
132 		xTextProps.setPropertyValue("NumberingStartValue", (short)6);
133 		xTextProps.setPropertyValue("ParaLineNumberCount",true);
134 		xTextProps.setPropertyValue("ParaLineNumberStartValue",(long)4);
135 		//save to odt
136 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
137 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
138 		aStoreProperties_odt[0] = new PropertyValue();
139 		aStoreProperties_odt[1] = new PropertyValue();
140 		aStoreProperties_odt[0].Name = "Override";
141 		aStoreProperties_odt[0].Value = true;
142 		aStoreProperties_odt[1].Name = "FilterName";
143 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
144 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
145 		//save to doc
146 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
147 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
148 		aStoreProperties_doc[0] = new PropertyValue();
149 		aStoreProperties_doc[1] = new PropertyValue();
150 		aStoreProperties_doc[0].Name = "Override";
151 		aStoreProperties_doc[0].Value = true;
152 		aStoreProperties_doc[1].Name = "FilterName";
153 		aStoreProperties_doc[1].Value = "MS Word 97";
154 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
155 		//app.closeDocument(xTextDocument);
156 
157 		//reopen the document
158 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
159 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
160 		//verify paragraph outline and numbering
161 		assertEquals("assert paragraph outline and numbering",(short)3,xCursorProps_Assert_odt.getPropertyValue("OutlineLevel"));
162 		assertEquals("assert paragraph outline and numbering","List 3",xCursorProps_Assert_odt.getPropertyValue("NumberingStyleName"));
163 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsNumberingRestart"));
164 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_odt.getPropertyValue("NumberingStartValue"));
165 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberCount"));
166 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberStartValue"));
167 
168 
169 		//reopen the document
170 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
171 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
172 		//verify paragraph outline and numbering
173 		assertEquals("assert paragraph outline and numbering",(short)3,xCursorProps_Assert_doc.getPropertyValue("OutlineLevel"));
174 		assertEquals("assert paragraph outline and numbering","List 3",xCursorProps_Assert_doc.getPropertyValue("NumberingStyleName"));
175 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsNumberingRestart"));
176 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_doc.getPropertyValue("NumberingStartValue"));
177 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberCount"));
178 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberStartValue"));
179 
180 	}
181 }
182