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 
13 import com.sun.star.style.NumberingType;
14 import com.sun.star.text.*;
15 import com.sun.star.beans.*;
16 import com.sun.star.container.XIndexAccess;
17 import com.sun.star.container.XIndexReplace;
18 import com.sun.star.frame.XStorable;
19 import com.sun.star.lang.XMultiServiceFactory;
20 import com.sun.star.uno.UnoRuntime;
21 
22 public class ParagraphNumberingAndBullet_Graphic {
23 	private static final UnoApp app = new UnoApp();
24 	XText xText = null;
25 
26 	@Before
27 	public void setUp() throws Exception {
28 		app.start();
29 
30 	}
31 
32 	@After
33 	public void tearDown() throws Exception {
34 		app.close();
35 	}
36 	/*
37 	 * test paragraph background color
38 	 * 1.new a text document
39 	 * 2.insert some text
40 	 * 3.set paragraph numbering bullet with graphic
41 	 * 4.save and close the document
42 	 * 5.reload the saved document and check the paragraph graphic bullet
43 	 */
44 	@Test@Ignore("Bug #120833 - [testUNO patch]graphic bullet will change to character bullet when save to doc.")
45 	public void testNumberingBullet_Graphic() throws Exception {
46 
47 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
48 		xText = xTextDocument.getText();
49 		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!" +
50 				"Hello,world!Hello,world!");
51 		//create cursor to select paragraph and formating paragraph
52 		XTextCursor xTextCursor = xText.createTextCursor();
53 		//create paragraph property set
54 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
55 		//create document service factory
56 		XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
57 		//set numbering character
58 		XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
59 		PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()};
60 		propsRule[0].Name = "NumberingType";
61 		propsRule[0].Value = NumberingType.BITMAP;
62 		propsRule[1].Name = "GraphicURL";
63 		propsRule[1].Value = FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif"));
64 		XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
65 		xReplaceRule.replaceByIndex(0, propsRule);
66 		//set paragraph numbering and bullet character
67 		xTextProps.setPropertyValue("NumberingRules", xNumRule);
68 
69 		//save to odt
70 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
71 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
72 		aStoreProperties_odt[0] = new PropertyValue();
73 		aStoreProperties_odt[1] = new PropertyValue();
74 		aStoreProperties_odt[0].Name = "Override";
75 		aStoreProperties_odt[0].Value = true;
76 		aStoreProperties_odt[1].Name = "FilterName";
77 		aStoreProperties_odt[1].Value = "writer8";
78 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
79 		//save to doc
80 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
81 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
82 		aStoreProperties_doc[0] = new PropertyValue();
83 		aStoreProperties_doc[1] = new PropertyValue();
84 		aStoreProperties_doc[0].Name = "Override";
85 		aStoreProperties_doc[0].Value = true;
86 		aStoreProperties_doc[1].Name = "FilterName";
87 		aStoreProperties_doc[1].Value = "MS Word 97";
88 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
89 		app.closeDocument(xTextDocument);
90 
91 		//reopen the document
92 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
93 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
94 		XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
95 		XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
96 		PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
97 		//verify paragraph numbering and bullet alignment
98 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
99 		assertEquals("assert numbering and bullet",NumberingType.BITMAP,propsRule_assert_odt[11].Value);
100 		assertEquals("assert numbering and bullet","GraphicURL",propsRule_assert_odt[12].Name);
101 		assertEquals("assert numbering and bullet",FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif")),propsRule_assert_odt[12].Value);
102 
103 		//reopen the document
104 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
105 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
106 		XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
107 		PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
108 		//verify paragraph numbering and bullet alignment
109 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
110 		assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value);
111 		assertEquals("assert numbering and bullet","GraphicURL",propsRule_assert_doc[12].Name);
112 		assertEquals("assert numbering and bullet",FileUtil.getUrl(Testspace.prepareData("uno/coffee_1.gif")),propsRule_assert_doc[12].Value);
113 	}
114 }
115