1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package fvt.uno.sw.paragraph; 23 24 import static org.junit.Assert.*; 25 26 import org.junit.After; 27 import org.junit.Before; 28 import org.junit.Ignore; 29 import org.junit.Test; 30 import org.openoffice.test.common.FileUtil; 31 import org.openoffice.test.common.Testspace; 32 import org.openoffice.test.uno.UnoApp; 33 34 import com.sun.star.table.BorderLine; 35 import com.sun.star.text.*; 36 import com.sun.star.beans.*; 37 import com.sun.star.frame.XStorable; 38 import com.sun.star.uno.UnoRuntime; 39 40 public class ParagraphBorder { 41 private static final UnoApp app = new UnoApp(); 42 XText xText = null; 43 44 @Before setUp()45 public void setUp() throws Exception { 46 app.start(); 47 48 } 49 50 @After tearDown()51 public void tearDown() throws Exception { 52 app.close(); 53 } 54 /* 55 * test paragraph background color 56 * 1.new a text document 57 * 2.insert some text 58 * 3.set paragraph border 59 * 4.save and close the document 60 * 5.reload the saved document and check the paragraph border 61 */ 62 @Test@Ignore("Bug #120694 - [testUNO patch]the paragraph border line style change when save to doc.") testParagraphBorderSetting()63 public void testParagraphBorderSetting() throws Exception { 64 65 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 66 xText = xTextDocument.getText(); 67 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!" + 68 "Hello,world!Hello,world!"); 69 // create text cursor for selecting and formatting text 70 XTextCursor xTextCursor = xText.createTextCursor(); 71 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 72 BorderLine[]borderLine=new BorderLine[] {new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine()}; 73 borderLine[0].Color=0x00FF0000; 74 borderLine[0].InnerLineWidth=101; 75 borderLine[0].OuterLineWidth=19; 76 borderLine[0].LineDistance=100; 77 borderLine[1].Color =0x00FFFF00; 78 borderLine[1].InnerLineWidth=101; 79 borderLine[1].OuterLineWidth=19; 80 borderLine[1].LineDistance=101; 81 borderLine[2].Color =0x0000FF00; 82 borderLine[2].InnerLineWidth=150; 83 borderLine[2].OuterLineWidth=19; 84 borderLine[2].LineDistance=101; 85 borderLine[3].Color =0x0000FF00; 86 borderLine[3].InnerLineWidth=150; 87 borderLine[3].OuterLineWidth=19; 88 borderLine[3].LineDistance=101; 89 xCursorProps.setPropertyValue("LeftBorder", borderLine[0]); 90 xCursorProps.setPropertyValue("RightBorder", borderLine[1]); 91 xCursorProps.setPropertyValue("TopBorder", borderLine[2]); 92 xCursorProps.setPropertyValue("BottomBorder", borderLine[3]); 93 //save to odt 94 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 95 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 96 aStoreProperties_odt[0] = new PropertyValue(); 97 aStoreProperties_odt[1] = new PropertyValue(); 98 aStoreProperties_odt[0].Name = "Override"; 99 aStoreProperties_odt[0].Value = true; 100 aStoreProperties_odt[1].Name = "FilterName"; 101 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 102 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 103 //save to doc 104 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 105 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 106 aStoreProperties_doc[0] = new PropertyValue(); 107 aStoreProperties_doc[1] = new PropertyValue(); 108 aStoreProperties_doc[0].Name = "Override"; 109 aStoreProperties_doc[0].Value = true; 110 aStoreProperties_doc[1].Name = "FilterName"; 111 aStoreProperties_doc[1].Value = "MS Word 97"; 112 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 113 app.closeDocument(xTextDocument); 114 115 //reopen the document 116 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 117 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 118 //verify paragraph border 119 Object borderLine_odt[]={xCursorProps_Assert_odt.getPropertyValue("LeftBorder"),xCursorProps_Assert_odt.getPropertyValue("RightBorder"),xCursorProps_Assert_odt.getPropertyValue("TopBorder"),xCursorProps_Assert_odt.getPropertyValue("BottomBorder")}; 120 BorderLine leftborderLine_odt=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_odt[0]); 121 assertEquals("assert paragraph left border",0x00FF0000,leftborderLine_odt.Color); 122 assertEquals("assert paragraph left border",101,leftborderLine_odt.InnerLineWidth); 123 assertEquals("assert paragraph left border",19,leftborderLine_odt.OuterLineWidth); 124 assertEquals("assert paragraph left border",101,leftborderLine_odt.LineDistance); 125 126 BorderLine rightborderLine_odt=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_odt[1]); 127 assertEquals("assert paragraph left border",0x00FFFF00,rightborderLine_odt.Color); 128 assertEquals("assert paragraph left border",101,rightborderLine_odt.InnerLineWidth); 129 assertEquals("assert paragraph left border",19,rightborderLine_odt.OuterLineWidth); 130 assertEquals("assert paragraph left border",101,rightborderLine_odt.LineDistance); 131 132 BorderLine topborderLine_odt=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_odt[2]); 133 assertEquals("assert paragraph left border",0x0000FF00,topborderLine_odt.Color); 134 assertEquals("assert paragraph left border",150,topborderLine_odt.InnerLineWidth); 135 assertEquals("assert paragraph left border",19,topborderLine_odt.OuterLineWidth); 136 assertEquals("assert paragraph left border",101,topborderLine_odt.LineDistance); 137 138 BorderLine bottomtborderLine_odt=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_odt[3]); 139 assertEquals("assert paragraph left border",0x0000FF00,bottomtborderLine_odt.Color); 140 assertEquals("assert paragraph left border",150,bottomtborderLine_odt.InnerLineWidth); 141 assertEquals("assert paragraph left border",19,bottomtborderLine_odt.OuterLineWidth); 142 assertEquals("assert paragraph left border",101,bottomtborderLine_odt.LineDistance); 143 144 //reopen the document 145 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 146 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 147 //verify paragraph border 148 Object borderLine_doc[]={xCursorProps_Assert_doc.getPropertyValue("LeftBorder"),xCursorProps_Assert_doc.getPropertyValue("RightBorder"),xCursorProps_Assert_doc.getPropertyValue("TopBorder"),xCursorProps_Assert_doc.getPropertyValue("BottomBorder")}; 149 BorderLine leftborderLine_doc=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_doc[0]); 150 assertEquals("assert paragraph left border",0x00FF0000,leftborderLine_doc.Color); 151 assertEquals("assert paragraph left border",101,leftborderLine_doc.InnerLineWidth); 152 assertEquals("assert paragraph left border",19,leftborderLine_doc.OuterLineWidth); 153 assertEquals("assert paragraph left border",101,leftborderLine_doc.LineDistance); 154 155 BorderLine rightborderLine_doc=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_doc[1]); 156 assertEquals("assert paragraph left border",0x00FFFF00,rightborderLine_doc.Color); 157 assertEquals("assert paragraph left border",101,rightborderLine_doc.InnerLineWidth); 158 assertEquals("assert paragraph left border",19,rightborderLine_doc.OuterLineWidth); 159 assertEquals("assert paragraph left border",101,rightborderLine_doc.LineDistance); 160 161 BorderLine topborderLine_doc=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_doc[2]); 162 assertEquals("assert paragraph left border",0x0000FF00,topborderLine_doc.Color); 163 assertEquals("assert paragraph left border",150,topborderLine_doc.InnerLineWidth); 164 assertEquals("assert paragraph left border",19,topborderLine_doc.OuterLineWidth); 165 assertEquals("assert paragraph left border",101,topborderLine_doc.LineDistance); 166 167 BorderLine bottomtborderLine_doc=(BorderLine)UnoRuntime.queryInterface(BorderLine.class,borderLine_doc[3]); 168 assertEquals("assert paragraph left border",0x0000FF00,bottomtborderLine_doc.Color); 169 assertEquals("assert paragraph left border",150,bottomtborderLine_doc.InnerLineWidth); 170 assertEquals("assert paragraph left border",19,bottomtborderLine_doc.OuterLineWidth); 171 assertEquals("assert paragraph left border",101,bottomtborderLine_doc.LineDistance); 172 } 173 } 174