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 border 49*eba4d44aSLiu Zhe * test page's footer/header's border 50*eba4d44aSLiu Zhe * 51*eba4d44aSLiu Zhe */ 52*eba4d44aSLiu Zhe @RunWith(Parameterized.class) 53*eba4d44aSLiu Zhe public class CheckBorder { 54*eba4d44aSLiu Zhe UnoApp unoApp = new UnoApp(); 55*eba4d44aSLiu Zhe XTextDocument textDocument = null; 56*eba4d44aSLiu Zhe File temp = null; 57*eba4d44aSLiu Zhe String tempFilePathODT = ""; 58*eba4d44aSLiu Zhe String tempFilePathDOC = ""; 59*eba4d44aSLiu Zhe 60*eba4d44aSLiu Zhe private String onProperty = ""; 61*eba4d44aSLiu Zhe private String borderProperty = ""; 62*eba4d44aSLiu Zhe private String borderDistanceProperty = ""; 63*eba4d44aSLiu Zhe private BorderLine borderLine = null; 64*eba4d44aSLiu Zhe private int borderDistance = 0; 65*eba4d44aSLiu Zhe 66*eba4d44aSLiu Zhe CheckBorder(String onProperty, String borderProperty, String borderDistanceProperty, int color, int lineDistance, int innerLineWidth, int outerLineWidth, int borderDistance)67*eba4d44aSLiu Zhe public CheckBorder(String onProperty, String borderProperty, String borderDistanceProperty, 68*eba4d44aSLiu Zhe int color, int lineDistance, int innerLineWidth, int outerLineWidth, int borderDistance){ 69*eba4d44aSLiu Zhe this.borderLine = new BorderLine(); 70*eba4d44aSLiu Zhe this.borderLine.Color = color; 71*eba4d44aSLiu Zhe this.borderLine.LineDistance = (short)lineDistance; 72*eba4d44aSLiu Zhe this.borderLine.InnerLineWidth = (short)innerLineWidth; 73*eba4d44aSLiu Zhe this.borderLine.OuterLineWidth = (short)outerLineWidth; 74*eba4d44aSLiu Zhe 75*eba4d44aSLiu Zhe this.onProperty = onProperty; 76*eba4d44aSLiu Zhe this.borderProperty = borderProperty; 77*eba4d44aSLiu Zhe this.borderDistanceProperty = borderDistanceProperty; 78*eba4d44aSLiu Zhe 79*eba4d44aSLiu Zhe this.borderDistance = borderDistance; 80*eba4d44aSLiu Zhe } 81*eba4d44aSLiu Zhe 82*eba4d44aSLiu Zhe @Parameters data()83*eba4d44aSLiu Zhe public static Collection<Object[]> data(){ 84*eba4d44aSLiu Zhe Object[][] params = new Object[][]{ 85*eba4d44aSLiu Zhe /*{"FooterIsOn", "LeftBorder", "LeftBorderDistance", 255, 100, 50,70,199}, 86*eba4d44aSLiu Zhe {"FooterIsOn", "RightBorder", "RightBorderDistance", 256, 0, 0,0,20}, 87*eba4d44aSLiu Zhe {"FooterIsOn", "BottomBorder", "BottomBorderDistance", 65536, 15, 10,30,300}, 88*eba4d44aSLiu Zhe {"FooterIsOn", "TopBorder", "TopBorderDistance", 65535, 6, 100,200,400}, 89*eba4d44aSLiu Zhe {"FooterIsOn", "FooterLeftBorder", "FooterLeftBorderDistance", 255, 100, 50,70,199}, 90*eba4d44aSLiu Zhe {"FooterIsOn", "FooterRightBorder", "FooterRightBorderDistance", 256, 0, 0,0,20}, 91*eba4d44aSLiu Zhe {"FooterIsOn", "FooterBottomBorder", "FooterBottomBorderDistance", 65536, 15, 10,30,300}, 92*eba4d44aSLiu Zhe {"FooterIsOn", "FooterTopBorder", "FooterTopBorderDistance", 65535, 6, 100,200,400},*/ 93*eba4d44aSLiu Zhe {"HeaderIsOn", "HeaderLeftBorder", "HeaderLeftBorderDistance", 255, 100, 50,70,0}, 94*eba4d44aSLiu Zhe {"HeaderIsOn", "HeaderRightBorder", "HeaderRightBorderDistance", 256, 0, 0,0,100}, 95*eba4d44aSLiu Zhe {"HeaderIsOn", "HeaderBottomBorder", "HeaderBottomBorderDistance", 65536, 15, 10,30,900}, 96*eba4d44aSLiu Zhe {"HeaderIsOn", "HeaderTopBorder", "HeaderTopBorderDistance", 65535, 6, 100,200,50} 97*eba4d44aSLiu Zhe }; 98*eba4d44aSLiu Zhe return Arrays.asList(params); 99*eba4d44aSLiu Zhe } 100*eba4d44aSLiu Zhe 101*eba4d44aSLiu Zhe /** 102*eba4d44aSLiu Zhe * test page's border 103*eba4d44aSLiu Zhe * test page's footer/header's border 104*eba4d44aSLiu Zhe * @throws Exception 105*eba4d44aSLiu Zhe */ 106*eba4d44aSLiu Zhe @Ignore("#120822 - header/footer's border styles are lost when export to DOC format") 107*eba4d44aSLiu Zhe @Test testFooterHeaderBorder()108*eba4d44aSLiu Zhe public void testFooterHeaderBorder() throws Exception 109*eba4d44aSLiu Zhe { 110*eba4d44aSLiu Zhe XComponent xComponent = unoApp.newDocument("swriter"); 111*eba4d44aSLiu Zhe //turn on header/footer 112*eba4d44aSLiu Zhe SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true)); 113*eba4d44aSLiu Zhe SWUtil.setDefaultPageStyleProperty(xComponent, borderProperty, borderLine); 114*eba4d44aSLiu Zhe SWUtil.setDefaultPageStyleProperty(xComponent, borderDistanceProperty, Integer.valueOf(borderDistance)); 115*eba4d44aSLiu Zhe 116*eba4d44aSLiu Zhe //save as ODT and reopen, get border 117*eba4d44aSLiu Zhe unoApp.saveDocument(xComponent, tempFilePathODT); 118*eba4d44aSLiu Zhe unoApp.closeDocument(xComponent); 119*eba4d44aSLiu Zhe xComponent = unoApp.loadDocument(tempFilePathODT); 120*eba4d44aSLiu Zhe 121*eba4d44aSLiu Zhe BorderLine actualBorderLine = (BorderLine)SWUtil.getDefaultPageStyleProperty(xComponent, borderProperty); 122*eba4d44aSLiu Zhe int actualBorderDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, borderDistanceProperty)).intValue(); 123*eba4d44aSLiu Zhe 124*eba4d44aSLiu Zhe this.compareBorder("ODT:", borderLine, borderDistance); 125*eba4d44aSLiu Zhe 126*eba4d44aSLiu Zhe //save as DOC and reopen, get border 127*eba4d44aSLiu Zhe SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC)); 128*eba4d44aSLiu Zhe unoApp.closeDocument(xComponent); 129*eba4d44aSLiu Zhe xComponent = unoApp.loadDocument(tempFilePathDOC); 130*eba4d44aSLiu Zhe actualBorderLine = (BorderLine)SWUtil.getDefaultPageStyleProperty(xComponent, borderProperty); 131*eba4d44aSLiu Zhe actualBorderDistance = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, borderDistanceProperty)).intValue(); 132*eba4d44aSLiu Zhe 133*eba4d44aSLiu Zhe this.compareBorder("DOC:", actualBorderLine, actualBorderDistance); 134*eba4d44aSLiu Zhe 135*eba4d44aSLiu Zhe unoApp.closeDocument(xComponent); 136*eba4d44aSLiu Zhe 137*eba4d44aSLiu Zhe } 138*eba4d44aSLiu Zhe compareBorder(String preDes, BorderLine actualBorderLine, int actualBorderDistance)139*eba4d44aSLiu Zhe private void compareBorder(String preDes, BorderLine actualBorderLine, int actualBorderDistance){ 140*eba4d44aSLiu Zhe Assert.assertEquals(preDes + borderProperty + "-->color.",(double)borderLine.Color, (double)actualBorderLine.Color, 2); 141*eba4d44aSLiu Zhe Assert.assertEquals(preDes + borderProperty + "-->LineDistance.", (double)borderLine.LineDistance, (double)actualBorderLine.LineDistance, 2); 142*eba4d44aSLiu Zhe Assert.assertEquals(preDes + borderProperty + "-->InnerLineWidth.", (double)borderLine.InnerLineWidth, (double)actualBorderLine.InnerLineWidth, 2); 143*eba4d44aSLiu Zhe Assert.assertEquals(preDes + borderProperty + "-->OuterLineWidth.", (double)borderLine.OuterLineWidth, (double)actualBorderLine.OuterLineWidth, 2); 144*eba4d44aSLiu Zhe 145*eba4d44aSLiu Zhe Assert.assertEquals(preDes + "-->" + borderDistanceProperty, (double)borderLine.OuterLineWidth, (double)actualBorderLine.OuterLineWidth, 2); 146*eba4d44aSLiu Zhe } 147*eba4d44aSLiu Zhe 148*eba4d44aSLiu Zhe /** 149*eba4d44aSLiu Zhe * @throws java.lang.Exception 150*eba4d44aSLiu Zhe */ 151*eba4d44aSLiu Zhe @Before setUp()152*eba4d44aSLiu Zhe public void setUp() throws Exception { 153*eba4d44aSLiu Zhe unoApp.start(); 154*eba4d44aSLiu Zhe 155*eba4d44aSLiu Zhe FileUtil.deleteFile(getPath("temp")); 156*eba4d44aSLiu Zhe temp = new File(getPath("temp")); 157*eba4d44aSLiu Zhe temp.mkdirs(); 158*eba4d44aSLiu Zhe 159*eba4d44aSLiu Zhe tempFilePathODT = temp + "/tempFilePathODT.odt"; 160*eba4d44aSLiu Zhe tempFilePathDOC = temp + "/tempFilePathDOC.doc"; 161*eba4d44aSLiu Zhe } 162*eba4d44aSLiu Zhe 163*eba4d44aSLiu Zhe @After tearDown()164*eba4d44aSLiu Zhe public void tearDown() throws Exception { 165*eba4d44aSLiu Zhe unoApp.close(); 166*eba4d44aSLiu Zhe } 167*eba4d44aSLiu Zhe 168*eba4d44aSLiu Zhe 169*eba4d44aSLiu Zhe } 170