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 
34 import com.sun.star.style.NumberingType;
35 import com.sun.star.text.*;
36 import com.sun.star.beans.*;
37 import com.sun.star.container.XIndexAccess;
38 import com.sun.star.container.XIndexReplace;
39 import com.sun.star.frame.XStorable;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
42 
43 public class ParagraphNumberingAndBullet_CharacterBullet {
44 	private static final UnoApp app = new UnoApp();
45 	XText xText = null;
46 
47 	@Before
48 	public void setUp() throws Exception {
49 		app.start();
50 
51 	}
52 
53 	@After
54 	public void tearDown() throws Exception {
55 		//app.close();
56 	}
57 	/*
58 	 * test paragraph background color
59 	 * 1.new a text document
60 	 * 2.insert some text
61 	 * 3.set paragraph bullet
62 	 * 4.save and close the document
63 	 * 5.reload the saved document and check the paragraph bullet
64 	 */
65 	@Test @Ignore("Bug #120963 - [testUNO patch]the bullet character font style change to other font style character when save to doc.")
66 	public void testNumberingAndBullet_CharacterBullet1() throws Exception {
67 
68 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
69 		xText = xTextDocument.getText();
70 		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!" +
71 				"Hello,world!Hello,world!");
72 		//create cursor to select paragraph and formating paragraph
73 		XTextCursor xTextCursor = xText.createTextCursor();
74 		//create paragraph property set
75 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
76 		//create document service factory
77 		XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
78 		//set numbering character
79 		XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
80 		PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()};
81 		propsRule[0].Name = "NumberingType";
82 		propsRule[0].Value = NumberingType.CHAR_SPECIAL;
83 		propsRule[1].Name = "BulletId";
84 		propsRule[1].Value = (short)8226;
85 		XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
86 		xReplaceRule.replaceByIndex(0, propsRule);
87 		//set paragraph numbering and bullet character
88 		xTextProps.setPropertyValue("NumberingRules", xNumRule);
89 		//save to odt
90 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
91 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
92 		aStoreProperties_odt[0] = new PropertyValue();
93 		aStoreProperties_odt[1] = new PropertyValue();
94 		aStoreProperties_odt[0].Name = "Override";
95 		aStoreProperties_odt[0].Value = true;
96 		aStoreProperties_odt[1].Name = "FilterName";
97 		aStoreProperties_odt[1].Value = "writer8";
98 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
99 		//save to doc
100 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
101 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
102 		aStoreProperties_doc[0] = new PropertyValue();
103 		aStoreProperties_doc[1] = new PropertyValue();
104 		aStoreProperties_doc[0].Name = "Override";
105 		aStoreProperties_doc[0].Value = true;
106 		aStoreProperties_doc[1].Name = "FilterName";
107 		aStoreProperties_doc[1].Value = "MS Word 97";
108 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
109 		app.closeDocument(xTextDocument);
110 
111 		//reopen the document
112 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
113 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
114 		XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
115 		XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
116 		PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
117 		//verify paragraph numbering and bullet alignment
118 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
119 		assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_odt[11].Value);
120 		assertEquals("assert numbering and bullet","BulletId",propsRule_assert_odt[12].Name);
121 		assertEquals("assert numbering and bullet",(short)8226,propsRule_assert_odt[12].Value);
122 
123 		//reopen the document
124 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
125 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
126 		XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
127 		PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
128 		//verify paragraph numbering and bullet alignment
129 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
130 		assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value);
131 		assertEquals("assert numbering and bullet","BulletId",propsRule_assert_doc[12].Name);
132 		assertEquals("assert numbering and bullet",(short)8226,propsRule_assert_doc[12].Value);
133 	}
134 	@Test @Ignore("Bug #120963 - [testUNO patch]the bullet character font style change to other font style character when save to doc.")
135 	public void testNumberingAndBullet_CharacterBullet2() throws Exception {
136 
137 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
138 		xText = xTextDocument.getText();
139 		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!" +
140 				"Hello,world!Hello,world!");
141 		//create cursor to select paragraph and formating paragraph
142 		XTextCursor xTextCursor = xText.createTextCursor();
143 		//create paragraph property set
144 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
145 		//create document service factory
146 		XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
147 		//set numbering character
148 		XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
149 		PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()};
150 		propsRule[0].Name = "NumberingType";
151 		propsRule[0].Value = NumberingType.CHAR_SPECIAL;
152 		propsRule[1].Name = "BulletId";
153 		propsRule[1].Value = (short)9679;
154 		XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
155 		xReplaceRule.replaceByIndex(0, propsRule);
156 		//set paragraph numbering and bullet character
157 		xTextProps.setPropertyValue("NumberingRules", xNumRule);
158 		//save to odt
159 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
160 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
161 		aStoreProperties_odt[0] = new PropertyValue();
162 		aStoreProperties_odt[1] = new PropertyValue();
163 		aStoreProperties_odt[0].Name = "Override";
164 		aStoreProperties_odt[0].Value = true;
165 		aStoreProperties_odt[1].Name = "FilterName";
166 		aStoreProperties_odt[1].Value = "writer8";
167 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
168 		//save to doc
169 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
170 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
171 		aStoreProperties_doc[0] = new PropertyValue();
172 		aStoreProperties_doc[1] = new PropertyValue();
173 		aStoreProperties_doc[0].Name = "Override";
174 		aStoreProperties_doc[0].Value = true;
175 		aStoreProperties_doc[1].Name = "FilterName";
176 		aStoreProperties_doc[1].Value = "MS Word 97";
177 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
178 		app.closeDocument(xTextDocument);
179 
180 		//reopen the document
181 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
182 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
183 		XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
184 		XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
185 		PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
186 		//verify paragraph numbering and bullet alignment
187 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
188 		assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_odt[11].Value);
189 		assertEquals("assert numbering and bullet","BulletId",propsRule_assert_odt[12].Name);
190 		assertEquals("assert numbering and bullet",(short)9679,propsRule_assert_odt[12].Value);
191 
192 		//reopen the document
193 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
194 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
195 		XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
196 		PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
197 		//verify paragraph numbering and bullet alignment
198 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
199 		assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value);
200 		assertEquals("assert numbering and bullet","BulletId",propsRule_assert_doc[12].Name);
201 		assertEquals("assert numbering and bullet",(short)9679,propsRule_assert_doc[12].Value);
202 	}
203 }
204