1*eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
24a089d9bSLiu Zhe 
34a089d9bSLiu Zhe import static org.junit.Assert.*;
44a089d9bSLiu Zhe 
54a089d9bSLiu Zhe import org.junit.After;
64a089d9bSLiu Zhe import org.junit.Before;
74a089d9bSLiu Zhe import org.junit.Test;
84a089d9bSLiu Zhe import org.openoffice.test.common.FileUtil;
94a089d9bSLiu Zhe import org.openoffice.test.common.Testspace;
104a089d9bSLiu Zhe import org.openoffice.test.uno.UnoApp;
114a089d9bSLiu Zhe 
124a089d9bSLiu Zhe import com.sun.star.style.NumberingType;
134a089d9bSLiu Zhe import com.sun.star.text.*;
144a089d9bSLiu Zhe import com.sun.star.beans.*;
154a089d9bSLiu Zhe import com.sun.star.container.XIndexAccess;
164a089d9bSLiu Zhe import com.sun.star.container.XIndexReplace;
174a089d9bSLiu Zhe import com.sun.star.frame.XStorable;
184a089d9bSLiu Zhe import com.sun.star.lang.XMultiServiceFactory;
194a089d9bSLiu Zhe import com.sun.star.uno.UnoRuntime;
204a089d9bSLiu Zhe 
214a089d9bSLiu Zhe public class ParagraphNumberingAndBulletIndentAtAndAlignAt {
224a089d9bSLiu Zhe 	private static final UnoApp app = new UnoApp();
234a089d9bSLiu Zhe 	XText xText = null;
244a089d9bSLiu Zhe 
254a089d9bSLiu Zhe 	@Before
264a089d9bSLiu Zhe 	public void setUp() throws Exception {
274a089d9bSLiu Zhe 		app.start();
284a089d9bSLiu Zhe 
294a089d9bSLiu Zhe 	}
304a089d9bSLiu Zhe 
314a089d9bSLiu Zhe 	@After
324a089d9bSLiu Zhe 	public void tearDown() throws Exception {
334a089d9bSLiu Zhe 		app.close();
344a089d9bSLiu Zhe 	}
354a089d9bSLiu Zhe 	/*
364a089d9bSLiu Zhe 	 * test paragraph background color
374a089d9bSLiu Zhe 	 * 1.new a text document
384a089d9bSLiu Zhe 	 * 2.insert some text
394a089d9bSLiu Zhe 	 * 3.set paragraph outline and numbering
404a089d9bSLiu Zhe 	 * 4.save and close the document
414a089d9bSLiu Zhe 	 * 5.reload the saved document and check the paragraph outline and numbering
424a089d9bSLiu Zhe 	 */
434a089d9bSLiu Zhe 	@Test
444a089d9bSLiu Zhe 	public void testNumberingBulletIndentAtAndAlignAt() throws Exception {
454a089d9bSLiu Zhe 
464a089d9bSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
474a089d9bSLiu Zhe 		xText = xTextDocument.getText();
484a089d9bSLiu Zhe 		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!" +
494a089d9bSLiu Zhe 				"Hello,world!Hello,world!");
504a089d9bSLiu Zhe 		//create cursor to select paragraph and formating paragraph
514a089d9bSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
524a089d9bSLiu Zhe 		//create paragraph property set
534a089d9bSLiu Zhe 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
544a089d9bSLiu Zhe 		//create document service factory
554a089d9bSLiu Zhe 		XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
564a089d9bSLiu Zhe 		//set numbering character
574a089d9bSLiu Zhe 		XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
584a089d9bSLiu Zhe 		PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue(),new PropertyValue()};
594a089d9bSLiu Zhe 		propsRule[0].Name = "NumberingType";
604a089d9bSLiu Zhe 		propsRule[0].Value = NumberingType.ARABIC;
614a089d9bSLiu Zhe 		propsRule[1].Name = "IndentAt";
624a089d9bSLiu Zhe 		propsRule[1].Value = 499;
634a089d9bSLiu Zhe 		propsRule[2].Name = "FirstLineIndent";
644a089d9bSLiu Zhe 		propsRule[2].Value = 199;
654a089d9bSLiu Zhe 		XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
664a089d9bSLiu Zhe 		xReplaceRule.replaceByIndex(0, propsRule);
674a089d9bSLiu Zhe 		//set paragraph numbering and bullet character
684a089d9bSLiu Zhe 		xTextProps.setPropertyValue("NumberingRules", xNumRule);
694a089d9bSLiu Zhe 		//save to odt
704a089d9bSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
714a089d9bSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
724a089d9bSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
734a089d9bSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
744a089d9bSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
754a089d9bSLiu Zhe 		aStoreProperties_odt[0].Value = true;
764a089d9bSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
774a089d9bSLiu Zhe 		aStoreProperties_odt[1].Value = "writer8";
784a089d9bSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
794a089d9bSLiu Zhe 		//save to doc
804a089d9bSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
814a089d9bSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
824a089d9bSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
834a089d9bSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
844a089d9bSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
854a089d9bSLiu Zhe 		aStoreProperties_doc[0].Value = true;
864a089d9bSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
874a089d9bSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
884a089d9bSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
894a089d9bSLiu Zhe 		app.closeDocument(xTextDocument);
904a089d9bSLiu Zhe 
914a089d9bSLiu Zhe 		//reopen the document
924a089d9bSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
934a089d9bSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
944a089d9bSLiu Zhe 		XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
954a089d9bSLiu Zhe 		XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
964a089d9bSLiu Zhe 		PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
974a089d9bSLiu Zhe 		//verify paragraph numbering and bullet alignment
984a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet","IndentAt",propsRule_assert_odt[10].Name);
994a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet",499,propsRule_assert_odt[10].Value);
1004a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name);
1014a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value);
1024a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet","FirstLineIndent",propsRule_assert_odt[9].Name);
1034a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet",199,propsRule_assert_odt[9].Value);
1044a089d9bSLiu Zhe 
1054a089d9bSLiu Zhe 		//reopen the document
1064a089d9bSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
1074a089d9bSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
1084a089d9bSLiu Zhe 		XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
1094a089d9bSLiu Zhe 		PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
1104a089d9bSLiu Zhe 		//verify paragraph numbering and bullet alignment
1114a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet","IndentAt",propsRule_assert_doc[10].Name);
1124a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet",499,propsRule_assert_doc[10].Value);
1134a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name);
1144a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value);
1154a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet","FirstLineIndent",propsRule_assert_doc[9].Name);
1164a089d9bSLiu Zhe 		assertEquals("assert numbering and bullet",199,propsRule_assert_doc[9].Value);
1174a089d9bSLiu Zhe 	}
1184a089d9bSLiu Zhe }
119