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