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 
47 /**
48  * test page's border
49  * test page's footer/header's border
50  *
51  */
52 @RunWith(Parameterized.class)
53 public class CheckBorder {
54 	UnoApp unoApp = new UnoApp();
55 	XTextDocument textDocument = null;
56 	File temp = null;
57 	String tempFilePathODT = "";
58 	String tempFilePathDOC = "";
59 
60 	private String onProperty = "";
61 	private String borderProperty = "";
62 	private String borderDistanceProperty = "";
63 	private BorderLine borderLine = null;
64 	private int borderDistance = 0;
65 
66 
CheckBorder(String onProperty, String borderProperty, String borderDistanceProperty, int color, int lineDistance, int innerLineWidth, int outerLineWidth, int borderDistance)67 	public CheckBorder(String onProperty, String borderProperty, String borderDistanceProperty,
68 			int color, int lineDistance, int innerLineWidth, int outerLineWidth, int borderDistance){
69 		this.borderLine = new BorderLine();
70 		this.borderLine.Color = color;
71 		this.borderLine.LineDistance = (short)lineDistance;
72 		this.borderLine.InnerLineWidth = (short)innerLineWidth;
73 		this.borderLine.OuterLineWidth = (short)outerLineWidth;
74 
75 		this.onProperty = onProperty;
76 		this.borderProperty = borderProperty;
77 		this.borderDistanceProperty = borderDistanceProperty;
78 
79 		this.borderDistance = borderDistance;
80 	}
81 
82 	@Parameters
data()83     public static Collection<Object[]> data(){
84     	Object[][] params = new Object[][]{
85     			/*{"FooterIsOn", "LeftBorder", "LeftBorderDistance", 255, 100, 50,70,199},
86     			{"FooterIsOn", "RightBorder", "RightBorderDistance", 256, 0, 0,0,20},
87     			{"FooterIsOn", "BottomBorder", "BottomBorderDistance", 65536, 15, 10,30,300},
88     			{"FooterIsOn", "TopBorder", "TopBorderDistance", 65535, 6, 100,200,400},
89     			{"FooterIsOn", "FooterLeftBorder", "FooterLeftBorderDistance", 255, 100, 50,70,199},
90     			{"FooterIsOn", "FooterRightBorder", "FooterRightBorderDistance", 256, 0, 0,0,20},
91     			{"FooterIsOn", "FooterBottomBorder", "FooterBottomBorderDistance", 65536, 15, 10,30,300},
92     			{"FooterIsOn", "FooterTopBorder", "FooterTopBorderDistance", 65535, 6, 100,200,400},*/
93     			{"HeaderIsOn", "HeaderLeftBorder", "HeaderLeftBorderDistance", 255, 100, 50,70,0},
94     			{"HeaderIsOn", "HeaderRightBorder", "HeaderRightBorderDistance", 256, 0, 0,0,100},
95     			{"HeaderIsOn", "HeaderBottomBorder", "HeaderBottomBorderDistance", 65536, 15, 10,30,900},
96     			{"HeaderIsOn", "HeaderTopBorder", "HeaderTopBorderDistance", 65535, 6, 100,200,50}
97     			};
98     	return Arrays.asList(params);
99     }
100 
101     /**
102      * test page's border
103      * test page's footer/header's border
104      * @throws Exception
105      */
106     @Ignore("#120822 - header/footer's border styles are lost when export to DOC format")
107 	@Test
testFooterHeaderBorder()108 	public void testFooterHeaderBorder() throws Exception
109 	{
110 		XComponent xComponent = unoApp.newDocument("swriter");
111 		//turn on header/footer
112 		SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true));
113 		SWUtil.setDefaultPageStyleProperty(xComponent, borderProperty, borderLine);
114 		SWUtil.setDefaultPageStyleProperty(xComponent, borderDistanceProperty, Integer.valueOf(borderDistance));
115 
116 		//save as ODT and reopen, get border
117 		unoApp.saveDocument(xComponent, tempFilePathODT);
118         unoApp.closeDocument(xComponent);
119         xComponent = unoApp.loadDocument(tempFilePathODT);
120 
121         BorderLine actualBorderLine = (BorderLine)SWUtil.getDefaultPageStyleProperty(xComponent, borderProperty);
122 		int actualBorderDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, borderDistanceProperty)).intValue();
123 
124 		this.compareBorder("ODT:", borderLine, borderDistance);
125 
126 		//save as DOC and reopen, get border
127 	    SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC));
128 	    unoApp.closeDocument(xComponent);
129 	    xComponent = unoApp.loadDocument(tempFilePathDOC);
130 	    actualBorderLine = (BorderLine)SWUtil.getDefaultPageStyleProperty(xComponent, borderProperty);
131 	    actualBorderDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, borderDistanceProperty)).intValue();
132 
133 		this.compareBorder("DOC:", actualBorderLine, actualBorderDistance);
134 
135 		unoApp.closeDocument(xComponent);
136 
137 	}
138 
compareBorder(String preDes, BorderLine actualBorderLine, int actualBorderDistance)139 	private void compareBorder(String preDes, BorderLine actualBorderLine, int actualBorderDistance){
140 		Assert.assertEquals(preDes + borderProperty + "-->color.",(double)borderLine.Color, (double)actualBorderLine.Color, 2);
141 		Assert.assertEquals(preDes + borderProperty + "-->LineDistance.", (double)borderLine.LineDistance, (double)actualBorderLine.LineDistance, 2);
142 		Assert.assertEquals(preDes + borderProperty + "-->InnerLineWidth.", (double)borderLine.InnerLineWidth, (double)actualBorderLine.InnerLineWidth, 2);
143 		Assert.assertEquals(preDes + borderProperty + "-->OuterLineWidth.", (double)borderLine.OuterLineWidth, (double)actualBorderLine.OuterLineWidth, 2);
144 
145 		Assert.assertEquals(preDes + "-->" + borderDistanceProperty, (double)borderLine.OuterLineWidth, (double)actualBorderLine.OuterLineWidth, 2);
146 	}
147 
148 	/**
149 	 * @throws java.lang.Exception
150 	 */
151 	@Before
setUp()152 	public void setUp() throws Exception {
153 		unoApp.start();
154 
155 		FileUtil.deleteFile(getPath("temp"));
156 		temp = new File(getPath("temp"));
157 		temp.mkdirs();
158 
159 		tempFilePathODT = temp + "/tempFilePathODT.odt";
160 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
161 	}
162 
163 	@After
tearDown()164 	public void tearDown() throws Exception {
165 		unoApp.close();
166 	}
167 
168 
169 }
170