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.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 ParagraphNumberingAndBullet_Number_StartWith { 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 numbering start with 40 * 4.save and close the document 41 * 5.reload the saved document and check the paragraph numbering start with 42 */ 43 @Test 44 public void testNumberingBulletStartWith() 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.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,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()}; 59 propsRule[1].Name = "NumberingType"; 60 propsRule[1].Value = NumberingType.ARABIC; 61 propsRule[0].Name = "StartWith"; 62 propsRule[0].Value = (short)5; 63 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 64 xReplaceRule.replaceByIndex(0, propsRule); 65 //set paragraph numbering and bullet character 66 xTextProps.setPropertyValue("NumberingRules", xNumRule); 67 //save to odt 68 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 69 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 70 aStoreProperties_odt[0] = new PropertyValue(); 71 aStoreProperties_odt[1] = new PropertyValue(); 72 aStoreProperties_odt[0].Name = "Override"; 73 aStoreProperties_odt[0].Value = true; 74 aStoreProperties_odt[1].Name = "FilterName"; 75 aStoreProperties_odt[1].Value = "writer8"; 76 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 77 //save to doc 78 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 79 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 80 aStoreProperties_doc[0] = new PropertyValue(); 81 aStoreProperties_doc[1] = new PropertyValue(); 82 aStoreProperties_doc[0].Name = "Override"; 83 aStoreProperties_doc[0].Value = true; 84 aStoreProperties_doc[1].Name = "FilterName"; 85 aStoreProperties_doc[1].Value = "MS Word 97"; 86 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 87 app.closeDocument(xTextDocument); 88 89 //reopen the document 90 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 91 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 92 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 93 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 94 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 95 //verify paragraph numbering and bullet alignment 96 assertEquals("assert numbering and bullet","StartWith",propsRule_assert_odt[5].Name); 97 assertEquals("assert numbering and bullet",(short)5,propsRule_assert_odt[5].Value); 98 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 99 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value); 100 101 //reopen the document 102 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 103 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 104 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 105 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 106 //verify paragraph numbering and bullet alignment 107 assertEquals("assert numbering and bullet","StartWith",propsRule_assert_doc[5].Name); 108 assertEquals("assert numbering and bullet",(short)5,propsRule_assert_doc[5].Value); 109 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 110 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value); 111 } 112 } 113