1*28725c19SLi Feng Wang /************************************************************** 2*28725c19SLi Feng Wang * 3*28725c19SLi Feng Wang * Licensed to the Apache Software Foundation (ASF) under one 4*28725c19SLi Feng Wang * or more contributor license agreements. See the NOTICE file 5*28725c19SLi Feng Wang * distributed with this work for additional information 6*28725c19SLi Feng Wang * regarding copyright ownership. The ASF licenses this file 7*28725c19SLi Feng Wang * to you under the Apache License, Version 2.0 (the 8*28725c19SLi Feng Wang * "License"); you may not use this file except in compliance 9*28725c19SLi Feng Wang * with the License. You may obtain a copy of the License at 10*28725c19SLi Feng Wang * 11*28725c19SLi Feng Wang * http://www.apache.org/licenses/LICENSE-2.0 12*28725c19SLi Feng Wang * 13*28725c19SLi Feng Wang * Unless required by applicable law or agreed to in writing, 14*28725c19SLi Feng Wang * software distributed under the License is distributed on an 15*28725c19SLi Feng Wang * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*28725c19SLi Feng Wang * KIND, either express or implied. See the License for the 17*28725c19SLi Feng Wang * specific language governing permissions and limitations 18*28725c19SLi Feng Wang * under the License. 19*28725c19SLi Feng Wang * 20*28725c19SLi Feng Wang *************************************************************/ 21*28725c19SLi Feng Wang /** 22*28725c19SLi Feng Wang * 23*28725c19SLi Feng Wang */ 24*28725c19SLi Feng Wang package fvt.uno.sd.bullet; 25*28725c19SLi Feng Wang import static org.junit.Assert.*; 26*28725c19SLi Feng Wang import static testlib.uno.GraphicUtil.getUniqueIDOfGraphicFile; 27*28725c19SLi Feng Wang import static testlib.uno.PageUtil.getDrawPageByIndex; 28*28725c19SLi Feng Wang import static testlib.uno.ShapeUtil.addPortion; 29*28725c19SLi Feng Wang import static testlib.uno.ShapeUtil.getPortion; 30*28725c19SLi Feng Wang 31*28725c19SLi Feng Wang import java.util.Arrays; 32*28725c19SLi Feng Wang import java.util.Collection; 33*28725c19SLi Feng Wang 34*28725c19SLi Feng Wang import org.junit.After; 35*28725c19SLi Feng Wang import org.junit.AfterClass; 36*28725c19SLi Feng Wang import org.junit.Before; 37*28725c19SLi Feng Wang import org.junit.BeforeClass; 38*28725c19SLi Feng Wang import org.junit.Test; 39*28725c19SLi Feng Wang import org.junit.runner.RunWith; 40*28725c19SLi Feng Wang import org.junit.runners.Parameterized; 41*28725c19SLi Feng Wang import org.junit.runners.Parameterized.Parameters; 42*28725c19SLi Feng Wang import org.openoffice.test.uno.UnoApp; 43*28725c19SLi Feng Wang import org.openoffice.test.common.FileUtil; 44*28725c19SLi Feng Wang import org.openoffice.test.common.Testspace; 45*28725c19SLi Feng Wang 46*28725c19SLi Feng Wang import testlib.uno.SDUtil; 47*28725c19SLi Feng Wang 48*28725c19SLi Feng Wang import com.sun.star.awt.Size; 49*28725c19SLi Feng Wang import com.sun.star.beans.PropertyValue; 50*28725c19SLi Feng Wang import com.sun.star.beans.UnknownPropertyException; 51*28725c19SLi Feng Wang import com.sun.star.beans.XPropertySet; 52*28725c19SLi Feng Wang import com.sun.star.container.XIndexReplace; 53*28725c19SLi Feng Wang import com.sun.star.drawing.XDrawPage; 54*28725c19SLi Feng Wang import com.sun.star.drawing.XShape; 55*28725c19SLi Feng Wang import com.sun.star.lang.WrappedTargetException; 56*28725c19SLi Feng Wang import com.sun.star.lang.XComponent; 57*28725c19SLi Feng Wang import com.sun.star.style.NumberingType; 58*28725c19SLi Feng Wang import com.sun.star.uno.UnoRuntime; 59*28725c19SLi Feng Wang 60*28725c19SLi Feng Wang /** 61*28725c19SLi Feng Wang * @author LouQL 62*28725c19SLi Feng Wang * 63*28725c19SLi Feng Wang */ 64*28725c19SLi Feng Wang @RunWith(Parameterized.class) 65*28725c19SLi Feng Wang public class NumberingBulletTypes { 66*28725c19SLi Feng Wang 67*28725c19SLi Feng Wang private static final UnoApp app = new UnoApp(); 68*28725c19SLi Feng Wang 69*28725c19SLi Feng Wang private XComponent m_xSDComponent = null; 70*28725c19SLi Feng Wang private String m_filePath = null; 71*28725c19SLi Feng Wang private XPropertySet m_xtextProps = null; 72*28725c19SLi Feng Wang private short m_numberingType = 0; 73*28725c19SLi Feng Wang private short m_expectType=0; 74*28725c19SLi Feng Wang 75*28725c19SLi Feng Wang @Before setUpDocument()76*28725c19SLi Feng Wang public void setUpDocument() throws Exception { 77*28725c19SLi Feng Wang m_filePath = Testspace.getPath("temp/NumberingBulletTypes.odp"); 78*28725c19SLi Feng Wang if (FileUtil.fileExists(m_filePath)) {//load 79*28725c19SLi Feng Wang m_xtextProps = load(); 80*28725c19SLi Feng Wang } else {//new 81*28725c19SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface( 82*28725c19SLi Feng Wang XComponent.class, app.newDocument("simpress")); 83*28725c19SLi Feng Wang Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 84*28725c19SLi Feng Wang Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1); 85*28725c19SLi Feng Wang XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox); 86*28725c19SLi Feng Wang m_xtextProps = addPortion(xsecondTextBox, "Numbering bullets", false); 87*28725c19SLi Feng Wang } 88*28725c19SLi Feng Wang } load()89*28725c19SLi Feng Wang private XPropertySet load() throws Exception{ 90*28725c19SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 91*28725c19SLi Feng Wang app.loadDocument(m_filePath)); 92*28725c19SLi Feng Wang Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 93*28725c19SLi Feng Wang XDrawPage firstpage = getDrawPageByIndex(m_xSDComponent, 0); 94*28725c19SLi Feng Wang Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1); 95*28725c19SLi Feng Wang XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox); 96*28725c19SLi Feng Wang return getPortion(xsecondTextBox, 0); 97*28725c19SLi Feng Wang } 98*28725c19SLi Feng Wang 99*28725c19SLi Feng Wang @After tearDownDocument()100*28725c19SLi Feng Wang public void tearDownDocument() { 101*28725c19SLi Feng Wang app.closeDocument(m_xSDComponent); 102*28725c19SLi Feng Wang //remove the temp file 103*28725c19SLi Feng Wang FileUtil.deleteFile(Testspace.getPath("temp")); 104*28725c19SLi Feng Wang } 105*28725c19SLi Feng Wang 106*28725c19SLi Feng Wang @BeforeClass setUpConnection()107*28725c19SLi Feng Wang public static void setUpConnection() throws Exception { 108*28725c19SLi Feng Wang app.start(); 109*28725c19SLi Feng Wang } 110*28725c19SLi Feng Wang 111*28725c19SLi Feng Wang @AfterClass tearDownConnection()112*28725c19SLi Feng Wang public static void tearDownConnection() throws InterruptedException, 113*28725c19SLi Feng Wang Exception { 114*28725c19SLi Feng Wang app.close(); 115*28725c19SLi Feng Wang 116*28725c19SLi Feng Wang } 117*28725c19SLi Feng Wang 118*28725c19SLi Feng Wang @Parameters data()119*28725c19SLi Feng Wang public static Collection<Short[]> data(){ 120*28725c19SLi Feng Wang Short[][] numberingTypes = new Short[][]{ 121*28725c19SLi Feng Wang {NumberingType.CHARS_UPPER_LETTER, NumberingType.CHARS_UPPER_LETTER}, 122*28725c19SLi Feng Wang {NumberingType.CHARS_LOWER_LETTER, NumberingType.CHARS_LOWER_LETTER}, 123*28725c19SLi Feng Wang {NumberingType.ROMAN_UPPER, NumberingType.ROMAN_UPPER}, 124*28725c19SLi Feng Wang {NumberingType.ROMAN_LOWER, NumberingType.ROMAN_LOWER}, 125*28725c19SLi Feng Wang {NumberingType.ARABIC, NumberingType.ARABIC}, 126*28725c19SLi Feng Wang //bug: 120752 127*28725c19SLi Feng Wang // {NumberingType.CIRCLE_NUMBER, NumberingType.CIRCLE_NUMBER}, 128*28725c19SLi Feng Wang {NumberingType.NUMBER_NONE, NumberingType.NUMBER_NONE}}; 129*28725c19SLi Feng Wang return Arrays.asList(numberingTypes); 130*28725c19SLi Feng Wang } 131*28725c19SLi Feng Wang NumberingBulletTypes(short input, short expect)132*28725c19SLi Feng Wang public NumberingBulletTypes(short input, short expect){ 133*28725c19SLi Feng Wang m_numberingType = input; 134*28725c19SLi Feng Wang m_expectType = expect; 135*28725c19SLi Feng Wang } 136*28725c19SLi Feng Wang 137*28725c19SLi Feng Wang /*NumberingType: specifies the type of numbering 138*28725c19SLi Feng Wang * GUI entry:Numbering and Bullet dialog->Customize->Numbering 139*28725c19SLi Feng Wang * */ 140*28725c19SLi Feng Wang @Test testNumberingTypes()141*28725c19SLi Feng Wang public void testNumberingTypes() throws Exception { 142*28725c19SLi Feng Wang Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules"); 143*28725c19SLi Feng Wang 144*28725c19SLi Feng Wang XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface( 145*28725c19SLi Feng Wang XIndexReplace.class, numberingrules); 146*28725c19SLi Feng Wang 147*28725c19SLi Feng Wang PropertyValue[] props = new PropertyValue[1]; 148*28725c19SLi Feng Wang props[0] = new PropertyValue(); 149*28725c19SLi Feng Wang props[0].Name = "NumberingType"; 150*28725c19SLi Feng Wang props[0].Value = m_numberingType; 151*28725c19SLi Feng Wang 152*28725c19SLi Feng Wang xReplace.replaceByIndex(0, props); 153*28725c19SLi Feng Wang 154*28725c19SLi Feng Wang m_xtextProps.setPropertyValue("NumberingRules", numberingrules); 155*28725c19SLi Feng Wang //set numbering level to 0 156*28725c19SLi Feng Wang m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0)); 157*28725c19SLi Feng Wang 158*28725c19SLi Feng Wang app.saveDocument(m_xSDComponent, m_filePath); 159*28725c19SLi Feng Wang app.closeDocument(m_xSDComponent); 160*28725c19SLi Feng Wang // m_xSDComponent.dispose(); 161*28725c19SLi Feng Wang //reopen 162*28725c19SLi Feng Wang m_xtextProps = load(); 163*28725c19SLi Feng Wang 164*28725c19SLi Feng Wang Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules"); 165*28725c19SLi Feng Wang 166*28725c19SLi Feng Wang XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface( 167*28725c19SLi Feng Wang XIndexReplace.class, numberingrules2); 168*28725c19SLi Feng Wang 169*28725c19SLi Feng Wang PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0); 170*28725c19SLi Feng Wang 171*28725c19SLi Feng Wang assertEquals("NumberingType should be"+m_numberingType, m_expectType, proValues2[0].Value); 172*28725c19SLi Feng Wang } 173*28725c19SLi Feng Wang } 174