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