xref: /AOO41X/test/testuno/source/fvt/uno/sw/page/CheckPage.java (revision 121b6c7516a7e331c5197b28db00725e40a2c367)
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 page's orientation, width, height, margins
49  *
50  */
51 @RunWith(Parameterized.class)
52 public class CheckPage {
53 	UnoApp unoApp = new UnoApp();
54 	XTextDocument textDocument = null;
55 	File temp = null;
56 	String tempFilePathODT = "";
57 	String tempFilePathDOC = "";
58 
59 	private String isLandscapeProperty = "IsLandscape";
60 	private String widthProperty = "Width";
61 	private String heightProperty = "Height";
62 	private String topMarginProperty = "TopMargin";
63 	private String bottomMarginProperty = "BottomMargin";
64 	private String leftMarginProperty = "LeftMargin";
65 	private String rightMarginProperty = "RightMargin";
66 
67 	private boolean isLandscape = false;
68 	private int width = 0;
69 	private int height = 0;
70 	private int topMargin = 0;
71 	private int bottomMargin = 0;
72 	private int leftMargin = 0;
73 	private int rightMargin = 0;
74 
75 
76 	public CheckPage(boolean isLandscape, int width, int height, int topMargin, int bottomMargin, int leftMargin, int rightMargin){
77 		this.isLandscape = isLandscape;
78 		this.width = width;
79 		this.height = height;
80 		this.topMargin = topMargin;
81 		this.bottomMargin = bottomMargin;
82 		this.leftMargin = leftMargin;
83 		this.rightMargin = rightMargin;
84 	}
85 
86 	@Parameters
87     public static Collection<Object[]> data(){
88     	Object[][] params = new Object[][]{
89     			{false,10000, 20000, 1000,2000, 0, 0},
90     			{false, 30000,40000, 0, 0, 100, 200},
91     			{true, 900, 10000, 0,0,0,0},
92     			{true, 20000, 30000, 300, 300, 300, 300}
93     			};
94     	return Arrays.asList(params);
95     }
96 
97     /**
98      * test page's orientation, width, height, margins
99      * @throws Exception
100      */
101 	@Test
102 	public void testPage() throws Exception
103 	{
104 		XComponent xComponent = unoApp.newDocument("swriter");
105 
106 		SWUtil.setDefaultPageStyleProperty(xComponent, isLandscapeProperty, new Boolean(this.isLandscape));
107 		SWUtil.setDefaultPageStyleProperty(xComponent, widthProperty, Integer.valueOf(this.width));
108 		SWUtil.setDefaultPageStyleProperty(xComponent, heightProperty, Integer.valueOf(this.height));
109 		SWUtil.setDefaultPageStyleProperty(xComponent, topMarginProperty, Integer.valueOf(this.topMargin));
110 		SWUtil.setDefaultPageStyleProperty(xComponent, bottomMarginProperty, Integer.valueOf(this.bottomMargin));
111 		SWUtil.setDefaultPageStyleProperty(xComponent, leftMarginProperty, Integer.valueOf(this.leftMargin));
112 		SWUtil.setDefaultPageStyleProperty(xComponent, rightMarginProperty, Integer.valueOf(this.rightMargin));
113 
114 		//save as ODT and reopen, get border
115 		unoApp.saveDocument(xComponent, tempFilePathODT);
116         unoApp.closeDocument(xComponent);
117         xComponent = unoApp.loadDocument(tempFilePathODT);
118 
119         boolean actualIsLandScape = ((Boolean)SWUtil.getDefaultPageStyleProperty(xComponent, isLandscapeProperty)).booleanValue();
120 		int actualWidth = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, widthProperty)).intValue();
121 		int actualHeight = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, heightProperty)).intValue();
122 		int actualTop = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, topMarginProperty)).intValue();
123 		int actualBottom = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, bottomMarginProperty)).intValue();
124 		int actualLeft = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, leftMarginProperty)).intValue();
125 		int actualRight = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, rightMarginProperty)).intValue();
126 
127 
128 
129 		this.compare("ODT", actualIsLandScape,actualWidth,actualHeight,actualTop,actualBottom, actualLeft,actualRight);
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 
136 	    actualIsLandScape = ((Boolean)SWUtil.getDefaultPageStyleProperty(xComponent, isLandscapeProperty)).booleanValue();
137 	    actualWidth = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, widthProperty)).intValue();
138 		actualHeight = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, heightProperty)).intValue();
139 		actualTop = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, topMarginProperty)).intValue();
140 		actualBottom = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, bottomMarginProperty)).intValue();
141 		actualLeft = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, leftMarginProperty)).intValue();
142 		actualRight = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, rightMarginProperty)).intValue();
143 
144 		this.compare("DOC", actualIsLandScape,actualWidth,actualHeight,actualTop,actualBottom, actualLeft,actualRight);
145 
146 		unoApp.closeDocument(xComponent);
147 
148 	}
149 
150 	private void compare(String preDescription, boolean isLandScape, int width, int height, int top, int bottom, int left, int right){
151 		Assert.assertEquals(preDescription + ":" + this.isLandscapeProperty,this.isLandscape, isLandScape);
152 		Assert.assertEquals(preDescription + ":" + this.widthProperty,(double)this.width, (double)width, 2);
153 		Assert.assertEquals(preDescription + ":" + this.heightProperty,(double)this.height, (double)height, 2);
154 		Assert.assertEquals(preDescription + ":" + this.topMarginProperty,(double)this.topMargin, (double)top, 2);
155 		Assert.assertEquals(preDescription + ":" + this.bottomMarginProperty,(double)this.bottomMargin, (double)bottom, 2);
156 		Assert.assertEquals(preDescription + ":" + this.leftMarginProperty,(double)this.leftMargin, (double)left, 2);
157 		Assert.assertEquals(preDescription + ":" + this.rightMarginProperty,(double)this.rightMargin, (double)right, 2);
158 	}
159 
160 	/**
161 	 * @throws java.lang.Exception
162 	 */
163 	@Before
164 	public void setUp() throws Exception {
165 		unoApp.start();
166 
167 		FileUtil.deleteFile(getPath("temp"));
168 		temp = new File(getPath("temp"));
169 		temp.mkdirs();
170 
171 		tempFilePathODT = temp + "/tempFilePathODT.odt";
172 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
173 	}
174 
175 	@After
176 	public void tearDown() throws Exception {
177 		unoApp.close();
178 	}
179 
180 
181 }
182