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