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