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