1 package testcase.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.Test;
8 import org.openoffice.test.common.FileUtil;
9 import org.openoffice.test.common.Testspace;
10 import org.openoffice.test.uno.UnoApp;
11 
12 import com.sun.star.style.NumberingType;
13 import com.sun.star.text.*;
14 import com.sun.star.beans.*;
15 import com.sun.star.container.XIndexAccess;
16 import com.sun.star.container.XIndexReplace;
17 import com.sun.star.frame.XStorable;
18 import com.sun.star.lang.XMultiServiceFactory;
19 import com.sun.star.uno.UnoRuntime;
20 
21 public class ParagraphNumberingAndBulletIndentAtAndAlignAt {
22 	private static final UnoApp app = new UnoApp();
23 	XText xText = null;
24 
25 	@Before
26 	public void setUp() throws Exception {
27 		app.start();
28 
29 	}
30 
31 	@After
32 	public void tearDown() throws Exception {
33 		app.close();
34 	}
35 	/*
36 	 * test paragraph background color
37 	 * 1.new a text document
38 	 * 2.insert some text
39 	 * 3.set paragraph outline and numbering
40 	 * 4.save and close the document
41 	 * 5.reload the saved document and check the paragraph outline and numbering
42 	 */
43 	@Test
44 	public void testNumberingBulletIndentAtAndAlignAt() throws Exception {
45 
46 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
47 		xText = xTextDocument.getText();
48 		xText.setString("we are Chinese,they are American.\nwe are all living in one earth!Hello,world!\nHello,world!Hello,world!Hello,world!Hello,world!\nHello,world!" +
49 				"Hello,world!Hello,world!");
50 		//create cursor to select paragraph and formating paragraph
51 		XTextCursor xTextCursor = xText.createTextCursor();
52 		//create paragraph property set
53 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
54 		//create document service factory
55 		XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
56 		//set numbering character
57 		XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
58 		PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue(),new PropertyValue()};
59 		propsRule[0].Name = "NumberingType";
60 		propsRule[0].Value = NumberingType.ARABIC;
61 		propsRule[1].Name = "IndentAt";
62 		propsRule[1].Value = 499;
63 		propsRule[2].Name = "FirstLineIndent";
64 		propsRule[2].Value = 199;
65 		XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
66 		xReplaceRule.replaceByIndex(0, propsRule);
67 		//set paragraph numbering and bullet character
68 		xTextProps.setPropertyValue("NumberingRules", xNumRule);
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","IndentAt",propsRule_assert_odt[10].Name);
99 		assertEquals("assert numbering and bullet",499,propsRule_assert_odt[10].Value);
100 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
101 		assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value);
102 		assertEquals("assert numbering and bullet","FirstLineIndent",propsRule_assert_odt[9].Name);
103 		assertEquals("assert numbering and bullet",199,propsRule_assert_odt[9].Value);
104 
105 		//reopen the document
106 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
107 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
108 		XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
109 		PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
110 		//verify paragraph numbering and bullet alignment
111 		assertEquals("assert numbering and bullet","IndentAt",propsRule_assert_doc[10].Name);
112 		assertEquals("assert numbering and bullet",499,propsRule_assert_doc[10].Value);
113 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
114 		assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value);
115 		assertEquals("assert numbering and bullet","FirstLineIndent",propsRule_assert_doc[9].Name);
116 		assertEquals("assert numbering and bullet",199,propsRule_assert_doc[9].Value);
117 	}
118 }
119