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.ShadowFormat; 14 import com.sun.star.table.ShadowLocation; 15 import com.sun.star.text.*; 16 import com.sun.star.beans.*; 17 import com.sun.star.frame.XStorable; 18 import com.sun.star.uno.UnoRuntime; 19 20 public class ParagraphShadow { 21 private static final UnoApp app = new UnoApp(); 22 XText xText = null; 23 24 @Before 25 public void setUp() throws Exception { 26 app.start(); 27 28 } 29 30 @After 31 public void tearDown() throws Exception { 32 app.close(); 33 } 34 /* 35 * test paragraph background color 36 * 1.new a text document 37 * 2.insert some text 38 * 3.set paragraph shadow 39 * 4.save and close the document 40 * 5.reload the saved document and check the paragraph shadow 41 */ 42 @Test@Ignore("Bug #120697 - [testUNO patch]paragraph shadow effect lost when save to doc.") 43 public void testParagraphShadow_BottomRight() throws Exception { 44 45 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 46 xText = xTextDocument.getText(); 47 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!" + 48 "Hello,world!Hello,world!"); 49 // create text cursor for selecting and formatting text 50 XTextCursor xTextCursor = xText.createTextCursor(); 51 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 52 //set paragraph background color 53 ShadowFormat shadowFormat=new ShadowFormat(); 54 shadowFormat.Location=ShadowLocation.BOTTOM_RIGHT; 55 shadowFormat.ShadowWidth=101; 56 shadowFormat.Color=0x00FF00FF; 57 xCursorProps.setPropertyValue("ParaShadowFormat",shadowFormat); 58 //save to odt 59 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 60 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 61 aStoreProperties_odt[0] = new PropertyValue(); 62 aStoreProperties_odt[1] = new PropertyValue(); 63 aStoreProperties_odt[0].Name = "Override"; 64 aStoreProperties_odt[0].Value = true; 65 aStoreProperties_odt[1].Name = "FilterName"; 66 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 67 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 68 //save to doc 69 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 70 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 71 aStoreProperties_doc[0] = new PropertyValue(); 72 aStoreProperties_doc[1] = new PropertyValue(); 73 aStoreProperties_doc[0].Name = "Override"; 74 aStoreProperties_doc[0].Value = true; 75 aStoreProperties_doc[1].Name = "FilterName"; 76 aStoreProperties_doc[1].Value = "MS Word 97"; 77 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 78 app.closeDocument(xTextDocument); 79 80 //reopen the document 81 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 82 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 83 //verify paragraph background color 84 ShadowFormat shadowFormat_Assert1=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_odt.getPropertyValue("ParaShadowFormat")); 85 assertEquals("assert shadow location",ShadowLocation.BOTTOM_RIGHT,shadowFormat_Assert1.Location); 86 assertEquals("assert shadow width",101,shadowFormat_Assert1.ShadowWidth); 87 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert1.Color); 88 89 //reopen the document 90 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 91 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 92 //verify paragraph background color 93 ShadowFormat shadowFormat_Assert2=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_doc.getPropertyValue("ParaShadowFormat")); 94 assertEquals("assert shadow location",ShadowLocation.BOTTOM_RIGHT,shadowFormat_Assert2.Location); 95 assertEquals("assert shadow width",100,shadowFormat_Assert2.ShadowWidth); 96 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert2.Color); 97 } 98 @Test@Ignore("Bug #120697 - [testUNO patch]paragraph shadow effect lost when save to doc.") 99 public void testParagraphShadow_BottomLeft() throws Exception { 100 101 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 102 xText = xTextDocument.getText(); 103 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!" + 104 "Hello,world!Hello,world!"); 105 // create text cursor for selecting and formatting text 106 XTextCursor xTextCursor = xText.createTextCursor(); 107 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 108 //set paragraph background color 109 ShadowFormat shadowFormat=new ShadowFormat(); 110 shadowFormat.Location=ShadowLocation.BOTTOM_LEFT; 111 shadowFormat.ShadowWidth=101; 112 shadowFormat.Color=0x00FF00FF; 113 xCursorProps.setPropertyValue("ParaShadowFormat",shadowFormat); 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 background color 140 ShadowFormat shadowFormat_Assert1=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_odt.getPropertyValue("ParaShadowFormat")); 141 assertEquals("assert shadow location",ShadowLocation.BOTTOM_LEFT,shadowFormat_Assert1.Location); 142 assertEquals("assert shadow width",101,shadowFormat_Assert1.ShadowWidth); 143 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert1.Color); 144 145 //reopen the document 146 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 147 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 148 //verify paragraph background color 149 ShadowFormat shadowFormat_Assert2=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_doc.getPropertyValue("ParaShadowFormat")); 150 assertEquals("assert shadow location",ShadowLocation.BOTTOM_LEFT,shadowFormat_Assert2.Location); 151 assertEquals("assert shadow width",100,shadowFormat_Assert2.ShadowWidth); 152 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert2.Color); 153 } 154 @Test@Ignore("Bug #120697 - [testUNO patch]paragraph shadow effect lost when save to doc.") 155 public void testParagraphShadow_TopLeft() throws Exception { 156 157 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 158 xText = xTextDocument.getText(); 159 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!" + 160 "Hello,world!Hello,world!"); 161 // create text cursor for selecting and formatting text 162 XTextCursor xTextCursor = xText.createTextCursor(); 163 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 164 //set paragraph background color 165 ShadowFormat shadowFormat=new ShadowFormat(); 166 shadowFormat.Location=ShadowLocation.TOP_LEFT; 167 shadowFormat.ShadowWidth=101; 168 shadowFormat.Color=0x00FF00FF; 169 xCursorProps.setPropertyValue("ParaShadowFormat",shadowFormat); 170 //save to odt 171 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 172 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 173 aStoreProperties_odt[0] = new PropertyValue(); 174 aStoreProperties_odt[1] = new PropertyValue(); 175 aStoreProperties_odt[0].Name = "Override"; 176 aStoreProperties_odt[0].Value = true; 177 aStoreProperties_odt[1].Name = "FilterName"; 178 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 179 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 180 //save to doc 181 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 182 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 183 aStoreProperties_doc[0] = new PropertyValue(); 184 aStoreProperties_doc[1] = new PropertyValue(); 185 aStoreProperties_doc[0].Name = "Override"; 186 aStoreProperties_doc[0].Value = true; 187 aStoreProperties_doc[1].Name = "FilterName"; 188 aStoreProperties_doc[1].Value = "MS Word 97"; 189 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 190 app.closeDocument(xTextDocument); 191 192 //reopen the document 193 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 194 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 195 //verify paragraph background color 196 ShadowFormat shadowFormat_Assert1=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_odt.getPropertyValue("ParaShadowFormat")); 197 assertEquals("assert shadow location",ShadowLocation.TOP_LEFT,shadowFormat_Assert1.Location); 198 assertEquals("assert shadow width",101,shadowFormat_Assert1.ShadowWidth); 199 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert1.Color); 200 201 //reopen the document 202 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 203 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 204 //verify paragraph background color 205 ShadowFormat shadowFormat_Assert2=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_doc.getPropertyValue("ParaShadowFormat")); 206 assertEquals("assert shadow location",ShadowLocation.TOP_LEFT,shadowFormat_Assert2.Location); 207 assertEquals("assert shadow width",100,shadowFormat_Assert2.ShadowWidth); 208 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert2.Color); 209 } 210 @Test@Ignore("Bug #120697 - [testUNO patch]paragraph shadow effect lost when save to doc.") 211 public void testParagraphShadow_TopRight() throws Exception { 212 213 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 214 xText = xTextDocument.getText(); 215 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!" + 216 "Hello,world!Hello,world!"); 217 // create text cursor for selecting and formatting text 218 XTextCursor xTextCursor = xText.createTextCursor(); 219 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 220 //set paragraph background color 221 ShadowFormat shadowFormat=new ShadowFormat(); 222 shadowFormat.Location=ShadowLocation.TOP_RIGHT; 223 shadowFormat.ShadowWidth=101; 224 shadowFormat.Color=0x00FF00FF; 225 xCursorProps.setPropertyValue("ParaShadowFormat",shadowFormat); 226 //save to odt 227 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 228 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 229 aStoreProperties_odt[0] = new PropertyValue(); 230 aStoreProperties_odt[1] = new PropertyValue(); 231 aStoreProperties_odt[0].Name = "Override"; 232 aStoreProperties_odt[0].Value = true; 233 aStoreProperties_odt[1].Name = "FilterName"; 234 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 235 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 236 //save to doc 237 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 238 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 239 aStoreProperties_doc[0] = new PropertyValue(); 240 aStoreProperties_doc[1] = new PropertyValue(); 241 aStoreProperties_doc[0].Name = "Override"; 242 aStoreProperties_doc[0].Value = true; 243 aStoreProperties_doc[1].Name = "FilterName"; 244 aStoreProperties_doc[1].Value = "MS Word 97"; 245 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 246 app.closeDocument(xTextDocument); 247 248 //reopen the document 249 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 250 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 251 //verify paragraph background color 252 ShadowFormat shadowFormat_Assert1=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_odt.getPropertyValue("ParaShadowFormat")); 253 assertEquals("assert shadow location",ShadowLocation.TOP_RIGHT,shadowFormat_Assert1.Location); 254 assertEquals("assert shadow width",101,shadowFormat_Assert1.ShadowWidth); 255 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert1.Color); 256 257 //reopen the document 258 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 259 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 260 //verify paragraph background color 261 ShadowFormat shadowFormat_Assert2=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_doc.getPropertyValue("ParaShadowFormat")); 262 assertEquals("assert shadow location",ShadowLocation.TOP_RIGHT,shadowFormat_Assert2.Location); 263 assertEquals("assert shadow width",100,shadowFormat_Assert2.ShadowWidth); 264 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert2.Color); 265 } 266 @Test 267 public void testParagraphShadow_None() throws Exception { 268 269 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 270 xText = xTextDocument.getText(); 271 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!" + 272 "Hello,world!Hello,world!"); 273 // create text cursor for selecting and formatting text 274 XTextCursor xTextCursor = xText.createTextCursor(); 275 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 276 //set paragraph background color 277 ShadowFormat shadowFormat=new ShadowFormat(); 278 shadowFormat.Location=ShadowLocation.NONE; 279 shadowFormat.ShadowWidth=101; 280 shadowFormat.Color=0x00FF00FF; 281 xCursorProps.setPropertyValue("ParaShadowFormat",shadowFormat); 282 //save to odt 283 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 284 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 285 aStoreProperties_odt[0] = new PropertyValue(); 286 aStoreProperties_odt[1] = new PropertyValue(); 287 aStoreProperties_odt[0].Name = "Override"; 288 aStoreProperties_odt[0].Value = true; 289 aStoreProperties_odt[1].Name = "FilterName"; 290 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 291 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 292 //save to doc 293 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 294 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 295 aStoreProperties_doc[0] = new PropertyValue(); 296 aStoreProperties_doc[1] = new PropertyValue(); 297 aStoreProperties_doc[0].Name = "Override"; 298 aStoreProperties_doc[0].Value = true; 299 aStoreProperties_doc[1].Name = "FilterName"; 300 aStoreProperties_doc[1].Value = "MS Word 97"; 301 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 302 app.closeDocument(xTextDocument); 303 304 //reopen the document 305 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 306 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 307 //verify paragraph background color 308 ShadowFormat shadowFormat_Assert1=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_odt.getPropertyValue("ParaShadowFormat")); 309 assertEquals("assert shadow location",ShadowLocation.NONE,shadowFormat_Assert1.Location); 310 311 //reopen the document 312 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 313 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 314 //verify paragraph background color 315 ShadowFormat shadowFormat_Assert2=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xCursorProps_Assert_doc.getPropertyValue("ParaShadowFormat")); 316 assertEquals("assert shadow location",ShadowLocation.NONE,shadowFormat_Assert2.Location); 317 } 318 } 319