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 import com.sun.star.text.*; 13 import com.sun.star.beans.*; 14 import com.sun.star.frame.XStorable; 15 import com.sun.star.uno.UnoRuntime; 16 17 public class ParagraphOutlineAndNumbering { 18 private static final UnoApp app = new UnoApp(); 19 XText xText = null; 20 21 @Before 22 public void setUp() throws Exception { 23 app.start(); 24 25 } 26 27 @After 28 public void tearDown() throws Exception { 29 //app.close(); 30 } 31 /* 32 * test paragraph background color 33 * 1.new a text document 34 * 2.insert some text 35 * 3.set paragraph outline and numbering 36 * 4.save and close the document 37 * 5.reload the saved document and check the paragraph outline and numbering 38 */ 39 @Test@Ignore("Bug #120753 - [testUNO patch]paragraph outline level and numbering style change when save to doc") 40 public void testOutlineAndNumbering_NumberStyle() throws Exception { 41 42 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 43 xText = xTextDocument.getText(); 44 xText.setString("we are Chinese,they are American.\nwe are all living in one earth!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!Hello,world!" + 45 "Hello,world!Hello,world!"); 46 XTextCursor xTextCursor=xText.createTextCursor(); 47 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 48 xTextProps.setPropertyValue("OutlineLevel", (short)6); 49 xTextProps.setPropertyValue("NumberingStyleName", "Numbering 2"); 50 xTextProps.setPropertyValue("ParaIsNumberingRestart", true); 51 xTextProps.setPropertyValue("NumberingStartValue", (short)7); 52 xTextProps.setPropertyValue("ParaLineNumberCount",true); 53 xTextProps.setPropertyValue("ParaLineNumberStartValue",(long)4); 54 //save to odt 55 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 56 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 57 aStoreProperties_odt[0] = new PropertyValue(); 58 aStoreProperties_odt[1] = new PropertyValue(); 59 aStoreProperties_odt[0].Name = "Override"; 60 aStoreProperties_odt[0].Value = true; 61 aStoreProperties_odt[1].Name = "FilterName"; 62 aStoreProperties_odt[1].Value = "writer8"; 63 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 64 //save to doc 65 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 66 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 67 aStoreProperties_doc[0] = new PropertyValue(); 68 aStoreProperties_doc[1] = new PropertyValue(); 69 aStoreProperties_doc[0].Name = "Override"; 70 aStoreProperties_doc[0].Value = true; 71 aStoreProperties_doc[1].Name = "FilterName"; 72 aStoreProperties_doc[1].Value = "MS Word 97"; 73 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 74 //app.closeDocument(xTextDocument); 75 76 //reopen the document 77 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 78 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 79 //verify paragraph outline and numbering 80 assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_odt.getPropertyValue("OutlineLevel")); 81 assertEquals("assert paragraph outline and numbering","Numbering 2",xCursorProps_Assert_odt.getPropertyValue("NumberingStyleName")); 82 assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsNumberingRestart")); 83 assertEquals("assert paragraph outline and numbering",(short)7,xCursorProps_Assert_odt.getPropertyValue("NumberingStartValue")); 84 assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberCount")); 85 assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberStartValue")); 86 87 //reopen the document 88 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 89 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 90 //verify paragraph outline and numbering 91 assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_doc.getPropertyValue("OutlineLevel")); 92 assertEquals("assert paragraph outline and numbering","Numbering 2",xCursorProps_Assert_doc.getPropertyValue("NumberingStyleName")); 93 assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsNumberingRestart")); 94 assertEquals("assert paragraph outline and numbering",(short)7,xCursorProps_Assert_doc.getPropertyValue("NumberingStartValue")); 95 assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberCount")); 96 assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberStartValue")); 97 98 } 99 @Test@Ignore("Bug #120753 - [testUNO patch]paragraph outline level and numbering style change when save to doc") 100 public void testOutlineAndNumbering_ListStyle() throws Exception { 101 102 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 103 xText = xTextDocument.getText(); 104 xText.setString("we are Chinese,they are American.\nwe are all living in one earth!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!Hello,world!" + 105 "Hello,world!Hello,world!"); 106 XTextCursor xTextCursor=xText.createTextCursor(); 107 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 108 xTextProps.setPropertyValue("OutlineLevel", (short)3); 109 xTextProps.setPropertyValue("NumberingStyleName", "List 3"); 110 xTextProps.setPropertyValue("ParaIsNumberingRestart", true); 111 xTextProps.setPropertyValue("NumberingStartValue", (short)6); 112 xTextProps.setPropertyValue("ParaLineNumberCount",true); 113 xTextProps.setPropertyValue("ParaLineNumberStartValue",(long)4); 114 //save to odt 115 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 116 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 117 aStoreProperties_odt[0] = new PropertyValue(); 118 aStoreProperties_odt[1] = new PropertyValue(); 119 aStoreProperties_odt[0].Name = "Override"; 120 aStoreProperties_odt[0].Value = true; 121 aStoreProperties_odt[1].Name = "FilterName"; 122 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 123 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 124 //save to doc 125 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 126 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 127 aStoreProperties_doc[0] = new PropertyValue(); 128 aStoreProperties_doc[1] = new PropertyValue(); 129 aStoreProperties_doc[0].Name = "Override"; 130 aStoreProperties_doc[0].Value = true; 131 aStoreProperties_doc[1].Name = "FilterName"; 132 aStoreProperties_doc[1].Value = "MS Word 97"; 133 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 134 //app.closeDocument(xTextDocument); 135 136 //reopen the document 137 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 138 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 139 //verify paragraph outline and numbering 140 assertEquals("assert paragraph outline and numbering",(short)3,xCursorProps_Assert_odt.getPropertyValue("OutlineLevel")); 141 assertEquals("assert paragraph outline and numbering","List 3",xCursorProps_Assert_odt.getPropertyValue("NumberingStyleName")); 142 assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsNumberingRestart")); 143 assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_odt.getPropertyValue("NumberingStartValue")); 144 assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberCount")); 145 assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberStartValue")); 146 147 148 //reopen the document 149 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 150 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 151 //verify paragraph outline and numbering 152 assertEquals("assert paragraph outline and numbering",(short)3,xCursorProps_Assert_doc.getPropertyValue("OutlineLevel")); 153 assertEquals("assert paragraph outline and numbering","List 3",xCursorProps_Assert_doc.getPropertyValue("NumberingStyleName")); 154 assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsNumberingRestart")); 155 assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_doc.getPropertyValue("NumberingStartValue")); 156 assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberCount")); 157 assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberStartValue")); 158 159 } 160 } 161