13104132fSLiu Zhe /************************************************************** 23104132fSLiu Zhe * 33104132fSLiu Zhe * Licensed to the Apache Software Foundation (ASF) under one 43104132fSLiu Zhe * or more contributor license agreements. See the NOTICE file 53104132fSLiu Zhe * distributed with this work for additional information 63104132fSLiu Zhe * regarding copyright ownership. The ASF licenses this file 73104132fSLiu Zhe * to you under the Apache License, Version 2.0 (the 83104132fSLiu Zhe * "License"); you may not use this file except in compliance 93104132fSLiu Zhe * with the License. You may obtain a copy of the License at 103104132fSLiu Zhe * 113104132fSLiu Zhe * http://www.apache.org/licenses/LICENSE-2.0 123104132fSLiu Zhe * 133104132fSLiu Zhe * Unless required by applicable law or agreed to in writing, 143104132fSLiu Zhe * software distributed under the License is distributed on an 153104132fSLiu Zhe * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 163104132fSLiu Zhe * KIND, either express or implied. See the License for the 173104132fSLiu Zhe * specific language governing permissions and limitations 183104132fSLiu Zhe * under the License. 193104132fSLiu Zhe * 203104132fSLiu Zhe *************************************************************/ 213104132fSLiu Zhe /** 223104132fSLiu Zhe * 233104132fSLiu Zhe */ 24323ac9c5SLi Feng Wang package fvt.uno.sd.bullet; 253104132fSLiu Zhe import static org.junit.Assert.*; 263104132fSLiu Zhe import static testlib.uno.PageUtil.getDrawPageByIndex; 273104132fSLiu Zhe import static testlib.uno.ShapeUtil.*; 283104132fSLiu Zhe 293104132fSLiu Zhe import org.junit.After; 303104132fSLiu Zhe import org.junit.AfterClass; 313104132fSLiu Zhe import org.junit.Before; 323104132fSLiu Zhe import org.junit.BeforeClass; 333104132fSLiu Zhe import org.junit.Test; 343104132fSLiu Zhe import org.openoffice.test.common.FileUtil; 353104132fSLiu Zhe import org.openoffice.test.common.Testspace; 363104132fSLiu Zhe import org.openoffice.test.uno.UnoApp; 373104132fSLiu Zhe 383104132fSLiu Zhe import com.sun.star.beans.PropertyValue; 393104132fSLiu Zhe import com.sun.star.beans.XPropertySet; 403104132fSLiu Zhe import com.sun.star.container.XIndexReplace; 413104132fSLiu Zhe import com.sun.star.drawing.XShape; 423104132fSLiu Zhe 433104132fSLiu Zhe import com.sun.star.lang.XComponent; 443104132fSLiu Zhe 453104132fSLiu Zhe import com.sun.star.style.NumberingType; 463104132fSLiu Zhe import com.sun.star.uno.UnoRuntime; 473104132fSLiu Zhe import testlib.uno.SDUtil; 483104132fSLiu Zhe 493104132fSLiu Zhe /** 503104132fSLiu Zhe * 1. New a SD 513104132fSLiu Zhe 2. Insert some text 523104132fSLiu Zhe 3. Set bullet on 533104132fSLiu Zhe 4. Change the bullet color and bullet size 543104132fSLiu Zhe 5. save/close/reopen and then check the bullet color and size 553104132fSLiu Zhe * 563104132fSLiu Zhe */ 573104132fSLiu Zhe public class CheckBulletStyle { 583104132fSLiu Zhe 593104132fSLiu Zhe private static final UnoApp app = new UnoApp(); 603104132fSLiu Zhe 613104132fSLiu Zhe private XComponent m_xSDComponent = null; 623104132fSLiu Zhe private String m_filePath = null; 633104132fSLiu Zhe // private XShape m_xsecondTextBox = null; 643104132fSLiu Zhe Object m_numberingRules = null; 653104132fSLiu Zhe XPropertySet m_textProperty = null; 663104132fSLiu Zhe XIndexReplace m_xReplace = null; 673104132fSLiu Zhe 683104132fSLiu Zhe @Before setUpDocument()693104132fSLiu Zhe public void setUpDocument() throws Exception { 70*28725c19SLi Feng Wang m_filePath = Testspace.getPath("temp/CheckBulletStyle.odp"); 713104132fSLiu Zhe if(FileUtil.fileExists(m_filePath)) 723104132fSLiu Zhe { //load 733104132fSLiu Zhe m_xReplace = load(); 743104132fSLiu Zhe } 753104132fSLiu Zhe else{ 763104132fSLiu Zhe //create a sd 773104132fSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); 783104132fSLiu Zhe Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 793104132fSLiu Zhe Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1); 803104132fSLiu Zhe XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox); 813104132fSLiu Zhe m_textProperty = addPortion(xsecondTextBox, "Test Bullet Style", false); 823104132fSLiu Zhe 833104132fSLiu Zhe //get numberingRules 843104132fSLiu Zhe m_numberingRules = m_textProperty.getPropertyValue("NumberingRules"); 853104132fSLiu Zhe 863104132fSLiu Zhe m_xReplace = (XIndexReplace) UnoRuntime.queryInterface( 873104132fSLiu Zhe XIndexReplace.class, m_numberingRules); 883104132fSLiu Zhe 893104132fSLiu Zhe PropertyValue[] props = new PropertyValue[1]; 903104132fSLiu Zhe props[0] = new PropertyValue(); 913104132fSLiu Zhe props[0].Name = "NumberingType"; 923104132fSLiu Zhe props[0].Value = new Short(NumberingType.CHAR_SPECIAL ); 933104132fSLiu Zhe 943104132fSLiu Zhe //set numberingType 953104132fSLiu Zhe m_xReplace.replaceByIndex(0, props); 963104132fSLiu Zhe m_textProperty.setPropertyValue("NumberingRules", m_numberingRules); 973104132fSLiu Zhe //set numbering level to 0 983104132fSLiu Zhe m_textProperty.setPropertyValue("NumberingLevel", new Short((short)0)); 993104132fSLiu Zhe } 1003104132fSLiu Zhe } load()1013104132fSLiu Zhe private XIndexReplace load() throws Exception{ 1023104132fSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 1033104132fSLiu Zhe app.loadDocument(m_filePath)); 1043104132fSLiu Zhe Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 1053104132fSLiu Zhe Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1); 1063104132fSLiu Zhe XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox); 1073104132fSLiu Zhe m_textProperty = getPortion(xsecondTextBox, 0); 1083104132fSLiu Zhe 1093104132fSLiu Zhe m_numberingRules = m_textProperty.getPropertyValue("NumberingRules"); 1103104132fSLiu Zhe 1113104132fSLiu Zhe XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface( 1123104132fSLiu Zhe XIndexReplace.class, m_numberingRules); 1133104132fSLiu Zhe return xReplace; 1143104132fSLiu Zhe } 1153104132fSLiu Zhe 1163104132fSLiu Zhe @After tearDownDocument()1173104132fSLiu Zhe public void tearDownDocument() { 1183104132fSLiu Zhe app.closeDocument(m_xSDComponent); 119*28725c19SLi Feng Wang 120*28725c19SLi Feng Wang //remove the temp file 121*28725c19SLi Feng Wang FileUtil.deleteFile(Testspace.getPath("temp")); 1223104132fSLiu Zhe } 1233104132fSLiu Zhe 1243104132fSLiu Zhe @BeforeClass setUpConnection()1253104132fSLiu Zhe public static void setUpConnection() throws Exception { 1263104132fSLiu Zhe app.start(); 1273104132fSLiu Zhe } 1283104132fSLiu Zhe 1293104132fSLiu Zhe @AfterClass tearDownConnection()1303104132fSLiu Zhe public static void tearDownConnection() throws InterruptedException, 1313104132fSLiu Zhe Exception { 1323104132fSLiu Zhe app.close(); 133*28725c19SLi Feng Wang 1343104132fSLiu Zhe } 1353104132fSLiu Zhe 1363104132fSLiu Zhe @Test testBulletColor()1373104132fSLiu Zhe public void testBulletColor() throws Exception { 1383104132fSLiu Zhe //BulletColor, Integer 1393104132fSLiu Zhe PropertyValue[] props = new PropertyValue[1]; 1403104132fSLiu Zhe props[0] = new PropertyValue(); 1413104132fSLiu Zhe props[0].Name = "BulletColor"; 1423104132fSLiu Zhe props[0].Value = new Integer(255); 1433104132fSLiu Zhe 1443104132fSLiu Zhe m_xReplace.replaceByIndex(0, props); 1453104132fSLiu Zhe m_textProperty.setPropertyValue("NumberingRules", m_numberingRules); 1463104132fSLiu Zhe 1473104132fSLiu Zhe app.saveDocument(m_xSDComponent, m_filePath); 1483104132fSLiu Zhe app.closeDocument(m_xSDComponent); 1493104132fSLiu Zhe 1503104132fSLiu Zhe XIndexReplace xReplace = load(); 1513104132fSLiu Zhe PropertyValue[] proValues = (PropertyValue[])xReplace.getByIndex(0); 1523104132fSLiu Zhe assertEquals("name should be BulletColor", "BulletColor", proValues[11].Name); 1533104132fSLiu Zhe assertEquals("BulletColor should be 255(Blue)", new Integer(255), proValues[11].Value); 1543104132fSLiu Zhe } 1553104132fSLiu Zhe 1563104132fSLiu Zhe @Test testBulletSize()1573104132fSLiu Zhe public void testBulletSize() throws Exception { 1583104132fSLiu Zhe //BulletRelSize, default 45 1593104132fSLiu Zhe PropertyValue[] props = new PropertyValue[1]; 1603104132fSLiu Zhe props[0] = new PropertyValue(); 1613104132fSLiu Zhe props[0].Name = "BulletRelSize"; 1623104132fSLiu Zhe props[0].Value = new Short((short)200); 1633104132fSLiu Zhe 1643104132fSLiu Zhe m_xReplace.replaceByIndex(0, props); 1653104132fSLiu Zhe m_textProperty.setPropertyValue("NumberingRules", m_numberingRules); 1663104132fSLiu Zhe 1673104132fSLiu Zhe app.saveDocument(m_xSDComponent, m_filePath); 1683104132fSLiu Zhe app.closeDocument(m_xSDComponent); 1693104132fSLiu Zhe 1703104132fSLiu Zhe XIndexReplace xReplace = load(); 1713104132fSLiu Zhe PropertyValue[] proValues = (PropertyValue[])xReplace.getByIndex(0); 1723104132fSLiu Zhe assertEquals("name should be BulletRelSize", "BulletRelSize", proValues[12].Name); 1733104132fSLiu Zhe assertEquals("BulletRelSize should be 200%", new Short((short)200), proValues[12].Value); 1743104132fSLiu Zhe } 1753104132fSLiu Zhe } 176