1deb45f49SLiu Zhe /**************************************************************
2deb45f49SLiu Zhe  *
3deb45f49SLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4deb45f49SLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5deb45f49SLiu Zhe  * distributed with this work for additional information
6deb45f49SLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7deb45f49SLiu Zhe  * to you under the Apache License, Version 2.0 (the
8deb45f49SLiu Zhe  * "License"); you may not use this file except in compliance
9deb45f49SLiu Zhe  * with the License.  You may obtain a copy of the License at
10deb45f49SLiu Zhe  *
11deb45f49SLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12deb45f49SLiu Zhe  *
13deb45f49SLiu Zhe  * Unless required by applicable law or agreed to in writing,
14deb45f49SLiu Zhe  * software distributed under the License is distributed on an
15deb45f49SLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16deb45f49SLiu Zhe  * KIND, either express or implied.  See the License for the
17deb45f49SLiu Zhe  * specific language governing permissions and limitations
18deb45f49SLiu Zhe  * under the License.
19deb45f49SLiu Zhe  *
20deb45f49SLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe package fvt.uno.sw.page;
22deb45f49SLiu Zhe 
23deb45f49SLiu Zhe import static org.openoffice.test.common.Testspace.*;
24deb45f49SLiu Zhe 
25deb45f49SLiu Zhe import java.io.File;
26deb45f49SLiu Zhe import java.util.Arrays;
27deb45f49SLiu Zhe import java.util.Collection;
28deb45f49SLiu Zhe 
29deb45f49SLiu Zhe import org.junit.After;
30deb45f49SLiu Zhe import org.junit.Before;
31deb45f49SLiu Zhe import org.junit.Test;
32deb45f49SLiu Zhe import org.junit.Ignore;
33deb45f49SLiu Zhe import org.junit.Assert;
34deb45f49SLiu Zhe import org.junit.runner.RunWith;
35deb45f49SLiu Zhe import org.junit.runners.Parameterized;
36deb45f49SLiu Zhe import org.junit.runners.Parameterized.Parameters;
37deb45f49SLiu Zhe 
38deb45f49SLiu Zhe import org.openoffice.test.common.FileUtil;
39deb45f49SLiu Zhe import org.openoffice.test.uno.UnoApp;
40deb45f49SLiu Zhe 
41deb45f49SLiu Zhe import testlib.uno.SWUtil;
42deb45f49SLiu Zhe import com.sun.star.text.XTextDocument;
43deb45f49SLiu Zhe import com.sun.star.uno.UnoRuntime;
44deb45f49SLiu Zhe import com.sun.star.lang.XComponent;
45deb45f49SLiu Zhe import com.sun.star.table.BorderLine;
46deb45f49SLiu Zhe 
47deb45f49SLiu Zhe /**
48deb45f49SLiu Zhe  * test page's border
49deb45f49SLiu Zhe  * test page's footer/header's border
50deb45f49SLiu Zhe  *
51deb45f49SLiu Zhe  */
52deb45f49SLiu Zhe @RunWith(Parameterized.class)
53deb45f49SLiu Zhe public class CheckBorder {
54deb45f49SLiu Zhe 	UnoApp unoApp = new UnoApp();
55deb45f49SLiu Zhe 	XTextDocument textDocument = null;
56deb45f49SLiu Zhe 	File temp = null;
57deb45f49SLiu Zhe 	String tempFilePathODT = "";
58deb45f49SLiu Zhe 	String tempFilePathDOC = "";
59deb45f49SLiu Zhe 
60deb45f49SLiu Zhe 	private String onProperty = "";
61deb45f49SLiu Zhe 	private String borderProperty = "";
62deb45f49SLiu Zhe 	private String borderDistanceProperty = "";
63deb45f49SLiu Zhe 	private BorderLine borderLine = null;
64deb45f49SLiu Zhe 	private int borderDistance = 0;
65deb45f49SLiu Zhe 
66deb45f49SLiu Zhe 
CheckBorder(String onProperty, String borderProperty, String borderDistanceProperty, int color, int lineDistance, int innerLineWidth, int outerLineWidth, int borderDistance)67deb45f49SLiu Zhe 	public CheckBorder(String onProperty, String borderProperty, String borderDistanceProperty,
68deb45f49SLiu Zhe 			int color, int lineDistance, int innerLineWidth, int outerLineWidth, int borderDistance){
69deb45f49SLiu Zhe 		this.borderLine = new BorderLine();
70deb45f49SLiu Zhe 		this.borderLine.Color = color;
71deb45f49SLiu Zhe 		this.borderLine.LineDistance = (short)lineDistance;
72deb45f49SLiu Zhe 		this.borderLine.InnerLineWidth = (short)innerLineWidth;
73deb45f49SLiu Zhe 		this.borderLine.OuterLineWidth = (short)outerLineWidth;
74deb45f49SLiu Zhe 
75deb45f49SLiu Zhe 		this.onProperty = onProperty;
76deb45f49SLiu Zhe 		this.borderProperty = borderProperty;
77deb45f49SLiu Zhe 		this.borderDistanceProperty = borderDistanceProperty;
78deb45f49SLiu Zhe 
79deb45f49SLiu Zhe 		this.borderDistance = borderDistance;
80deb45f49SLiu Zhe 	}
81deb45f49SLiu Zhe 
82deb45f49SLiu Zhe 	@Parameters
data()83deb45f49SLiu Zhe     public static Collection<Object[]> data(){
84deb45f49SLiu Zhe     	Object[][] params = new Object[][]{
85deb45f49SLiu Zhe     			/*{"FooterIsOn", "LeftBorder", "LeftBorderDistance", 255, 100, 50,70,199},
86deb45f49SLiu Zhe     			{"FooterIsOn", "RightBorder", "RightBorderDistance", 256, 0, 0,0,20},
87deb45f49SLiu Zhe     			{"FooterIsOn", "BottomBorder", "BottomBorderDistance", 65536, 15, 10,30,300},
88deb45f49SLiu Zhe     			{"FooterIsOn", "TopBorder", "TopBorderDistance", 65535, 6, 100,200,400},
89deb45f49SLiu Zhe     			{"FooterIsOn", "FooterLeftBorder", "FooterLeftBorderDistance", 255, 100, 50,70,199},
90deb45f49SLiu Zhe     			{"FooterIsOn", "FooterRightBorder", "FooterRightBorderDistance", 256, 0, 0,0,20},
91deb45f49SLiu Zhe     			{"FooterIsOn", "FooterBottomBorder", "FooterBottomBorderDistance", 65536, 15, 10,30,300},
92deb45f49SLiu Zhe     			{"FooterIsOn", "FooterTopBorder", "FooterTopBorderDistance", 65535, 6, 100,200,400},*/
93deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderLeftBorder", "HeaderLeftBorderDistance", 255, 100, 50,70,0},
94deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderRightBorder", "HeaderRightBorderDistance", 256, 0, 0,0,100},
95deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderBottomBorder", "HeaderBottomBorderDistance", 65536, 15, 10,30,900},
96deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderTopBorder", "HeaderTopBorderDistance", 65535, 6, 100,200,50}
97deb45f49SLiu Zhe     			};
98deb45f49SLiu Zhe     	return Arrays.asList(params);
99deb45f49SLiu Zhe     }
100deb45f49SLiu Zhe 
101deb45f49SLiu Zhe     /**
102deb45f49SLiu Zhe      * test page's border
103deb45f49SLiu Zhe      * test page's footer/header's border
104deb45f49SLiu Zhe      * @throws Exception
105deb45f49SLiu Zhe      */
106deb45f49SLiu Zhe     @Ignore("#120822 - header/footer's border styles are lost when export to DOC format")
107deb45f49SLiu Zhe 	@Test
testFooterHeaderBorder()108deb45f49SLiu Zhe 	public void testFooterHeaderBorder() throws Exception
109deb45f49SLiu Zhe 	{
110deb45f49SLiu Zhe 		XComponent xComponent = unoApp.newDocument("swriter");
111deb45f49SLiu Zhe 		//turn on header/footer
112deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true));
113deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, borderProperty, borderLine);
114deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, borderDistanceProperty, Integer.valueOf(borderDistance));
115deb45f49SLiu Zhe 
116deb45f49SLiu Zhe 		//save as ODT and reopen, get border
117deb45f49SLiu Zhe 		unoApp.saveDocument(xComponent, tempFilePathODT);
118deb45f49SLiu Zhe         unoApp.closeDocument(xComponent);
119deb45f49SLiu Zhe         xComponent = unoApp.loadDocument(tempFilePathODT);
120deb45f49SLiu Zhe 
121deb45f49SLiu Zhe         BorderLine actualBorderLine = (BorderLine)SWUtil.getDefaultPageStyleProperty(xComponent, borderProperty);
122deb45f49SLiu Zhe 		int actualBorderDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, borderDistanceProperty)).intValue();
123deb45f49SLiu Zhe 
124deb45f49SLiu Zhe 		this.compareBorder("ODT:", borderLine, borderDistance);
125deb45f49SLiu Zhe 
126deb45f49SLiu Zhe 		//save as DOC and reopen, get border
127deb45f49SLiu Zhe 	    SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC));
128deb45f49SLiu Zhe 	    unoApp.closeDocument(xComponent);
129deb45f49SLiu Zhe 	    xComponent = unoApp.loadDocument(tempFilePathDOC);
130deb45f49SLiu Zhe 	    actualBorderLine = (BorderLine)SWUtil.getDefaultPageStyleProperty(xComponent, borderProperty);
131deb45f49SLiu Zhe 	    actualBorderDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, borderDistanceProperty)).intValue();
132deb45f49SLiu Zhe 
133deb45f49SLiu Zhe 		this.compareBorder("DOC:", actualBorderLine, actualBorderDistance);
134deb45f49SLiu Zhe 
135deb45f49SLiu Zhe 		unoApp.closeDocument(xComponent);
136deb45f49SLiu Zhe 
137deb45f49SLiu Zhe 	}
138deb45f49SLiu Zhe 
compareBorder(String preDes, BorderLine actualBorderLine, int actualBorderDistance)139deb45f49SLiu Zhe 	private void compareBorder(String preDes, BorderLine actualBorderLine, int actualBorderDistance){
140deb45f49SLiu Zhe 		Assert.assertEquals(preDes + borderProperty + "-->color.",(double)borderLine.Color, (double)actualBorderLine.Color, 2);
141deb45f49SLiu Zhe 		Assert.assertEquals(preDes + borderProperty + "-->LineDistance.", (double)borderLine.LineDistance, (double)actualBorderLine.LineDistance, 2);
142deb45f49SLiu Zhe 		Assert.assertEquals(preDes + borderProperty + "-->InnerLineWidth.", (double)borderLine.InnerLineWidth, (double)actualBorderLine.InnerLineWidth, 2);
143deb45f49SLiu Zhe 		Assert.assertEquals(preDes + borderProperty + "-->OuterLineWidth.", (double)borderLine.OuterLineWidth, (double)actualBorderLine.OuterLineWidth, 2);
144deb45f49SLiu Zhe 
145deb45f49SLiu Zhe 		Assert.assertEquals(preDes + "-->" + borderDistanceProperty, (double)borderLine.OuterLineWidth, (double)actualBorderLine.OuterLineWidth, 2);
146deb45f49SLiu Zhe 	}
147deb45f49SLiu Zhe 
148deb45f49SLiu Zhe 	/**
149deb45f49SLiu Zhe 	 * @throws java.lang.Exception
150deb45f49SLiu Zhe 	 */
151deb45f49SLiu Zhe 	@Before
setUp()152deb45f49SLiu Zhe 	public void setUp() throws Exception {
153deb45f49SLiu Zhe 		unoApp.start();
154deb45f49SLiu Zhe 
155deb45f49SLiu Zhe 		FileUtil.deleteFile(getPath("temp"));
156deb45f49SLiu Zhe 		temp = new File(getPath("temp"));
157deb45f49SLiu Zhe 		temp.mkdirs();
158deb45f49SLiu Zhe 
159deb45f49SLiu Zhe 		tempFilePathODT = temp + "/tempFilePathODT.odt";
160deb45f49SLiu Zhe 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
161deb45f49SLiu Zhe 	}
162deb45f49SLiu Zhe 
163deb45f49SLiu Zhe 	@After
tearDown()164deb45f49SLiu Zhe 	public void tearDown() throws Exception {
165deb45f49SLiu Zhe 		unoApp.close();
166deb45f49SLiu Zhe 	}
167deb45f49SLiu Zhe 
168deb45f49SLiu Zhe 
169deb45f49SLiu Zhe }
170