xref: /AOO41X/test/testuno/source/fvt/uno/sw/page/CheckShadowFormat.java (revision eba4d44a33e5be0b2528d5a9a6f0dcbf65adaa0d)
1*eba4d44aSLiu Zhe /**************************************************************
2*eba4d44aSLiu Zhe  *
3*eba4d44aSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4*eba4d44aSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5*eba4d44aSLiu Zhe  * distributed with this work for additional information
6*eba4d44aSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7*eba4d44aSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8*eba4d44aSLiu Zhe  * "License"); you may not use this file except in compliance
9*eba4d44aSLiu Zhe  * with the License.  You may obtain a copy of the License at
10*eba4d44aSLiu Zhe  *
11*eba4d44aSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12*eba4d44aSLiu Zhe  *
13*eba4d44aSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14*eba4d44aSLiu Zhe  * software distributed under the License is distributed on an
15*eba4d44aSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*eba4d44aSLiu Zhe  * KIND, either express or implied.  See the License for the
17*eba4d44aSLiu Zhe  * specific language governing permissions and limitations
18*eba4d44aSLiu Zhe  * under the License.
19*eba4d44aSLiu Zhe  *
20*eba4d44aSLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe package fvt.uno.sw.page;
22*eba4d44aSLiu Zhe 
23*eba4d44aSLiu Zhe import static org.openoffice.test.common.Testspace.*;
24*eba4d44aSLiu Zhe 
25*eba4d44aSLiu Zhe import java.io.File;
26*eba4d44aSLiu Zhe import java.util.Arrays;
27*eba4d44aSLiu Zhe import java.util.Collection;
28*eba4d44aSLiu Zhe 
29*eba4d44aSLiu Zhe import org.junit.After;
30*eba4d44aSLiu Zhe import org.junit.Before;
31*eba4d44aSLiu Zhe import org.junit.Test;
32*eba4d44aSLiu Zhe import org.junit.Ignore;
33*eba4d44aSLiu Zhe import org.junit.Assert;
34*eba4d44aSLiu Zhe import org.junit.runner.RunWith;
35*eba4d44aSLiu Zhe import org.junit.runners.Parameterized;
36*eba4d44aSLiu Zhe import org.junit.runners.Parameterized.Parameters;
37*eba4d44aSLiu Zhe 
38*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil;
39*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
40*eba4d44aSLiu Zhe 
41*eba4d44aSLiu Zhe import testlib.uno.SWUtil;
42*eba4d44aSLiu Zhe import com.sun.star.text.XTextDocument;
43*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
44*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
45*eba4d44aSLiu Zhe import com.sun.star.table.BorderLine;
46*eba4d44aSLiu Zhe import com.sun.star.table.ShadowFormat;
47*eba4d44aSLiu Zhe import com.sun.star.table.ShadowLocation;
48*eba4d44aSLiu Zhe 
49*eba4d44aSLiu Zhe /**
50*eba4d44aSLiu Zhe  * test footer/header's border's shadow format.
51*eba4d44aSLiu Zhe  * test page border's shadow format
52*eba4d44aSLiu Zhe  *
53*eba4d44aSLiu Zhe  */
54*eba4d44aSLiu Zhe @RunWith(Parameterized.class)
55*eba4d44aSLiu Zhe public class CheckShadowFormat {
56*eba4d44aSLiu Zhe 	UnoApp unoApp = new UnoApp();
57*eba4d44aSLiu Zhe 	XTextDocument textDocument = null;
58*eba4d44aSLiu Zhe 	File temp = null;
59*eba4d44aSLiu Zhe 	String tempFilePathODT = "";
60*eba4d44aSLiu Zhe 	String tempFilePathDOC = "";
61*eba4d44aSLiu Zhe 
62*eba4d44aSLiu Zhe 	private String onProperty = "";
63*eba4d44aSLiu Zhe 	private String shadowFormatProperty = "";
64*eba4d44aSLiu Zhe 
65*eba4d44aSLiu Zhe 	private ShadowFormat shadowFormat = null;
66*eba4d44aSLiu Zhe 
CheckShadowFormat(String onProperty, String shadowFormatProperty, int locationValue, int width, boolean isTransparent, int color)67*eba4d44aSLiu Zhe 	public CheckShadowFormat(String onProperty, String shadowFormatProperty, int locationValue, int width,
68*eba4d44aSLiu Zhe 			boolean isTransparent, int color){
69*eba4d44aSLiu Zhe 		this.onProperty = onProperty;
70*eba4d44aSLiu Zhe 		this.shadowFormatProperty = shadowFormatProperty;
71*eba4d44aSLiu Zhe 		this.shadowFormat = new ShadowFormat();
72*eba4d44aSLiu Zhe 		this.shadowFormat.Location = ShadowLocation.fromInt(locationValue);
73*eba4d44aSLiu Zhe 		this.shadowFormat.ShadowWidth = (short)width;
74*eba4d44aSLiu Zhe 		this.shadowFormat.IsTransparent = isTransparent;
75*eba4d44aSLiu Zhe 		this.shadowFormat.Color = color;
76*eba4d44aSLiu Zhe 	}
77*eba4d44aSLiu Zhe 
78*eba4d44aSLiu Zhe 	/**
79*eba4d44aSLiu Zhe 	 * ShadowLocation
80*eba4d44aSLiu Zhe 	 * 0:NONE
81*eba4d44aSLiu Zhe 	 * 1:TOP_LEFT
82*eba4d44aSLiu Zhe 	 * 2:TOP_RIGHT
83*eba4d44aSLiu Zhe 	 * 3:BOTTOM_LEFT
84*eba4d44aSLiu Zhe 	 * 4:BOTTOM_RIGHT
85*eba4d44aSLiu Zhe 	 * @return
86*eba4d44aSLiu Zhe 	 */
87*eba4d44aSLiu Zhe 	@Parameters
data()88*eba4d44aSLiu Zhe     public static Collection<Object[]> data(){
89*eba4d44aSLiu Zhe     	Object[][] params = new Object[][]{
90*eba4d44aSLiu Zhe     			{"FooterIsOn", "ShadowFormat", 0, 200, false,255},
91*eba4d44aSLiu Zhe     			{"FooterIsOn", "ShadowFormat", 1, 500, false,256},
92*eba4d44aSLiu Zhe     			{"FooterIsOn", "ShadowFormat", 2, 50, false,65535},
93*eba4d44aSLiu Zhe     			{"FooterIsOn", "ShadowFormat", 3, 30, false,65536},
94*eba4d44aSLiu Zhe     			{"FooterIsOn", "ShadowFormat", 4, 1000, false,255},
95*eba4d44aSLiu Zhe     			{"FooterIsOn", "FooterShadowFormat", 0, 200, false,256},
96*eba4d44aSLiu Zhe     			{"FooterIsOn", "FooterShadowFormat", 1, 500, false,65535},
97*eba4d44aSLiu Zhe     			{"FooterIsOn", "FooterShadowFormat", 2, 50, false,65536},
98*eba4d44aSLiu Zhe     			{"FooterIsOn", "FooterShadowFormat", 3, 30, false,255},
99*eba4d44aSLiu Zhe     			{"FooterIsOn", "FooterShadowFormat", 4, 1000, false,256},
100*eba4d44aSLiu Zhe     			{"HeaderIsOn", "HeaderShadowFormat", 0, 200, false,65535},
101*eba4d44aSLiu Zhe     			{"HeaderIsOn", "HeaderShadowFormat", 1, 500, false,65536},
102*eba4d44aSLiu Zhe     			{"HeaderIsOn", "HeaderShadowFormat", 2, 50, false,255},
103*eba4d44aSLiu Zhe     			{"HeaderIsOn", "HeaderShadowFormat", 3, 30, false,256},
104*eba4d44aSLiu Zhe     			{"HeaderIsOn", "HeaderShadowFormat", 4, 1000, false,65536}
105*eba4d44aSLiu Zhe     			};
106*eba4d44aSLiu Zhe     	return Arrays.asList(params);
107*eba4d44aSLiu Zhe     }
108*eba4d44aSLiu Zhe 
109*eba4d44aSLiu Zhe     /**
110*eba4d44aSLiu Zhe      * test footer/header's border's shadow format.
111*eba4d44aSLiu Zhe      * test page border's shadow format
112*eba4d44aSLiu Zhe      * @throws Exception
113*eba4d44aSLiu Zhe      */
114*eba4d44aSLiu Zhe     @Ignore("#120969 - page and page's footer/header's shadow style lost after export to doc format in AOO")
115*eba4d44aSLiu Zhe     @Test
testFooterHeader()116*eba4d44aSLiu Zhe 	public void testFooterHeader() throws Exception
117*eba4d44aSLiu Zhe 	{
118*eba4d44aSLiu Zhe 		XComponent xComponent = unoApp.newDocument("swriter");
119*eba4d44aSLiu Zhe 		//turn on header/footer
120*eba4d44aSLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true));
121*eba4d44aSLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, shadowFormatProperty, this.shadowFormat);
122*eba4d44aSLiu Zhe 
123*eba4d44aSLiu Zhe 		//save as ODT and reopen, get border
124*eba4d44aSLiu Zhe 		unoApp.saveDocument(xComponent, tempFilePathODT);
125*eba4d44aSLiu Zhe         unoApp.closeDocument(xComponent);
126*eba4d44aSLiu Zhe         xComponent = unoApp.loadDocument(tempFilePathODT);
127*eba4d44aSLiu Zhe 
128*eba4d44aSLiu Zhe 		ShadowFormat actualShadowFormat = (ShadowFormat)SWUtil.getDefaultPageStyleProperty(xComponent, shadowFormatProperty);
129*eba4d44aSLiu Zhe 
130*eba4d44aSLiu Zhe 		this.compare("ODT", actualShadowFormat);
131*eba4d44aSLiu Zhe 
132*eba4d44aSLiu Zhe 		//save as DOC and reopen, get properties
133*eba4d44aSLiu Zhe 	    SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC));
134*eba4d44aSLiu Zhe 	    unoApp.closeDocument(xComponent);
135*eba4d44aSLiu Zhe 	    xComponent = unoApp.loadDocument(tempFilePathDOC);
136*eba4d44aSLiu Zhe 	    actualShadowFormat = (ShadowFormat)SWUtil.getDefaultPageStyleProperty(xComponent, shadowFormatProperty);
137*eba4d44aSLiu Zhe 
138*eba4d44aSLiu Zhe 		this.compare("DOC", actualShadowFormat);
139*eba4d44aSLiu Zhe 
140*eba4d44aSLiu Zhe 		unoApp.closeDocument(xComponent);
141*eba4d44aSLiu Zhe 
142*eba4d44aSLiu Zhe 	}
143*eba4d44aSLiu Zhe 
compare(String preDescription, ShadowFormat actual)144*eba4d44aSLiu Zhe 	private void compare(String preDescription, ShadowFormat actual){
145*eba4d44aSLiu Zhe 		Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Location",this.shadowFormat.Location.getValue(), actual.Location.getValue());
146*eba4d44aSLiu Zhe 		//check shadow width, isTransparent, color if shadow location is not NONE
147*eba4d44aSLiu Zhe 		if(!this.shadowFormat.Location.equals(ShadowLocation.NONE)){
148*eba4d44aSLiu Zhe 			Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Width",(double)this.shadowFormat.ShadowWidth, (double)actual.ShadowWidth, 2);
149*eba4d44aSLiu Zhe 			Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->IsTransparent",this.shadowFormat.IsTransparent, actual.IsTransparent);
150*eba4d44aSLiu Zhe 			Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Color",this.shadowFormat.Color, actual.Color);
151*eba4d44aSLiu Zhe 		}
152*eba4d44aSLiu Zhe 	}
153*eba4d44aSLiu Zhe 
154*eba4d44aSLiu Zhe 
155*eba4d44aSLiu Zhe 	/**
156*eba4d44aSLiu Zhe 	 * @throws java.lang.Exception
157*eba4d44aSLiu Zhe 	 */
158*eba4d44aSLiu Zhe 	@Before
setUp()159*eba4d44aSLiu Zhe 	public void setUp() throws Exception {
160*eba4d44aSLiu Zhe 		unoApp.start();
161*eba4d44aSLiu Zhe 
162*eba4d44aSLiu Zhe 		FileUtil.deleteFile(getPath("temp"));
163*eba4d44aSLiu Zhe 		temp = new File(getPath("temp"));
164*eba4d44aSLiu Zhe 		temp.mkdirs();
165*eba4d44aSLiu Zhe 
166*eba4d44aSLiu Zhe 		tempFilePathODT = temp + "/tempFilePathODT.odt";
167*eba4d44aSLiu Zhe 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
168*eba4d44aSLiu Zhe 	}
169*eba4d44aSLiu Zhe 
170*eba4d44aSLiu Zhe 	@After
tearDown()171*eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
172*eba4d44aSLiu Zhe 		unoApp.close();
173*eba4d44aSLiu Zhe 	}
174*eba4d44aSLiu Zhe 
175*eba4d44aSLiu Zhe 
176*eba4d44aSLiu Zhe }
177