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.page;
22 
23 import static org.openoffice.test.common.Testspace.*;
24 
25 import java.io.File;
26 import java.util.Arrays;
27 import java.util.Collection;
28 
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.Ignore;
33 import org.junit.Assert;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.Parameterized;
36 import org.junit.runners.Parameterized.Parameters;
37 
38 import org.openoffice.test.common.FileUtil;
39 import org.openoffice.test.uno.UnoApp;
40 
41 import testlib.uno.SWUtil;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.table.BorderLine;
46 import com.sun.star.table.ShadowFormat;
47 import com.sun.star.table.ShadowLocation;
48 
49 /**
50  * test footer/header's border's shadow format.
51  * test page border's shadow format
52  *
53  */
54 @RunWith(Parameterized.class)
55 public class CheckShadowFormat {
56 	UnoApp unoApp = new UnoApp();
57 	XTextDocument textDocument = null;
58 	File temp = null;
59 	String tempFilePathODT = "";
60 	String tempFilePathDOC = "";
61 
62 	private String onProperty = "";
63 	private String shadowFormatProperty = "";
64 
65 	private ShadowFormat shadowFormat = null;
66 
CheckShadowFormat(String onProperty, String shadowFormatProperty, int locationValue, int width, boolean isTransparent, int color)67 	public CheckShadowFormat(String onProperty, String shadowFormatProperty, int locationValue, int width,
68 			boolean isTransparent, int color){
69 		this.onProperty = onProperty;
70 		this.shadowFormatProperty = shadowFormatProperty;
71 		this.shadowFormat = new ShadowFormat();
72 		this.shadowFormat.Location = ShadowLocation.fromInt(locationValue);
73 		this.shadowFormat.ShadowWidth = (short)width;
74 		this.shadowFormat.IsTransparent = isTransparent;
75 		this.shadowFormat.Color = color;
76 	}
77 
78 	/**
79 	 * ShadowLocation
80 	 * 0:NONE
81 	 * 1:TOP_LEFT
82 	 * 2:TOP_RIGHT
83 	 * 3:BOTTOM_LEFT
84 	 * 4:BOTTOM_RIGHT
85 	 * @return
86 	 */
87 	@Parameters
data()88     public static Collection<Object[]> data(){
89     	Object[][] params = new Object[][]{
90     			{"FooterIsOn", "ShadowFormat", 0, 200, false,255},
91     			{"FooterIsOn", "ShadowFormat", 1, 500, false,256},
92     			{"FooterIsOn", "ShadowFormat", 2, 50, false,65535},
93     			{"FooterIsOn", "ShadowFormat", 3, 30, false,65536},
94     			{"FooterIsOn", "ShadowFormat", 4, 1000, false,255},
95     			{"FooterIsOn", "FooterShadowFormat", 0, 200, false,256},
96     			{"FooterIsOn", "FooterShadowFormat", 1, 500, false,65535},
97     			{"FooterIsOn", "FooterShadowFormat", 2, 50, false,65536},
98     			{"FooterIsOn", "FooterShadowFormat", 3, 30, false,255},
99     			{"FooterIsOn", "FooterShadowFormat", 4, 1000, false,256},
100     			{"HeaderIsOn", "HeaderShadowFormat", 0, 200, false,65535},
101     			{"HeaderIsOn", "HeaderShadowFormat", 1, 500, false,65536},
102     			{"HeaderIsOn", "HeaderShadowFormat", 2, 50, false,255},
103     			{"HeaderIsOn", "HeaderShadowFormat", 3, 30, false,256},
104     			{"HeaderIsOn", "HeaderShadowFormat", 4, 1000, false,65536}
105     			};
106     	return Arrays.asList(params);
107     }
108 
109     /**
110      * test footer/header's border's shadow format.
111      * test page border's shadow format
112      * @throws Exception
113      */
114     @Ignore("#120969 - page and page's footer/header's shadow style lost after export to doc format in AOO")
115     @Test
testFooterHeader()116 	public void testFooterHeader() throws Exception
117 	{
118 		XComponent xComponent = unoApp.newDocument("swriter");
119 		//turn on header/footer
120 		SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true));
121 		SWUtil.setDefaultPageStyleProperty(xComponent, shadowFormatProperty, this.shadowFormat);
122 
123 		//save as ODT and reopen, get border
124 		unoApp.saveDocument(xComponent, tempFilePathODT);
125         unoApp.closeDocument(xComponent);
126         xComponent = unoApp.loadDocument(tempFilePathODT);
127 
128 		ShadowFormat actualShadowFormat = (ShadowFormat)SWUtil.getDefaultPageStyleProperty(xComponent, shadowFormatProperty);
129 
130 		this.compare("ODT", actualShadowFormat);
131 
132 		//save as DOC and reopen, get properties
133 	    SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC));
134 	    unoApp.closeDocument(xComponent);
135 	    xComponent = unoApp.loadDocument(tempFilePathDOC);
136 	    actualShadowFormat = (ShadowFormat)SWUtil.getDefaultPageStyleProperty(xComponent, shadowFormatProperty);
137 
138 		this.compare("DOC", actualShadowFormat);
139 
140 		unoApp.closeDocument(xComponent);
141 
142 	}
143 
compare(String preDescription, ShadowFormat actual)144 	private void compare(String preDescription, ShadowFormat actual){
145 		Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Location",this.shadowFormat.Location.getValue(), actual.Location.getValue());
146 		//check shadow width, isTransparent, color if shadow location is not NONE
147 		if(!this.shadowFormat.Location.equals(ShadowLocation.NONE)){
148 			Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Width",(double)this.shadowFormat.ShadowWidth, (double)actual.ShadowWidth, 2);
149 			Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->IsTransparent",this.shadowFormat.IsTransparent, actual.IsTransparent);
150 			Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Color",this.shadowFormat.Color, actual.Color);
151 		}
152 	}
153 
154 
155 	/**
156 	 * @throws java.lang.Exception
157 	 */
158 	@Before
setUp()159 	public void setUp() throws Exception {
160 		unoApp.start();
161 
162 		FileUtil.deleteFile(getPath("temp"));
163 		temp = new File(getPath("temp"));
164 		temp.mkdirs();
165 
166 		tempFilePathODT = temp + "/tempFilePathODT.odt";
167 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
168 	}
169 
170 	@After
tearDown()171 	public void tearDown() throws Exception {
172 		unoApp.close();
173 	}
174 
175 
176 }
177