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 package fvt.uno.sw.frame;
22 
23 import static org.junit.Assert.*;
24 
25 import java.util.Arrays;
26 import java.util.Collection;
27 
28 import org.junit.After;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.junit.runners.Parameterized;
34 import org.junit.runners.Parameterized.Parameters;
35 import org.openoffice.test.common.Testspace;
36 import org.openoffice.test.uno.UnoApp;
37 
38 import testlib.uno.SWUtil;
39 
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.container.XNameAccess;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.table.ShadowFormat;
44 import com.sun.star.table.ShadowLocation;
45 import com.sun.star.text.XText;
46 import com.sun.star.text.XTextCursor;
47 import com.sun.star.text.XTextDocument;
48 import com.sun.star.text.XTextFrame;
49 import com.sun.star.text.XTextFramesSupplier;
50 import com.sun.star.uno.UnoRuntime;
51 @RunWith(value = Parameterized.class)
52 public class FrameShadow {
53 	private static final UnoApp app = new UnoApp();
54 	private XTextDocument xTextDocument=null;
55 	private XMultiServiceFactory xWriterFactory=null;
56 	private XText xText=null;
57 	private int shadowColor;
58 	private short shadowWidth;
59 	private ShadowLocation shadowLocation;
FrameShadow(ShadowLocation shadowLocation,short shadowWidth,int shadowColor)60 	public FrameShadow(ShadowLocation shadowLocation,short shadowWidth,int shadowColor){
61 		this.shadowLocation=shadowLocation;
62 		this.shadowWidth=shadowWidth;
63 		this.shadowColor=shadowColor;
64 	}
65 	@Parameters
data()66     public static Collection<Object[]> data(){
67     	Object[][] params = new Object[][]{
68     			{ShadowLocation.NONE,(short)0,0},
69     			{ShadowLocation.TOP_LEFT,(short)101,0x00FF00FF},
70     			{ShadowLocation.TOP_RIGHT,(short)101,0x00FF00FF},
71     			{ShadowLocation.BOTTOM_LEFT,(short)101,0x00FF00FF},
72     			{ShadowLocation.BOTTOM_RIGHT,(short)101,0x00FF00FF},
73     			};
74     	return Arrays.asList(params);
75     }
76 	@Before
setUp()77 	public void setUp() throws Exception {
78 		app.start();
79 	}
80 
81 	@After
tearDown()82 	public void tearDown() throws Exception {
83 		app.close();
84 	}
85 
86 	@Test
testFrameShadow()87 	public void testFrameShadow() throws Exception {
88 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
89 		xText=xTextDocument.getText();
90 		XTextCursor xTextCursor = xText.createTextCursor();
91 		// get internal service factory of the document
92 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
93 		// Create a new table from the document's factory
94 		XTextFrame xTextFrame1 = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
95 		xText.insertTextContent(xTextCursor,xTextFrame1,false);
96 		XPropertySet xTextFrameProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame1);
97 		ShadowFormat shadowFormat=new ShadowFormat();
98 		shadowFormat.Color=shadowColor;
99 		shadowFormat.Location=shadowLocation;
100 		shadowFormat.ShadowWidth=shadowWidth;
101 		xTextFrameProps1.setPropertyValue("ShadowFormat",shadowFormat);
102 		//reopen the document
103 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, SWUtil.saveTo_Override_reload(xTextDocument,"writer8", Testspace.getPath("output/test.odt"),app));
104 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
105 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
106 		XTextFrame xTextFrame_Assert1=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrames_odt.getByName("Frame1"));
107 		XPropertySet xTextFrameProps_assert1 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert1);
108 		ShadowFormat shadowFormat_Assert1=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xTextFrameProps_assert1.getPropertyValue("ShadowFormat"));
109 		assertEquals("assert shadow color",shadowColor,shadowFormat_Assert1.Color);
110 		assertEquals("assert shadow location",shadowLocation,shadowFormat_Assert1.Location);
111 		assertEquals("assert shadow width",shadowWidth,shadowFormat_Assert1.ShadowWidth);
112 	}
113 }
114