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