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