1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski package fvt.uno.sw.page;
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski import static org.openoffice.test.common.Testspace.*;
24*b1cdbd2cSJim Jagielski 
25*b1cdbd2cSJim Jagielski import java.io.File;
26*b1cdbd2cSJim Jagielski import java.util.Arrays;
27*b1cdbd2cSJim Jagielski import java.util.Collection;
28*b1cdbd2cSJim Jagielski 
29*b1cdbd2cSJim Jagielski import org.junit.After;
30*b1cdbd2cSJim Jagielski import org.junit.Before;
31*b1cdbd2cSJim Jagielski import org.junit.Test;
32*b1cdbd2cSJim Jagielski import org.junit.Ignore;
33*b1cdbd2cSJim Jagielski import org.junit.Assert;
34*b1cdbd2cSJim Jagielski import org.junit.runner.RunWith;
35*b1cdbd2cSJim Jagielski import org.junit.runners.Parameterized;
36*b1cdbd2cSJim Jagielski import org.junit.runners.Parameterized.Parameters;
37*b1cdbd2cSJim Jagielski 
38*b1cdbd2cSJim Jagielski import org.openoffice.test.common.FileUtil;
39*b1cdbd2cSJim Jagielski import org.openoffice.test.uno.UnoApp;
40*b1cdbd2cSJim Jagielski 
41*b1cdbd2cSJim Jagielski import testlib.uno.SWUtil;
42*b1cdbd2cSJim Jagielski import com.sun.star.text.XTextDocument;
43*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime;
44*b1cdbd2cSJim Jagielski import com.sun.star.lang.XComponent;
45*b1cdbd2cSJim Jagielski import com.sun.star.table.BorderLine;
46*b1cdbd2cSJim Jagielski 
47*b1cdbd2cSJim Jagielski /**
48*b1cdbd2cSJim Jagielski  * test footer/header's margins, spacing and height.
49*b1cdbd2cSJim Jagielski  *
50*b1cdbd2cSJim Jagielski  */
51*b1cdbd2cSJim Jagielski @RunWith(Parameterized.class)
52*b1cdbd2cSJim Jagielski public class CheckFooterHeader {
53*b1cdbd2cSJim Jagielski 	UnoApp unoApp = new UnoApp();
54*b1cdbd2cSJim Jagielski 	XTextDocument textDocument = null;
55*b1cdbd2cSJim Jagielski 	File temp = null;
56*b1cdbd2cSJim Jagielski 	String tempFilePathODT = "";
57*b1cdbd2cSJim Jagielski 	String tempFilePathDOC = "";
58*b1cdbd2cSJim Jagielski 
59*b1cdbd2cSJim Jagielski 	private String m_onProperty = "";
60*b1cdbd2cSJim Jagielski 
61*b1cdbd2cSJim Jagielski 	private String m_LeftMarginProperty = "";
62*b1cdbd2cSJim Jagielski 	private String m_RightMarginProperty = "";
63*b1cdbd2cSJim Jagielski 	private String m_BodyDistanceProperty = "";
64*b1cdbd2cSJim Jagielski 	private String m_HeightProperty = "";
65*b1cdbd2cSJim Jagielski 
66*b1cdbd2cSJim Jagielski 	private int m_LeftMargin = 0;
67*b1cdbd2cSJim Jagielski 	private int m_RightMargin = 0;
68*b1cdbd2cSJim Jagielski 	private int m_BodyDistance = 0;
69*b1cdbd2cSJim Jagielski 	private int m_Height = 0;
70*b1cdbd2cSJim Jagielski 
71*b1cdbd2cSJim Jagielski 
CheckFooterHeader(String onProperty, String leftMarginProperty, String rightMarginProperty, String bodyDistanceProperty, String heightProperty, int leftMargin, int rightMargin, int bodyDistance, int height)72*b1cdbd2cSJim Jagielski 	public CheckFooterHeader(String onProperty, String leftMarginProperty, String rightMarginProperty, String bodyDistanceProperty, String heightProperty,
73*b1cdbd2cSJim Jagielski 			int leftMargin, int rightMargin, int bodyDistance, int height){
74*b1cdbd2cSJim Jagielski 		m_onProperty = onProperty;
75*b1cdbd2cSJim Jagielski 		m_LeftMarginProperty = leftMarginProperty;
76*b1cdbd2cSJim Jagielski 		m_RightMarginProperty = rightMarginProperty;
77*b1cdbd2cSJim Jagielski 		m_BodyDistanceProperty = bodyDistanceProperty;
78*b1cdbd2cSJim Jagielski 		m_HeightProperty = heightProperty;
79*b1cdbd2cSJim Jagielski 
80*b1cdbd2cSJim Jagielski 		m_LeftMargin = leftMargin;
81*b1cdbd2cSJim Jagielski 		m_RightMargin = rightMargin;
82*b1cdbd2cSJim Jagielski 		m_BodyDistance = bodyDistance;
83*b1cdbd2cSJim Jagielski 		m_BodyDistance = bodyDistance;
84*b1cdbd2cSJim Jagielski 		m_Height = height;
85*b1cdbd2cSJim Jagielski 	}
86*b1cdbd2cSJim Jagielski 
87*b1cdbd2cSJim Jagielski 	@Parameters
data()88*b1cdbd2cSJim Jagielski     public static Collection<Object[]> data(){
89*b1cdbd2cSJim Jagielski     	Object[][] params = new Object[][]{
90*b1cdbd2cSJim Jagielski     			{"FooterIsOn", "FooterLeftMargin", "FooterRightMargin", "FooterBodyDistance","FooterHeight", 1000, 2000, 500,500},
91*b1cdbd2cSJim Jagielski     			{"FooterIsOn", "FooterLeftMargin", "FooterRightMargin", "FooterBodyDistance","FooterHeight", 3000, 1500, 300,400},
92*b1cdbd2cSJim Jagielski     			{"FooterIsOn", "FooterLeftMargin", "FooterRightMargin", "FooterBodyDistance","FooterHeight", 0, 0, 500,500},
93*b1cdbd2cSJim Jagielski     			{"FooterIsOn", "FooterLeftMargin", "FooterRightMargin", "FooterBodyDistance","FooterHeight", 600, 2000, 0,300},
94*b1cdbd2cSJim Jagielski     			{"HeaderIsOn", "HeaderLeftMargin", "HeaderRightMargin", "HeaderBodyDistance","HeaderHeight", 1000, 2000, 500,500},
95*b1cdbd2cSJim Jagielski     			{"HeaderIsOn", "HeaderLeftMargin", "HeaderRightMargin", "HeaderBodyDistance","HeaderHeight", 3000, 1500, 300,400},
96*b1cdbd2cSJim Jagielski     			{"HeaderIsOn", "HeaderLeftMargin", "HeaderRightMargin", "HeaderBodyDistance","HeaderHeight", 0, 0, 500,500},
97*b1cdbd2cSJim Jagielski     			{"HeaderIsOn", "HeaderLeftMargin", "HeaderRightMargin", "HeaderBodyDistance","HeaderHeight", 600, 2000, 0,300}
98*b1cdbd2cSJim Jagielski     			};
99*b1cdbd2cSJim Jagielski     	return Arrays.asList(params);
100*b1cdbd2cSJim Jagielski     }
101*b1cdbd2cSJim Jagielski 
102*b1cdbd2cSJim Jagielski     /**
103*b1cdbd2cSJim Jagielski      * test header/footer's left margin, right margin, spacing and height.
104*b1cdbd2cSJim Jagielski      * @throws Exception
105*b1cdbd2cSJim Jagielski      */
106*b1cdbd2cSJim Jagielski     //@Ignore("#120796 - header/footer's margins are all set to 0 when export to DOC format")
107*b1cdbd2cSJim Jagielski     @Ignore("#120798 - header/footer's spacing is increased when export to DOC file")
108*b1cdbd2cSJim Jagielski 	@Test
testFooterHeader()109*b1cdbd2cSJim Jagielski 	public void testFooterHeader() throws Exception
110*b1cdbd2cSJim Jagielski 	{
111*b1cdbd2cSJim Jagielski 		XComponent xComponent = unoApp.newDocument("swriter");
112*b1cdbd2cSJim Jagielski 		//turn on header/footer
113*b1cdbd2cSJim Jagielski 		SWUtil.setDefaultPageStyleProperty(xComponent, m_onProperty, new Boolean(true));
114*b1cdbd2cSJim Jagielski 		SWUtil.setDefaultPageStyleProperty(xComponent, m_LeftMarginProperty, Integer.valueOf(m_LeftMargin));
115*b1cdbd2cSJim Jagielski 		SWUtil.setDefaultPageStyleProperty(xComponent, m_RightMarginProperty, Integer.valueOf(m_RightMargin));
116*b1cdbd2cSJim Jagielski 		SWUtil.setDefaultPageStyleProperty(xComponent, m_BodyDistanceProperty, Integer.valueOf(m_BodyDistance));
117*b1cdbd2cSJim Jagielski 		SWUtil.setDefaultPageStyleProperty(xComponent, m_HeightProperty, Integer.valueOf(m_Height));
118*b1cdbd2cSJim Jagielski 
119*b1cdbd2cSJim Jagielski 		//save as ODT and reopen, get border
120*b1cdbd2cSJim Jagielski 		unoApp.saveDocument(xComponent, tempFilePathODT);
121*b1cdbd2cSJim Jagielski         unoApp.closeDocument(xComponent);
122*b1cdbd2cSJim Jagielski         xComponent = unoApp.loadDocument(tempFilePathODT);
123*b1cdbd2cSJim Jagielski 
124*b1cdbd2cSJim Jagielski 		int leftMargin = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_LeftMarginProperty)).intValue();
125*b1cdbd2cSJim Jagielski 		int rightMargin = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_RightMarginProperty)).intValue();
126*b1cdbd2cSJim Jagielski 		int bodyDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_BodyDistanceProperty)).intValue();
127*b1cdbd2cSJim Jagielski 		int height = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_HeightProperty)).intValue();
128*b1cdbd2cSJim Jagielski 
129*b1cdbd2cSJim Jagielski 		this.compare("ODT", leftMargin, rightMargin, bodyDistance, height);
130*b1cdbd2cSJim Jagielski 
131*b1cdbd2cSJim Jagielski 		//save as DOC and reopen, get properties
132*b1cdbd2cSJim Jagielski 	    SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC));
133*b1cdbd2cSJim Jagielski 	    unoApp.closeDocument(xComponent);
134*b1cdbd2cSJim Jagielski 	    xComponent = unoApp.loadDocument(tempFilePathDOC);
135*b1cdbd2cSJim Jagielski 	    leftMargin = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_LeftMarginProperty)).intValue();
136*b1cdbd2cSJim Jagielski 		rightMargin = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_RightMarginProperty)).intValue();
137*b1cdbd2cSJim Jagielski 		bodyDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_BodyDistanceProperty)).intValue();
138*b1cdbd2cSJim Jagielski 		height = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_HeightProperty)).intValue();
139*b1cdbd2cSJim Jagielski 
140*b1cdbd2cSJim Jagielski 		this.compare("DOC", leftMargin, rightMargin, bodyDistance, height);
141*b1cdbd2cSJim Jagielski 
142*b1cdbd2cSJim Jagielski 		unoApp.closeDocument(xComponent);
143*b1cdbd2cSJim Jagielski 
144*b1cdbd2cSJim Jagielski 	}
145*b1cdbd2cSJim Jagielski 
compare(String preDescription, int leftMargin, int rightMargin, int bodyDistance, int height)146*b1cdbd2cSJim Jagielski 	private void compare(String preDescription, int leftMargin, int rightMargin, int bodyDistance, int height){
147*b1cdbd2cSJim Jagielski 		Assert.assertEquals(preDescription + ":" + m_LeftMarginProperty,(double)m_LeftMargin, (double)leftMargin, 2);
148*b1cdbd2cSJim Jagielski 		Assert.assertEquals(preDescription + ":" + m_RightMarginProperty,(double)m_RightMargin, (double)rightMargin, 2);
149*b1cdbd2cSJim Jagielski 		Assert.assertEquals(preDescription + ":" + m_BodyDistanceProperty,(double)m_BodyDistance, (double)bodyDistance, 2);
150*b1cdbd2cSJim Jagielski 		Assert.assertEquals(preDescription + ":" + m_HeightProperty,(double)m_Height, (double)height, 2);
151*b1cdbd2cSJim Jagielski 	}
152*b1cdbd2cSJim Jagielski 
153*b1cdbd2cSJim Jagielski 	/**
154*b1cdbd2cSJim Jagielski 	 * @throws java.lang.Exception
155*b1cdbd2cSJim Jagielski 	 */
156*b1cdbd2cSJim Jagielski 	@Before
setUp()157*b1cdbd2cSJim Jagielski 	public void setUp() throws Exception {
158*b1cdbd2cSJim Jagielski 		unoApp.start();
159*b1cdbd2cSJim Jagielski 
160*b1cdbd2cSJim Jagielski 		FileUtil.deleteFile(getPath("temp"));
161*b1cdbd2cSJim Jagielski 		temp = new File(getPath("temp"));
162*b1cdbd2cSJim Jagielski 		temp.mkdirs();
163*b1cdbd2cSJim Jagielski 
164*b1cdbd2cSJim Jagielski 		tempFilePathODT = temp + "/tempFilePathODT.odt";
165*b1cdbd2cSJim Jagielski 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
166*b1cdbd2cSJim Jagielski 	}
167*b1cdbd2cSJim Jagielski 
168*b1cdbd2cSJim Jagielski 	@After
tearDown()169*b1cdbd2cSJim Jagielski 	public void tearDown() throws Exception {
170*b1cdbd2cSJim Jagielski 		unoApp.close();
171*b1cdbd2cSJim Jagielski 	}
172*b1cdbd2cSJim Jagielski 
173*b1cdbd2cSJim Jagielski 
174*b1cdbd2cSJim Jagielski }
175