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 footer/header's margins, spacing and height.
49deb45f49SLiu Zhe  *
50deb45f49SLiu Zhe  */
51deb45f49SLiu Zhe @RunWith(Parameterized.class)
52deb45f49SLiu Zhe public class CheckFooterHeader {
53deb45f49SLiu Zhe 	UnoApp unoApp = new UnoApp();
54deb45f49SLiu Zhe 	XTextDocument textDocument = null;
55deb45f49SLiu Zhe 	File temp = null;
56deb45f49SLiu Zhe 	String tempFilePathODT = "";
57deb45f49SLiu Zhe 	String tempFilePathDOC = "";
58deb45f49SLiu Zhe 
59deb45f49SLiu Zhe 	private String m_onProperty = "";
60deb45f49SLiu Zhe 
61deb45f49SLiu Zhe 	private String m_LeftMarginProperty = "";
62deb45f49SLiu Zhe 	private String m_RightMarginProperty = "";
63deb45f49SLiu Zhe 	private String m_BodyDistanceProperty = "";
64deb45f49SLiu Zhe 	private String m_HeightProperty = "";
65deb45f49SLiu Zhe 
66deb45f49SLiu Zhe 	private int m_LeftMargin = 0;
67deb45f49SLiu Zhe 	private int m_RightMargin = 0;
68deb45f49SLiu Zhe 	private int m_BodyDistance = 0;
69deb45f49SLiu Zhe 	private int m_Height = 0;
70deb45f49SLiu Zhe 
71deb45f49SLiu Zhe 
CheckFooterHeader(String onProperty, String leftMarginProperty, String rightMarginProperty, String bodyDistanceProperty, String heightProperty, int leftMargin, int rightMargin, int bodyDistance, int height)72deb45f49SLiu Zhe 	public CheckFooterHeader(String onProperty, String leftMarginProperty, String rightMarginProperty, String bodyDistanceProperty, String heightProperty,
73deb45f49SLiu Zhe 			int leftMargin, int rightMargin, int bodyDistance, int height){
74deb45f49SLiu Zhe 		m_onProperty = onProperty;
75deb45f49SLiu Zhe 		m_LeftMarginProperty = leftMarginProperty;
76deb45f49SLiu Zhe 		m_RightMarginProperty = rightMarginProperty;
77deb45f49SLiu Zhe 		m_BodyDistanceProperty = bodyDistanceProperty;
78deb45f49SLiu Zhe 		m_HeightProperty = heightProperty;
79deb45f49SLiu Zhe 
80deb45f49SLiu Zhe 		m_LeftMargin = leftMargin;
81deb45f49SLiu Zhe 		m_RightMargin = rightMargin;
82deb45f49SLiu Zhe 		m_BodyDistance = bodyDistance;
83deb45f49SLiu Zhe 		m_BodyDistance = bodyDistance;
84deb45f49SLiu Zhe 		m_Height = height;
85deb45f49SLiu Zhe 	}
86deb45f49SLiu Zhe 
87deb45f49SLiu Zhe 	@Parameters
data()88deb45f49SLiu Zhe     public static Collection<Object[]> data(){
89deb45f49SLiu Zhe     	Object[][] params = new Object[][]{
90deb45f49SLiu Zhe     			{"FooterIsOn", "FooterLeftMargin", "FooterRightMargin", "FooterBodyDistance","FooterHeight", 1000, 2000, 500,500},
91deb45f49SLiu Zhe     			{"FooterIsOn", "FooterLeftMargin", "FooterRightMargin", "FooterBodyDistance","FooterHeight", 3000, 1500, 300,400},
92deb45f49SLiu Zhe     			{"FooterIsOn", "FooterLeftMargin", "FooterRightMargin", "FooterBodyDistance","FooterHeight", 0, 0, 500,500},
93deb45f49SLiu Zhe     			{"FooterIsOn", "FooterLeftMargin", "FooterRightMargin", "FooterBodyDistance","FooterHeight", 600, 2000, 0,300},
94deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderLeftMargin", "HeaderRightMargin", "HeaderBodyDistance","HeaderHeight", 1000, 2000, 500,500},
95deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderLeftMargin", "HeaderRightMargin", "HeaderBodyDistance","HeaderHeight", 3000, 1500, 300,400},
96deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderLeftMargin", "HeaderRightMargin", "HeaderBodyDistance","HeaderHeight", 0, 0, 500,500},
97deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderLeftMargin", "HeaderRightMargin", "HeaderBodyDistance","HeaderHeight", 600, 2000, 0,300}
98deb45f49SLiu Zhe     			};
99deb45f49SLiu Zhe     	return Arrays.asList(params);
100deb45f49SLiu Zhe     }
101deb45f49SLiu Zhe 
102deb45f49SLiu Zhe     /**
103deb45f49SLiu Zhe      * test header/footer's left margin, right margin, spacing and height.
104deb45f49SLiu Zhe      * @throws Exception
105deb45f49SLiu Zhe      */
106deb45f49SLiu Zhe     //@Ignore("#120796 - header/footer's margins are all set to 0 when export to DOC format")
107deb45f49SLiu Zhe     @Ignore("#120798 - header/footer's spacing is increased when export to DOC file")
108deb45f49SLiu Zhe 	@Test
testFooterHeader()109deb45f49SLiu Zhe 	public void testFooterHeader() throws Exception
110deb45f49SLiu Zhe 	{
111deb45f49SLiu Zhe 		XComponent xComponent = unoApp.newDocument("swriter");
112deb45f49SLiu Zhe 		//turn on header/footer
113deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, m_onProperty, new Boolean(true));
114deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, m_LeftMarginProperty, Integer.valueOf(m_LeftMargin));
115deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, m_RightMarginProperty, Integer.valueOf(m_RightMargin));
116deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, m_BodyDistanceProperty, Integer.valueOf(m_BodyDistance));
117deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, m_HeightProperty, Integer.valueOf(m_Height));
118deb45f49SLiu Zhe 
119deb45f49SLiu Zhe 		//save as ODT and reopen, get border
120deb45f49SLiu Zhe 		unoApp.saveDocument(xComponent, tempFilePathODT);
121deb45f49SLiu Zhe         unoApp.closeDocument(xComponent);
122deb45f49SLiu Zhe         xComponent = unoApp.loadDocument(tempFilePathODT);
123deb45f49SLiu Zhe 
124deb45f49SLiu Zhe 		int leftMargin = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_LeftMarginProperty)).intValue();
125deb45f49SLiu Zhe 		int rightMargin = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_RightMarginProperty)).intValue();
126deb45f49SLiu Zhe 		int bodyDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_BodyDistanceProperty)).intValue();
127deb45f49SLiu Zhe 		int height = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_HeightProperty)).intValue();
128deb45f49SLiu Zhe 
129deb45f49SLiu Zhe 		this.compare("ODT", leftMargin, rightMargin, bodyDistance, height);
130deb45f49SLiu Zhe 
131deb45f49SLiu Zhe 		//save as DOC and reopen, get properties
132deb45f49SLiu Zhe 	    SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC));
133deb45f49SLiu Zhe 	    unoApp.closeDocument(xComponent);
134deb45f49SLiu Zhe 	    xComponent = unoApp.loadDocument(tempFilePathDOC);
135deb45f49SLiu Zhe 	    leftMargin = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_LeftMarginProperty)).intValue();
136deb45f49SLiu Zhe 		rightMargin = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_RightMarginProperty)).intValue();
137deb45f49SLiu Zhe 		bodyDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_BodyDistanceProperty)).intValue();
138deb45f49SLiu Zhe 		height = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, m_HeightProperty)).intValue();
139deb45f49SLiu Zhe 
140deb45f49SLiu Zhe 		this.compare("DOC", leftMargin, rightMargin, bodyDistance, height);
141deb45f49SLiu Zhe 
142deb45f49SLiu Zhe 		unoApp.closeDocument(xComponent);
143deb45f49SLiu Zhe 
144deb45f49SLiu Zhe 	}
145deb45f49SLiu Zhe 
compare(String preDescription, int leftMargin, int rightMargin, int bodyDistance, int height)146deb45f49SLiu Zhe 	private void compare(String preDescription, int leftMargin, int rightMargin, int bodyDistance, int height){
147deb45f49SLiu Zhe 		Assert.assertEquals(preDescription + ":" + m_LeftMarginProperty,(double)m_LeftMargin, (double)leftMargin, 2);
148deb45f49SLiu Zhe 		Assert.assertEquals(preDescription + ":" + m_RightMarginProperty,(double)m_RightMargin, (double)rightMargin, 2);
149deb45f49SLiu Zhe 		Assert.assertEquals(preDescription + ":" + m_BodyDistanceProperty,(double)m_BodyDistance, (double)bodyDistance, 2);
150deb45f49SLiu Zhe 		Assert.assertEquals(preDescription + ":" + m_HeightProperty,(double)m_Height, (double)height, 2);
151deb45f49SLiu Zhe 	}
152deb45f49SLiu Zhe 
153deb45f49SLiu Zhe 	/**
154deb45f49SLiu Zhe 	 * @throws java.lang.Exception
155deb45f49SLiu Zhe 	 */
156deb45f49SLiu Zhe 	@Before
setUp()157deb45f49SLiu Zhe 	public void setUp() throws Exception {
158deb45f49SLiu Zhe 		unoApp.start();
159deb45f49SLiu Zhe 
160deb45f49SLiu Zhe 		FileUtil.deleteFile(getPath("temp"));
161deb45f49SLiu Zhe 		temp = new File(getPath("temp"));
162deb45f49SLiu Zhe 		temp.mkdirs();
163deb45f49SLiu Zhe 
164deb45f49SLiu Zhe 		tempFilePathODT = temp + "/tempFilePathODT.odt";
165deb45f49SLiu Zhe 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
166deb45f49SLiu Zhe 	}
167deb45f49SLiu Zhe 
168deb45f49SLiu Zhe 	@After
tearDown()169deb45f49SLiu Zhe 	public void tearDown() throws Exception {
170deb45f49SLiu Zhe 		unoApp.close();
171deb45f49SLiu Zhe 	}
172deb45f49SLiu Zhe 
173deb45f49SLiu Zhe 
174deb45f49SLiu Zhe }
175