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