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