xref: /trunk/test/testuno/source/fvt/uno/sw/page/CheckPageLayout.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 import java.lang.Enum;
29*eba4d44aSLiu Zhe 
30*eba4d44aSLiu Zhe import org.junit.After;
31*eba4d44aSLiu Zhe import org.junit.Before;
32*eba4d44aSLiu Zhe import org.junit.Test;
33*eba4d44aSLiu Zhe import org.junit.Ignore;
34*eba4d44aSLiu Zhe import org.junit.Assert;
35*eba4d44aSLiu Zhe import org.junit.runner.RunWith;
36*eba4d44aSLiu Zhe import org.junit.runners.Parameterized;
37*eba4d44aSLiu Zhe import org.junit.runners.Parameterized.Parameters;
38*eba4d44aSLiu Zhe 
39*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil;
40*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
41*eba4d44aSLiu Zhe 
42*eba4d44aSLiu Zhe import testlib.uno.SWUtil;
43*eba4d44aSLiu Zhe import com.sun.star.text.XTextDocument;
44*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
45*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
46*eba4d44aSLiu Zhe import com.sun.star.table.BorderLine;
47*eba4d44aSLiu Zhe import com.sun.star.style.PageStyleLayout;
48*eba4d44aSLiu Zhe 
49*eba4d44aSLiu Zhe /**
50*eba4d44aSLiu Zhe  * test page's layout settings
51*eba4d44aSLiu Zhe  *
52*eba4d44aSLiu Zhe  */
53*eba4d44aSLiu Zhe @RunWith(Parameterized.class)
54*eba4d44aSLiu Zhe public class CheckPageLayout {
55*eba4d44aSLiu Zhe     UnoApp unoApp = new UnoApp();
56*eba4d44aSLiu Zhe     XTextDocument textDocument = null;
57*eba4d44aSLiu Zhe     File temp = null;
58*eba4d44aSLiu Zhe     String tempFilePathODT = "";
59*eba4d44aSLiu Zhe     String tempFilePathDOC = "";
60*eba4d44aSLiu Zhe 
61*eba4d44aSLiu Zhe     private String pageStyleLayoutProperty = "PageStyleLayout";
62*eba4d44aSLiu Zhe 
63*eba4d44aSLiu Zhe     private PageStyleLayout pageStyleLayout = PageStyleLayout.getDefault();
64*eba4d44aSLiu Zhe 
65*eba4d44aSLiu Zhe 
CheckPageLayout(int styleValue)66*eba4d44aSLiu Zhe     public CheckPageLayout(int styleValue){
67*eba4d44aSLiu Zhe         this.pageStyleLayout = PageStyleLayout.fromInt(styleValue);
68*eba4d44aSLiu Zhe     }
69*eba4d44aSLiu Zhe     /**
70*eba4d44aSLiu Zhe      * 0:ALL
71*eba4d44aSLiu Zhe      * 1:LEFT
72*eba4d44aSLiu Zhe      * 2:RIGHT
73*eba4d44aSLiu Zhe      * 3:MIRRORED
74*eba4d44aSLiu Zhe      * @return
75*eba4d44aSLiu Zhe      */
76*eba4d44aSLiu Zhe     @Parameters
data()77*eba4d44aSLiu Zhe     public static Collection<Object[]> data(){
78*eba4d44aSLiu Zhe         Object[][] params = new Object[][]{
79*eba4d44aSLiu Zhe                 {0},
80*eba4d44aSLiu Zhe                 {1},
81*eba4d44aSLiu Zhe                 {2},
82*eba4d44aSLiu Zhe                 {3}
83*eba4d44aSLiu Zhe                 };
84*eba4d44aSLiu Zhe         return Arrays.asList(params);
85*eba4d44aSLiu Zhe     }
86*eba4d44aSLiu Zhe 
87*eba4d44aSLiu Zhe     /**
88*eba4d44aSLiu Zhe      * test page's layout settings
89*eba4d44aSLiu Zhe      * @throws Exception
90*eba4d44aSLiu Zhe      */
91*eba4d44aSLiu Zhe     @Ignore("#120964 - page layout 'only left' and 'only right' all changed to default value 'right and left' after export to doc format in AOO")
92*eba4d44aSLiu Zhe     @Test
testPageStyleLayout()93*eba4d44aSLiu Zhe     public void testPageStyleLayout() throws Exception
94*eba4d44aSLiu Zhe     {
95*eba4d44aSLiu Zhe         XComponent xComponent = unoApp.newDocument("swriter");
96*eba4d44aSLiu Zhe         SWUtil.setDefaultPageStyleProperty(xComponent, this.pageStyleLayoutProperty, this.pageStyleLayout);
97*eba4d44aSLiu Zhe 
98*eba4d44aSLiu Zhe         //save as ODT and reopen, get border
99*eba4d44aSLiu Zhe         unoApp.saveDocument(xComponent, tempFilePathODT);
100*eba4d44aSLiu Zhe         unoApp.closeDocument(xComponent);
101*eba4d44aSLiu Zhe         xComponent = unoApp.loadDocument(tempFilePathODT);
102*eba4d44aSLiu Zhe 
103*eba4d44aSLiu Zhe         PageStyleLayout actualPageStyleLayout = (PageStyleLayout)SWUtil.getDefaultPageStyleProperty(xComponent, this.pageStyleLayoutProperty);
104*eba4d44aSLiu Zhe 
105*eba4d44aSLiu Zhe         this.compare("ODT", actualPageStyleLayout);
106*eba4d44aSLiu Zhe 
107*eba4d44aSLiu Zhe         //save as DOC and reopen, get properties
108*eba4d44aSLiu Zhe         SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC));
109*eba4d44aSLiu Zhe         unoApp.closeDocument(xComponent);
110*eba4d44aSLiu Zhe         xComponent = unoApp.loadDocument(tempFilePathDOC);
111*eba4d44aSLiu Zhe 
112*eba4d44aSLiu Zhe         actualPageStyleLayout = (PageStyleLayout)SWUtil.getDefaultPageStyleProperty(xComponent, this.pageStyleLayoutProperty);
113*eba4d44aSLiu Zhe 
114*eba4d44aSLiu Zhe         this.compare("DOC", actualPageStyleLayout);
115*eba4d44aSLiu Zhe 
116*eba4d44aSLiu Zhe         unoApp.closeDocument(xComponent);
117*eba4d44aSLiu Zhe 
118*eba4d44aSLiu Zhe     }
119*eba4d44aSLiu Zhe 
compare(String preDescription, PageStyleLayout actual)120*eba4d44aSLiu Zhe     private void compare(String preDescription, PageStyleLayout actual){
121*eba4d44aSLiu Zhe         Assert.assertEquals(preDescription + ":" + this.pageStyleLayoutProperty,this.pageStyleLayout.getValue(), actual.getValue());
122*eba4d44aSLiu Zhe     }
123*eba4d44aSLiu Zhe 
124*eba4d44aSLiu Zhe     /**
125*eba4d44aSLiu Zhe      * @throws java.lang.Exception
126*eba4d44aSLiu Zhe      */
127*eba4d44aSLiu Zhe     @Before
setUp()128*eba4d44aSLiu Zhe     public void setUp() throws Exception {
129*eba4d44aSLiu Zhe         unoApp.start();
130*eba4d44aSLiu Zhe 
131*eba4d44aSLiu Zhe         FileUtil.deleteFile(getPath("temp"));
132*eba4d44aSLiu Zhe         temp = new File(getPath("temp"));
133*eba4d44aSLiu Zhe         temp.mkdirs();
134*eba4d44aSLiu Zhe 
135*eba4d44aSLiu Zhe         tempFilePathODT = temp + "/tempFilePathODT.odt";
136*eba4d44aSLiu Zhe         tempFilePathDOC = temp + "/tempFilePathDOC.doc";
137*eba4d44aSLiu Zhe     }
138*eba4d44aSLiu Zhe 
139*eba4d44aSLiu Zhe     @After
tearDown()140*eba4d44aSLiu Zhe     public void tearDown() throws Exception {
141*eba4d44aSLiu Zhe         unoApp.close();
142*eba4d44aSLiu Zhe     }
143*eba4d44aSLiu Zhe 
144*eba4d44aSLiu Zhe 
145*eba4d44aSLiu Zhe }
146