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