107d7dbdcSHerbert Dürr /************************************************************** 207d7dbdcSHerbert Dürr * 307d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 407d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 507d7dbdcSHerbert Dürr * distributed with this work for additional information 607d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 707d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 807d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 907d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 1007d7dbdcSHerbert Dürr * 1107d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 1207d7dbdcSHerbert Dürr * 1307d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 1407d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 1507d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1607d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 1707d7dbdcSHerbert Dürr * specific language governing permissions and limitations 1807d7dbdcSHerbert Dürr * under the License. 1907d7dbdcSHerbert Dürr * 2007d7dbdcSHerbert Dürr *************************************************************/ 21323ac9c5SLi Feng Wang /** 22323ac9c5SLi Feng Wang * There are 8 build-in bullets. Verify those bullets can be applied successfully. 23323ac9c5SLi Feng Wang * insert text into a SD 24323ac9c5SLi Feng Wang * apply the 8 bullets one by one, and check 25323ac9c5SLi Feng Wang */ 26323ac9c5SLi Feng Wang package fvt.uno.sd.bullet; 27323ac9c5SLi Feng Wang 28323ac9c5SLi Feng Wang import static org.junit.Assert.assertEquals; 29323ac9c5SLi Feng Wang import static testlib.uno.PageUtil.getDrawPageByIndex; 30323ac9c5SLi Feng Wang import static testlib.uno.ShapeUtil.addPortion; 31323ac9c5SLi Feng Wang import static testlib.uno.ShapeUtil.getPortion; 32323ac9c5SLi Feng Wang 33323ac9c5SLi Feng Wang import java.io.File; 34323ac9c5SLi Feng Wang import java.util.Arrays; 35323ac9c5SLi Feng Wang import java.util.Collection; 36323ac9c5SLi Feng Wang 37323ac9c5SLi Feng Wang import org.junit.After; 38323ac9c5SLi Feng Wang import org.junit.AfterClass; 39323ac9c5SLi Feng Wang import org.junit.Before; 40323ac9c5SLi Feng Wang import org.junit.BeforeClass; 41323ac9c5SLi Feng Wang import org.junit.Test; 42323ac9c5SLi Feng Wang import org.junit.runner.RunWith; 43323ac9c5SLi Feng Wang import org.junit.runners.Parameterized; 44323ac9c5SLi Feng Wang import org.junit.runners.Parameterized.Parameters; 45323ac9c5SLi Feng Wang import org.openoffice.test.common.FileUtil; 46323ac9c5SLi Feng Wang import org.openoffice.test.common.Testspace; 47323ac9c5SLi Feng Wang import org.openoffice.test.uno.UnoApp; 48323ac9c5SLi Feng Wang 49323ac9c5SLi Feng Wang import testlib.uno.SDUtil; 50323ac9c5SLi Feng Wang 51323ac9c5SLi Feng Wang import com.sun.star.beans.PropertyValue; 52323ac9c5SLi Feng Wang import com.sun.star.beans.XPropertySet; 53323ac9c5SLi Feng Wang import com.sun.star.container.XIndexReplace; 54323ac9c5SLi Feng Wang import com.sun.star.drawing.XShape; 55323ac9c5SLi Feng Wang import com.sun.star.lang.XComponent; 56323ac9c5SLi Feng Wang import com.sun.star.style.NumberingType; 57323ac9c5SLi Feng Wang import com.sun.star.uno.UnoRuntime; 58323ac9c5SLi Feng Wang 59323ac9c5SLi Feng Wang 60323ac9c5SLi Feng Wang /** 61323ac9c5SLi Feng Wang * @author LouQL 62323ac9c5SLi Feng Wang * 63323ac9c5SLi Feng Wang */ 64323ac9c5SLi Feng Wang @RunWith(Parameterized.class) 65323ac9c5SLi Feng Wang public class CheckBuildInBullet { 66323ac9c5SLi Feng Wang 67323ac9c5SLi Feng Wang private static final UnoApp app = new UnoApp(); 68323ac9c5SLi Feng Wang private XComponent m_xSDComponent = null; 69323ac9c5SLi Feng Wang private String m_filePath = null; 70323ac9c5SLi Feng Wang private XPropertySet m_xtextProps = null; 71323ac9c5SLi Feng Wang private String m_BulletChar = null; 72323ac9c5SLi Feng Wang private String m_expectedBulletChar = null; 73323ac9c5SLi Feng Wang /** 74323ac9c5SLi Feng Wang * @throws java.lang.Exception 75323ac9c5SLi Feng Wang */ 76323ac9c5SLi Feng Wang CheckBuildInBullet(String BulletChar, String expected)77323ac9c5SLi Feng Wang public CheckBuildInBullet(String BulletChar, String expected) { 78323ac9c5SLi Feng Wang this.m_BulletChar = BulletChar; 79323ac9c5SLi Feng Wang m_expectedBulletChar = expected; 80323ac9c5SLi Feng Wang } 81323ac9c5SLi Feng Wang @Parameters data()82323ac9c5SLi Feng Wang public static Collection<String[]> data() { 83323ac9c5SLi Feng Wang String[][] bulletChar = new String[][] {{"\u25cf","\u25cf"}, {"\u2022","\u2022"}, {"\ue00c","\ue00c"},{"\ue00a","\ue00a"},{"\u2794","\u2794"}, {"\u27a2","\u27a2"}, {"\u2717","\u2717"},{"\u2714","\u2714"}}; 84323ac9c5SLi Feng Wang return Arrays.asList(bulletChar); 85323ac9c5SLi Feng Wang } 86323ac9c5SLi Feng Wang 87323ac9c5SLi Feng Wang @BeforeClass setUpBeforeClass()88323ac9c5SLi Feng Wang public static void setUpBeforeClass() throws Exception { 89323ac9c5SLi Feng Wang app.start(); 90323ac9c5SLi Feng Wang File temp = new File(Testspace.getPath("temp")); 91323ac9c5SLi Feng Wang temp.mkdirs(); 92323ac9c5SLi Feng Wang } 93323ac9c5SLi Feng Wang 94323ac9c5SLi Feng Wang /** 95323ac9c5SLi Feng Wang * @throws java.lang.Exception 96323ac9c5SLi Feng Wang */ 97323ac9c5SLi Feng Wang @AfterClass tearDownAfterClass()98323ac9c5SLi Feng Wang public static void tearDownAfterClass() throws Exception { 99323ac9c5SLi Feng Wang app.close(); 100323ac9c5SLi Feng Wang } 101323ac9c5SLi Feng Wang 102323ac9c5SLi Feng Wang /** 103323ac9c5SLi Feng Wang * @throws java.lang.Exception 104323ac9c5SLi Feng Wang */ 105323ac9c5SLi Feng Wang @Before setUp()106323ac9c5SLi Feng Wang public void setUp() throws Exception { 107*de51bb97SLi Feng Wang m_filePath = Testspace.getPath("temp/CheckBuildInBullet.odp"); 108323ac9c5SLi Feng Wang // m_filePath = "F:/aa.odp"; 109323ac9c5SLi Feng Wang if(FileUtil.fileExists(m_filePath)) 110323ac9c5SLi Feng Wang { //load 111323ac9c5SLi Feng Wang m_xtextProps = load(); 112323ac9c5SLi Feng Wang } 113323ac9c5SLi Feng Wang else{ 114323ac9c5SLi Feng Wang //create a sd 115323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); 116323ac9c5SLi Feng Wang Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 117323ac9c5SLi Feng Wang Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 118323ac9c5SLi Feng Wang XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox); 119323ac9c5SLi Feng Wang m_xtextProps = addPortion(xfirstTextBox, "test Build-in Bullet", false); 120323ac9c5SLi Feng Wang } 121323ac9c5SLi Feng Wang } 122323ac9c5SLi Feng Wang 123323ac9c5SLi Feng Wang /** 124323ac9c5SLi Feng Wang * @throws java.lang.Exception 125323ac9c5SLi Feng Wang */ 126323ac9c5SLi Feng Wang @After tearDown()127323ac9c5SLi Feng Wang public void tearDown() throws Exception { 128323ac9c5SLi Feng Wang app.closeDocument(m_xSDComponent); 129*de51bb97SLi Feng Wang FileUtil.deleteFile(Testspace.getPath("temp")); 130323ac9c5SLi Feng Wang } load()131323ac9c5SLi Feng Wang private XPropertySet load() throws Exception{ 132323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 133323ac9c5SLi Feng Wang app.loadDocument(m_filePath)); 134323ac9c5SLi Feng Wang Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 135323ac9c5SLi Feng Wang Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 136323ac9c5SLi Feng Wang XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox); 137323ac9c5SLi Feng Wang return getPortion(xfirstTextBox, 0); 138323ac9c5SLi Feng Wang } 139323ac9c5SLi Feng Wang 140323ac9c5SLi Feng Wang @Test testBuildInBullet()141323ac9c5SLi Feng Wang public void testBuildInBullet() throws Exception { 142323ac9c5SLi Feng Wang 143323ac9c5SLi Feng Wang Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules"); 144323ac9c5SLi Feng Wang 145323ac9c5SLi Feng Wang XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface( 146323ac9c5SLi Feng Wang XIndexReplace.class, numberingrules); 147323ac9c5SLi Feng Wang 148323ac9c5SLi Feng Wang PropertyValue[] props = new PropertyValue[2]; 149323ac9c5SLi Feng Wang props[0] = new PropertyValue(); 150323ac9c5SLi Feng Wang props[0].Name = "NumberingType"; 151323ac9c5SLi Feng Wang props[0].Value = new Short(NumberingType.CHAR_SPECIAL ); 152323ac9c5SLi Feng Wang 153323ac9c5SLi Feng Wang props[1] = new PropertyValue(); 154323ac9c5SLi Feng Wang props[1].Name = "BulletChar"; 155323ac9c5SLi Feng Wang props[1].Value = this.m_BulletChar; 156323ac9c5SLi Feng Wang 157323ac9c5SLi Feng Wang //set numberingType 158323ac9c5SLi Feng Wang xReplace.replaceByIndex(0, props); 159323ac9c5SLi Feng Wang m_xtextProps.setPropertyValue("NumberingRules", numberingrules); 160323ac9c5SLi Feng Wang //set numbering level to 0 161323ac9c5SLi Feng Wang m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0)); 162323ac9c5SLi Feng Wang 163323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, m_filePath); 164323ac9c5SLi Feng Wang app.closeDocument(m_xSDComponent); 165323ac9c5SLi Feng Wang //reopen 166323ac9c5SLi Feng Wang m_xtextProps = load(); 167323ac9c5SLi Feng Wang 168323ac9c5SLi Feng Wang Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules"); 169323ac9c5SLi Feng Wang 170323ac9c5SLi Feng Wang XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface( 171323ac9c5SLi Feng Wang XIndexReplace.class, numberingrules2); 172323ac9c5SLi Feng Wang 173323ac9c5SLi Feng Wang PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0); 174323ac9c5SLi Feng Wang assertEquals("NumberingType should be CHAR_SPECIAL", NumberingType.CHAR_SPECIAL, proValues2[0].Value); 175323ac9c5SLi Feng Wang assertEquals("BulletChar should be"+m_expectedBulletChar, m_expectedBulletChar, proValues2[4].Value); 176323ac9c5SLi Feng Wang } 177323ac9c5SLi Feng Wang } 178