107d7dbdcSHerbert Dürr /**************************************************************
207d7dbdcSHerbert Dürr  *
307d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
407d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
507d7dbdcSHerbert Dürr  * distributed with this work for additional information
607d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
707d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
807d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
907d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
1007d7dbdcSHerbert Dürr  *
1107d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
1207d7dbdcSHerbert Dürr  *
1307d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
1407d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
1507d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1607d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
1707d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
1807d7dbdcSHerbert Dürr  * under the License.
1907d7dbdcSHerbert Dürr  *
2007d7dbdcSHerbert Dürr  *************************************************************/
2107d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
23294fe326SLiu Zhe 
24294fe326SLiu Zhe import static org.junit.Assert.*;
25294fe326SLiu Zhe 
26294fe326SLiu Zhe import org.junit.After;
27294fe326SLiu Zhe import org.junit.Before;
28294fe326SLiu Zhe import org.junit.Ignore;
29294fe326SLiu Zhe import org.junit.Test;
30294fe326SLiu Zhe import org.openoffice.test.common.FileUtil;
31294fe326SLiu Zhe import org.openoffice.test.common.Testspace;
32294fe326SLiu Zhe import org.openoffice.test.uno.UnoApp;
33294fe326SLiu Zhe 
34294fe326SLiu Zhe import com.sun.star.style.NumberingType;
35294fe326SLiu Zhe import com.sun.star.text.*;
36294fe326SLiu Zhe import com.sun.star.beans.*;
37294fe326SLiu Zhe import com.sun.star.container.XIndexAccess;
38294fe326SLiu Zhe import com.sun.star.container.XIndexReplace;
39294fe326SLiu Zhe import com.sun.star.frame.XStorable;
40294fe326SLiu Zhe import com.sun.star.lang.XMultiServiceFactory;
41294fe326SLiu Zhe import com.sun.star.uno.UnoRuntime;
42294fe326SLiu Zhe 
43294fe326SLiu Zhe public class ParagraphNumberingAndBullet_Graphic {
44294fe326SLiu Zhe 	private static final UnoApp app = new UnoApp();
45294fe326SLiu Zhe 	XText xText = null;
46294fe326SLiu Zhe 
47294fe326SLiu Zhe 	@Before
setUp()48294fe326SLiu Zhe 	public void setUp() throws Exception {
49294fe326SLiu Zhe 		app.start();
50294fe326SLiu Zhe 
51294fe326SLiu Zhe 	}
52294fe326SLiu Zhe 
53294fe326SLiu Zhe 	@After
tearDown()54294fe326SLiu Zhe 	public void tearDown() throws Exception {
55294fe326SLiu Zhe 		app.close();
56294fe326SLiu Zhe 	}
57294fe326SLiu Zhe 	/*
58294fe326SLiu Zhe 	 * test paragraph background color
59294fe326SLiu Zhe 	 * 1.new a text document
60294fe326SLiu Zhe 	 * 2.insert some text
61294fe326SLiu Zhe 	 * 3.set paragraph numbering bullet with graphic
62294fe326SLiu Zhe 	 * 4.save and close the document
63294fe326SLiu Zhe 	 * 5.reload the saved document and check the paragraph graphic bullet
64294fe326SLiu Zhe 	 */
65af986861SLiu Zhe 	@Test@Ignore("Bug #120833 - [testUNO patch]graphic bullet will change to character bullet when save to doc.")
testNumberingBullet_Graphic()66294fe326SLiu Zhe 	public void testNumberingBullet_Graphic() throws Exception {
67294fe326SLiu Zhe 
68294fe326SLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
69294fe326SLiu Zhe 		xText = xTextDocument.getText();
70294fe326SLiu 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!" +
71294fe326SLiu Zhe 				"Hello,world!Hello,world!");
72*06fb39a1SJohn Bampton 		//create cursor to select paragraph and formatting paragraph
73294fe326SLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
74294fe326SLiu Zhe 		//create paragraph property set
75294fe326SLiu Zhe 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
76294fe326SLiu Zhe 		//create document service factory
77294fe326SLiu Zhe 		XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
78294fe326SLiu Zhe 		//set numbering character
79294fe326SLiu Zhe 		XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
80294fe326SLiu Zhe 		PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()};
81294fe326SLiu Zhe 		propsRule[0].Name = "NumberingType";
82294fe326SLiu Zhe 		propsRule[0].Value = NumberingType.BITMAP;
83294fe326SLiu Zhe 		propsRule[1].Name = "GraphicURL";
84294fe326SLiu Zhe 		propsRule[1].Value = FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif"));
85294fe326SLiu Zhe 		XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
86294fe326SLiu Zhe 		xReplaceRule.replaceByIndex(0, propsRule);
87294fe326SLiu Zhe 		//set paragraph numbering and bullet character
88294fe326SLiu Zhe 		xTextProps.setPropertyValue("NumberingRules", xNumRule);
89294fe326SLiu Zhe 
90294fe326SLiu Zhe 		//save to odt
91294fe326SLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
92294fe326SLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
93294fe326SLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
94294fe326SLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
95294fe326SLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
96294fe326SLiu Zhe 		aStoreProperties_odt[0].Value = true;
97294fe326SLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
98294fe326SLiu Zhe 		aStoreProperties_odt[1].Value = "writer8";
99294fe326SLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
100294fe326SLiu Zhe 		//save to doc
101294fe326SLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
102294fe326SLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
103294fe326SLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
104294fe326SLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
105294fe326SLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
106294fe326SLiu Zhe 		aStoreProperties_doc[0].Value = true;
107294fe326SLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
108294fe326SLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
109294fe326SLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
110294fe326SLiu Zhe 		app.closeDocument(xTextDocument);
111294fe326SLiu Zhe 
112294fe326SLiu Zhe 		//reopen the document
113294fe326SLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
114294fe326SLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
115294fe326SLiu Zhe 		XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
116294fe326SLiu Zhe 		XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
117294fe326SLiu Zhe 		PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
118294fe326SLiu Zhe 		//verify paragraph numbering and bullet alignment
119294fe326SLiu Zhe 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
120294fe326SLiu Zhe 		assertEquals("assert numbering and bullet",NumberingType.BITMAP,propsRule_assert_odt[11].Value);
121294fe326SLiu Zhe 		assertEquals("assert numbering and bullet","GraphicURL",propsRule_assert_odt[12].Name);
122294fe326SLiu Zhe 		assertEquals("assert numbering and bullet",FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif")),propsRule_assert_odt[12].Value);
123294fe326SLiu Zhe 
124294fe326SLiu Zhe 		//reopen the document
125294fe326SLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
126294fe326SLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
127294fe326SLiu Zhe 		XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
128294fe326SLiu Zhe 		PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
129294fe326SLiu Zhe 		//verify paragraph numbering and bullet alignment
130294fe326SLiu Zhe 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
131294fe326SLiu Zhe 		assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value);
132294fe326SLiu Zhe 		assertEquals("assert numbering and bullet","GraphicURL",propsRule_assert_doc[12].Name);
133294fe326SLiu Zhe 		assertEquals("assert numbering and bullet",FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif")),propsRule_assert_doc[12].Value);
134294fe326SLiu Zhe 	}
135294fe326SLiu Zhe }
136