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 import com.sun.star.table.ShadowFormat; 47deb45f49SLiu Zhe import com.sun.star.table.ShadowLocation; 48deb45f49SLiu Zhe 49deb45f49SLiu Zhe /** 50deb45f49SLiu Zhe * test footer/header's border's shadow format. 51deb45f49SLiu Zhe * test page border's shadow format 52deb45f49SLiu Zhe * 53deb45f49SLiu Zhe */ 54deb45f49SLiu Zhe @RunWith(Parameterized.class) 55deb45f49SLiu Zhe public class CheckShadowFormat { 56deb45f49SLiu Zhe UnoApp unoApp = new UnoApp(); 57deb45f49SLiu Zhe XTextDocument textDocument = null; 58deb45f49SLiu Zhe File temp = null; 59deb45f49SLiu Zhe String tempFilePathODT = ""; 60deb45f49SLiu Zhe String tempFilePathDOC = ""; 61deb45f49SLiu Zhe 62deb45f49SLiu Zhe private String onProperty = ""; 63deb45f49SLiu Zhe private String shadowFormatProperty = ""; 64deb45f49SLiu Zhe 65deb45f49SLiu Zhe private ShadowFormat shadowFormat = null; 66deb45f49SLiu Zhe CheckShadowFormat(String onProperty, String shadowFormatProperty, int locationValue, int width, boolean isTransparent, int color)67deb45f49SLiu Zhe public CheckShadowFormat(String onProperty, String shadowFormatProperty, int locationValue, int width, 68deb45f49SLiu Zhe boolean isTransparent, int color){ 69deb45f49SLiu Zhe this.onProperty = onProperty; 70deb45f49SLiu Zhe this.shadowFormatProperty = shadowFormatProperty; 71deb45f49SLiu Zhe this.shadowFormat = new ShadowFormat(); 72deb45f49SLiu Zhe this.shadowFormat.Location = ShadowLocation.fromInt(locationValue); 73deb45f49SLiu Zhe this.shadowFormat.ShadowWidth = (short)width; 74deb45f49SLiu Zhe this.shadowFormat.IsTransparent = isTransparent; 75deb45f49SLiu Zhe this.shadowFormat.Color = color; 76deb45f49SLiu Zhe } 77deb45f49SLiu Zhe 78deb45f49SLiu Zhe /** 79deb45f49SLiu Zhe * ShadowLocation 80deb45f49SLiu Zhe * 0:NONE 81deb45f49SLiu Zhe * 1:TOP_LEFT 82deb45f49SLiu Zhe * 2:TOP_RIGHT 83deb45f49SLiu Zhe * 3:BOTTOM_LEFT 84deb45f49SLiu Zhe * 4:BOTTOM_RIGHT 85deb45f49SLiu Zhe * @return 86deb45f49SLiu Zhe */ 87deb45f49SLiu Zhe @Parameters data()88deb45f49SLiu Zhe public static Collection<Object[]> data(){ 89deb45f49SLiu Zhe Object[][] params = new Object[][]{ 90deb45f49SLiu Zhe {"FooterIsOn", "ShadowFormat", 0, 200, false,255}, 91deb45f49SLiu Zhe {"FooterIsOn", "ShadowFormat", 1, 500, false,256}, 92deb45f49SLiu Zhe {"FooterIsOn", "ShadowFormat", 2, 50, false,65535}, 93deb45f49SLiu Zhe {"FooterIsOn", "ShadowFormat", 3, 30, false,65536}, 94deb45f49SLiu Zhe {"FooterIsOn", "ShadowFormat", 4, 1000, false,255}, 95deb45f49SLiu Zhe {"FooterIsOn", "FooterShadowFormat", 0, 200, false,256}, 96deb45f49SLiu Zhe {"FooterIsOn", "FooterShadowFormat", 1, 500, false,65535}, 97deb45f49SLiu Zhe {"FooterIsOn", "FooterShadowFormat", 2, 50, false,65536}, 98deb45f49SLiu Zhe {"FooterIsOn", "FooterShadowFormat", 3, 30, false,255}, 99deb45f49SLiu Zhe {"FooterIsOn", "FooterShadowFormat", 4, 1000, false,256}, 100deb45f49SLiu Zhe {"HeaderIsOn", "HeaderShadowFormat", 0, 200, false,65535}, 101deb45f49SLiu Zhe {"HeaderIsOn", "HeaderShadowFormat", 1, 500, false,65536}, 102deb45f49SLiu Zhe {"HeaderIsOn", "HeaderShadowFormat", 2, 50, false,255}, 103deb45f49SLiu Zhe {"HeaderIsOn", "HeaderShadowFormat", 3, 30, false,256}, 104deb45f49SLiu Zhe {"HeaderIsOn", "HeaderShadowFormat", 4, 1000, false,65536} 105deb45f49SLiu Zhe }; 106deb45f49SLiu Zhe return Arrays.asList(params); 107deb45f49SLiu Zhe } 108deb45f49SLiu Zhe 109deb45f49SLiu Zhe /** 110deb45f49SLiu Zhe * test footer/header's border's shadow format. 111deb45f49SLiu Zhe * test page border's shadow format 112deb45f49SLiu Zhe * @throws Exception 113deb45f49SLiu Zhe */ 114deb45f49SLiu Zhe @Ignore("#120969 - page and page's footer/header's shadow style lost after export to doc format in AOO") 115deb45f49SLiu Zhe @Test testFooterHeader()116deb45f49SLiu Zhe public void testFooterHeader() throws Exception 117deb45f49SLiu Zhe { 118deb45f49SLiu Zhe XComponent xComponent = unoApp.newDocument("swriter"); 119deb45f49SLiu Zhe //turn on header/footer 120deb45f49SLiu Zhe SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true)); 121deb45f49SLiu Zhe SWUtil.setDefaultPageStyleProperty(xComponent, shadowFormatProperty, this.shadowFormat); 122deb45f49SLiu Zhe 123deb45f49SLiu Zhe //save as ODT and reopen, get border 124deb45f49SLiu Zhe unoApp.saveDocument(xComponent, tempFilePathODT); 125deb45f49SLiu Zhe unoApp.closeDocument(xComponent); 126deb45f49SLiu Zhe xComponent = unoApp.loadDocument(tempFilePathODT); 127deb45f49SLiu Zhe 128deb45f49SLiu Zhe ShadowFormat actualShadowFormat = (ShadowFormat)SWUtil.getDefaultPageStyleProperty(xComponent, shadowFormatProperty); 129deb45f49SLiu Zhe 130deb45f49SLiu Zhe this.compare("ODT", actualShadowFormat); 131deb45f49SLiu Zhe 132deb45f49SLiu Zhe //save as DOC and reopen, get properties 133deb45f49SLiu Zhe SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC)); 134deb45f49SLiu Zhe unoApp.closeDocument(xComponent); 135deb45f49SLiu Zhe xComponent = unoApp.loadDocument(tempFilePathDOC); 136deb45f49SLiu Zhe actualShadowFormat = (ShadowFormat)SWUtil.getDefaultPageStyleProperty(xComponent, shadowFormatProperty); 137deb45f49SLiu Zhe 138deb45f49SLiu Zhe this.compare("DOC", actualShadowFormat); 139deb45f49SLiu Zhe 140deb45f49SLiu Zhe unoApp.closeDocument(xComponent); 141deb45f49SLiu Zhe 142deb45f49SLiu Zhe } 143deb45f49SLiu Zhe compare(String preDescription, ShadowFormat actual)144deb45f49SLiu Zhe private void compare(String preDescription, ShadowFormat actual){ 145deb45f49SLiu Zhe Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Location",this.shadowFormat.Location.getValue(), actual.Location.getValue()); 146deb45f49SLiu Zhe //check shadow width, isTransparent, color if shadow location is not NONE 147deb45f49SLiu Zhe if(!this.shadowFormat.Location.equals(ShadowLocation.NONE)){ 148deb45f49SLiu Zhe Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Width",(double)this.shadowFormat.ShadowWidth, (double)actual.ShadowWidth, 2); 149deb45f49SLiu Zhe Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->IsTransparent",this.shadowFormat.IsTransparent, actual.IsTransparent); 150deb45f49SLiu Zhe Assert.assertEquals(preDescription + ":" + shadowFormatProperty + "-->Color",this.shadowFormat.Color, actual.Color); 151deb45f49SLiu Zhe } 152deb45f49SLiu Zhe } 153deb45f49SLiu Zhe 154deb45f49SLiu Zhe 155deb45f49SLiu Zhe /** 156deb45f49SLiu Zhe * @throws java.lang.Exception 157deb45f49SLiu Zhe */ 158deb45f49SLiu Zhe @Before setUp()159deb45f49SLiu Zhe public void setUp() throws Exception { 160deb45f49SLiu Zhe unoApp.start(); 161deb45f49SLiu Zhe 162deb45f49SLiu Zhe FileUtil.deleteFile(getPath("temp")); 163deb45f49SLiu Zhe temp = new File(getPath("temp")); 164deb45f49SLiu Zhe temp.mkdirs(); 165deb45f49SLiu Zhe 166deb45f49SLiu Zhe tempFilePathODT = temp + "/tempFilePathODT.odt"; 167deb45f49SLiu Zhe tempFilePathDOC = temp + "/tempFilePathDOC.doc"; 168deb45f49SLiu Zhe } 169deb45f49SLiu Zhe 170deb45f49SLiu Zhe @After tearDown()171deb45f49SLiu Zhe public void tearDown() throws Exception { 172deb45f49SLiu Zhe unoApp.close(); 173deb45f49SLiu Zhe } 174deb45f49SLiu Zhe 175deb45f49SLiu Zhe 176deb45f49SLiu Zhe } 177