1*07d7dbdcSHerbert Dürr /************************************************************** 2*07d7dbdcSHerbert Dürr * 3*07d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 4*07d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 5*07d7dbdcSHerbert Dürr * distributed with this work for additional information 6*07d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 7*07d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 8*07d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 9*07d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 10*07d7dbdcSHerbert Dürr * 11*07d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 12*07d7dbdcSHerbert Dürr * 13*07d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 14*07d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 15*07d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*07d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 17*07d7dbdcSHerbert Dürr * specific language governing permissions and limitations 18*07d7dbdcSHerbert Dürr * under the License. 19*07d7dbdcSHerbert Dürr * 20*07d7dbdcSHerbert 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 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 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 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 98323ac9c5SLi Feng Wang public static void tearDownAfterClass() throws Exception { 99323ac9c5SLi Feng Wang app.close(); 100323ac9c5SLi Feng Wang //remove the temp file 101323ac9c5SLi Feng Wang FileUtil.deleteFile(Testspace.getPath("temp")); 102323ac9c5SLi Feng Wang } 103323ac9c5SLi Feng Wang 104323ac9c5SLi Feng Wang /** 105323ac9c5SLi Feng Wang * @throws java.lang.Exception 106323ac9c5SLi Feng Wang */ 107323ac9c5SLi Feng Wang @Before 108323ac9c5SLi Feng Wang public void setUp() throws Exception { 109323ac9c5SLi Feng Wang m_filePath = Testspace.getPath("temp/CheckBuildInBullet.odt"); 110323ac9c5SLi Feng Wang // m_filePath = "F:/aa.odp"; 111323ac9c5SLi Feng Wang if(FileUtil.fileExists(m_filePath)) 112323ac9c5SLi Feng Wang { //load 113323ac9c5SLi Feng Wang m_xtextProps = load(); 114323ac9c5SLi Feng Wang } 115323ac9c5SLi Feng Wang else{ 116323ac9c5SLi Feng Wang //create a sd 117323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); 118323ac9c5SLi Feng Wang Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 119323ac9c5SLi Feng Wang Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 120323ac9c5SLi Feng Wang XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox); 121323ac9c5SLi Feng Wang m_xtextProps = addPortion(xfirstTextBox, "test Build-in Bullet", false); 122323ac9c5SLi Feng Wang } 123323ac9c5SLi Feng Wang } 124323ac9c5SLi Feng Wang 125323ac9c5SLi Feng Wang /** 126323ac9c5SLi Feng Wang * @throws java.lang.Exception 127323ac9c5SLi Feng Wang */ 128323ac9c5SLi Feng Wang @After 129323ac9c5SLi Feng Wang public void tearDown() throws Exception { 130323ac9c5SLi Feng Wang app.closeDocument(m_xSDComponent); 131323ac9c5SLi Feng Wang } 132323ac9c5SLi Feng Wang private XPropertySet load() throws Exception{ 133323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 134323ac9c5SLi Feng Wang app.loadDocument(m_filePath)); 135323ac9c5SLi Feng Wang Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 136323ac9c5SLi Feng Wang Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 137323ac9c5SLi Feng Wang XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox); 138323ac9c5SLi Feng Wang return getPortion(xfirstTextBox, 0); 139323ac9c5SLi Feng Wang } 140323ac9c5SLi Feng Wang 141323ac9c5SLi Feng Wang @Test 142323ac9c5SLi Feng Wang public void testBuildInBullet() throws Exception { 143323ac9c5SLi Feng Wang 144323ac9c5SLi Feng Wang Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules"); 145323ac9c5SLi Feng Wang 146323ac9c5SLi Feng Wang XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface( 147323ac9c5SLi Feng Wang XIndexReplace.class, numberingrules); 148323ac9c5SLi Feng Wang 149323ac9c5SLi Feng Wang PropertyValue[] props = new PropertyValue[2]; 150323ac9c5SLi Feng Wang props[0] = new PropertyValue(); 151323ac9c5SLi Feng Wang props[0].Name = "NumberingType"; 152323ac9c5SLi Feng Wang props[0].Value = new Short(NumberingType.CHAR_SPECIAL ); 153323ac9c5SLi Feng Wang 154323ac9c5SLi Feng Wang props[1] = new PropertyValue(); 155323ac9c5SLi Feng Wang props[1].Name = "BulletChar"; 156323ac9c5SLi Feng Wang props[1].Value = this.m_BulletChar; 157323ac9c5SLi Feng Wang 158323ac9c5SLi Feng Wang //set numberingType 159323ac9c5SLi Feng Wang xReplace.replaceByIndex(0, props); 160323ac9c5SLi Feng Wang m_xtextProps.setPropertyValue("NumberingRules", numberingrules); 161323ac9c5SLi Feng Wang //set numbering level to 0 162323ac9c5SLi Feng Wang m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0)); 163323ac9c5SLi Feng Wang 164323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, m_filePath); 165323ac9c5SLi Feng Wang app.closeDocument(m_xSDComponent); 166323ac9c5SLi Feng Wang //reopen 167323ac9c5SLi Feng Wang m_xtextProps = load(); 168323ac9c5SLi Feng Wang 169323ac9c5SLi Feng Wang Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules"); 170323ac9c5SLi Feng Wang 171323ac9c5SLi Feng Wang XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface( 172323ac9c5SLi Feng Wang XIndexReplace.class, numberingrules2); 173323ac9c5SLi Feng Wang 174323ac9c5SLi Feng Wang PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0); 175323ac9c5SLi Feng Wang assertEquals("NumberingType should be CHAR_SPECIAL", NumberingType.CHAR_SPECIAL, proValues2[0].Value); 176323ac9c5SLi Feng Wang assertEquals("BulletChar should be"+m_expectedBulletChar, m_expectedBulletChar, proValues2[4].Value); 177323ac9c5SLi Feng Wang } 178323ac9c5SLi Feng Wang } 179