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.table.BorderLine; 14 import com.sun.star.text.*; 15 import com.sun.star.beans.*; 16 import com.sun.star.frame.XStorable; 17 import com.sun.star.uno.UnoRuntime; 18 19 public class ParagraphBorder { 20 private static final UnoApp app = new UnoApp(); 21 XText xText = null; 22 23 @Before 24 public void setUp() throws Exception { 25 app.start(); 26 27 } 28 29 @After 30 public void tearDown() throws Exception { 31 app.close(); 32 } 33 /* 34 * test paragraph background color 35 * 1.new a text document 36 * 2.insert some text 37 * 3.set paragraph border 38 * 4.save and close the document 39 * 5.reload the saved document and check the paragraph border 40 */ 41 @Test@Ignore("Bug #120694 - [testUNO patch]the paragraph border line style change when save to doc.") 42 public void testParagraphBorderSetting() throws Exception { 43 44 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 45 xText = xTextDocument.getText(); 46 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!" + 47 "Hello,world!Hello,world!"); 48 // create text cursor for selecting and formatting text 49 XTextCursor xTextCursor = xText.createTextCursor(); 50 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 51 BorderLine[]borderLine=new BorderLine[] {new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine()}; 52 borderLine[0].Color=0x00FF0000; 53 borderLine[0].InnerLineWidth=101; 54 borderLine[0].OuterLineWidth=19; 55 borderLine[0].LineDistance=100; 56 borderLine[1].Color =0x00FFFF00; 57 borderLine[1].InnerLineWidth=101; 58 borderLine[1].OuterLineWidth=19; 59 borderLine[1].LineDistance=101; 60 borderLine[2].Color =0x0000FF00; 61 borderLine[2].InnerLineWidth=150; 62 borderLine[2].OuterLineWidth=19; 63 borderLine[2].LineDistance=101; 64 borderLine[3].Color =0x0000FF00; 65 borderLine[3].InnerLineWidth=150; 66 borderLine[3].OuterLineWidth=19; 67 borderLine[3].LineDistance=101; 68 xCursorProps.setPropertyValue("LeftBorder", borderLine[0]); 69 xCursorProps.setPropertyValue("RightBorder", borderLine[1]); 70 xCursorProps.setPropertyValue("TopBorder", borderLine[2]); 71 xCursorProps.setPropertyValue("BottomBorder", borderLine[3]); 72 //save to odt 73 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 74 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 75 aStoreProperties_odt[0] = new PropertyValue(); 76 aStoreProperties_odt[1] = new PropertyValue(); 77 aStoreProperties_odt[0].Name = "Override"; 78 aStoreProperties_odt[0].Value = true; 79 aStoreProperties_odt[1].Name = "FilterName"; 80 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 81 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 82 //save to doc 83 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 84 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 85 aStoreProperties_doc[0] = new PropertyValue(); 86 aStoreProperties_doc[1] = new PropertyValue(); 87 aStoreProperties_doc[0].Name = "Override"; 88 aStoreProperties_doc[0].Value = true; 89 aStoreProperties_doc[1].Name = "FilterName"; 90 aStoreProperties_doc[1].Value = "MS Word 97"; 91 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 92 app.closeDocument(xTextDocument); 93 94 //reopen the document 95 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 96 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 97 //verify paragraph border 98 Object borderLine_odt[]={xCursorProps_Assert_odt.getPropertyValue("LeftBorder"),xCursorProps_Assert_odt.getPropertyValue("RightBorder"),xCursorProps_Assert_odt.getPropertyValue("TopBorder"),xCursorProps_Assert_odt.getPropertyValue("BottomBorder")}; 99 BorderLine leftborderLine_odt=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_odt[0]); 100 assertEquals("assert paragraph left border",0x00FF0000,leftborderLine_odt.Color); 101 assertEquals("assert paragraph left border",101,leftborderLine_odt.InnerLineWidth); 102 assertEquals("assert paragraph left border",19,leftborderLine_odt.OuterLineWidth); 103 assertEquals("assert paragraph left border",101,leftborderLine_odt.LineDistance); 104 105 BorderLine rightborderLine_odt=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_odt[1]); 106 assertEquals("assert paragraph left border",0x00FFFF00,rightborderLine_odt.Color); 107 assertEquals("assert paragraph left border",101,rightborderLine_odt.InnerLineWidth); 108 assertEquals("assert paragraph left border",19,rightborderLine_odt.OuterLineWidth); 109 assertEquals("assert paragraph left border",101,rightborderLine_odt.LineDistance); 110 111 BorderLine topborderLine_odt=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_odt[2]); 112 assertEquals("assert paragraph left border",0x0000FF00,topborderLine_odt.Color); 113 assertEquals("assert paragraph left border",150,topborderLine_odt.InnerLineWidth); 114 assertEquals("assert paragraph left border",19,topborderLine_odt.OuterLineWidth); 115 assertEquals("assert paragraph left border",101,topborderLine_odt.LineDistance); 116 117 BorderLine bottomtborderLine_odt=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_odt[3]); 118 assertEquals("assert paragraph left border",0x0000FF00,bottomtborderLine_odt.Color); 119 assertEquals("assert paragraph left border",150,bottomtborderLine_odt.InnerLineWidth); 120 assertEquals("assert paragraph left border",19,bottomtborderLine_odt.OuterLineWidth); 121 assertEquals("assert paragraph left border",101,bottomtborderLine_odt.LineDistance); 122 123 //reopen the document 124 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 125 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 126 //verify paragraph border 127 Object borderLine_doc[]={xCursorProps_Assert_doc.getPropertyValue("LeftBorder"),xCursorProps_Assert_doc.getPropertyValue("RightBorder"),xCursorProps_Assert_doc.getPropertyValue("TopBorder"),xCursorProps_Assert_doc.getPropertyValue("BottomBorder")}; 128 BorderLine leftborderLine_doc=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_doc[0]); 129 assertEquals("assert paragraph left border",0x00FF0000,leftborderLine_doc.Color); 130 assertEquals("assert paragraph left border",101,leftborderLine_doc.InnerLineWidth); 131 assertEquals("assert paragraph left border",19,leftborderLine_doc.OuterLineWidth); 132 assertEquals("assert paragraph left border",101,leftborderLine_doc.LineDistance); 133 134 BorderLine rightborderLine_doc=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_doc[1]); 135 assertEquals("assert paragraph left border",0x00FFFF00,rightborderLine_doc.Color); 136 assertEquals("assert paragraph left border",101,rightborderLine_doc.InnerLineWidth); 137 assertEquals("assert paragraph left border",19,rightborderLine_doc.OuterLineWidth); 138 assertEquals("assert paragraph left border",101,rightborderLine_doc.LineDistance); 139 140 BorderLine topborderLine_doc=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_doc[2]); 141 assertEquals("assert paragraph left border",0x0000FF00,topborderLine_doc.Color); 142 assertEquals("assert paragraph left border",150,topborderLine_doc.InnerLineWidth); 143 assertEquals("assert paragraph left border",19,topborderLine_doc.OuterLineWidth); 144 assertEquals("assert paragraph left border",101,topborderLine_doc.LineDistance); 145 146 BorderLine bottomtborderLine_doc=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_doc[3]); 147 assertEquals("assert paragraph left border",0x0000FF00,bottomtborderLine_doc.Color); 148 assertEquals("assert paragraph left border",150,bottomtborderLine_doc.InnerLineWidth); 149 assertEquals("assert paragraph left border",19,bottomtborderLine_doc.OuterLineWidth); 150 assertEquals("assert paragraph left border",101,bottomtborderLine_doc.LineDistance); 151 } 152 } 153