1 /** 2 * There are 8 build-in bullets. Verify those bullets can be applied successfully. 3 * insert text into a SD 4 * apply the 8 bullets one by one, and check 5 */ 6 package fvt.uno.sd.bullet; 7 8 import static org.junit.Assert.assertEquals; 9 import static testlib.uno.PageUtil.getDrawPageByIndex; 10 import static testlib.uno.ShapeUtil.addPortion; 11 import static testlib.uno.ShapeUtil.getPortion; 12 13 import java.io.File; 14 import java.util.Arrays; 15 import java.util.Collection; 16 17 import org.junit.After; 18 import org.junit.AfterClass; 19 import org.junit.Before; 20 import org.junit.BeforeClass; 21 import org.junit.Test; 22 import org.junit.runner.RunWith; 23 import org.junit.runners.Parameterized; 24 import org.junit.runners.Parameterized.Parameters; 25 import org.openoffice.test.common.FileUtil; 26 import org.openoffice.test.common.Testspace; 27 import org.openoffice.test.uno.UnoApp; 28 29 import testlib.uno.SDUtil; 30 31 import com.sun.star.beans.PropertyValue; 32 import com.sun.star.beans.XPropertySet; 33 import com.sun.star.container.XIndexReplace; 34 import com.sun.star.drawing.XShape; 35 import com.sun.star.lang.XComponent; 36 import com.sun.star.style.NumberingType; 37 import com.sun.star.uno.UnoRuntime; 38 39 40 /** 41 * @author LouQL 42 * 43 */ 44 @RunWith(Parameterized.class) 45 public class CheckBuildInBullet { 46 47 private static final UnoApp app = new UnoApp(); 48 private XComponent m_xSDComponent = null; 49 private String m_filePath = null; 50 private XPropertySet m_xtextProps = null; 51 private String m_BulletChar = null; 52 private String m_expectedBulletChar = null; 53 /** 54 * @throws java.lang.Exception 55 */ 56 57 public CheckBuildInBullet(String BulletChar, String expected) { 58 this.m_BulletChar = BulletChar; 59 m_expectedBulletChar = expected; 60 } 61 @Parameters 62 public static Collection<String[]> data() { 63 String[][] bulletChar = new String[][] {{"\u25cf","\u25cf"}, {"\u2022","\u2022"}, {"\ue00c","\ue00c"},{"\ue00a","\ue00a"},{"\u2794","\u2794"}, {"\u27a2","\u27a2"}, {"\u2717","\u2717"},{"\u2714","\u2714"}}; 64 return Arrays.asList(bulletChar); 65 } 66 67 @BeforeClass 68 public static void setUpBeforeClass() throws Exception { 69 app.start(); 70 File temp = new File(Testspace.getPath("temp")); 71 temp.mkdirs(); 72 } 73 74 /** 75 * @throws java.lang.Exception 76 */ 77 @AfterClass 78 public static void tearDownAfterClass() throws Exception { 79 app.close(); 80 //remove the temp file 81 FileUtil.deleteFile(Testspace.getPath("temp")); 82 } 83 84 /** 85 * @throws java.lang.Exception 86 */ 87 @Before 88 public void setUp() throws Exception { 89 m_filePath = Testspace.getPath("temp/CheckBuildInBullet.odt"); 90 // m_filePath = "F:/aa.odp"; 91 if(FileUtil.fileExists(m_filePath)) 92 { //load 93 m_xtextProps = load(); 94 } 95 else{ 96 //create a sd 97 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); 98 Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 99 Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 100 XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox); 101 m_xtextProps = addPortion(xfirstTextBox, "test Build-in Bullet", false); 102 } 103 } 104 105 /** 106 * @throws java.lang.Exception 107 */ 108 @After 109 public void tearDown() throws Exception { 110 app.closeDocument(m_xSDComponent); 111 } 112 private XPropertySet load() throws Exception{ 113 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 114 app.loadDocument(m_filePath)); 115 Object firstPage = getDrawPageByIndex(m_xSDComponent, 0); 116 Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 117 XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox); 118 return getPortion(xfirstTextBox, 0); 119 } 120 121 @Test 122 public void testBuildInBullet() throws Exception { 123 124 Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules"); 125 126 XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface( 127 XIndexReplace.class, numberingrules); 128 129 PropertyValue[] props = new PropertyValue[2]; 130 props[0] = new PropertyValue(); 131 props[0].Name = "NumberingType"; 132 props[0].Value = new Short(NumberingType.CHAR_SPECIAL ); 133 134 props[1] = new PropertyValue(); 135 props[1].Name = "BulletChar"; 136 props[1].Value = this.m_BulletChar; 137 138 //set numberingType 139 xReplace.replaceByIndex(0, props); 140 m_xtextProps.setPropertyValue("NumberingRules", numberingrules); 141 //set numbering level to 0 142 m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0)); 143 144 app.saveDocument(m_xSDComponent, m_filePath); 145 app.closeDocument(m_xSDComponent); 146 //reopen 147 m_xtextProps = load(); 148 149 Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules"); 150 151 XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface( 152 XIndexReplace.class, numberingrules2); 153 154 PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0); 155 assertEquals("NumberingType should be CHAR_SPECIAL", NumberingType.CHAR_SPECIAL, proValues2[0].Value); 156 assertEquals("BulletChar should be"+m_expectedBulletChar, m_expectedBulletChar, proValues2[4].Value); 157 } 158 } 159