107d7dbdcSHerbert Dürr /**************************************************************
207d7dbdcSHerbert Dürr  *
307d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
407d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
507d7dbdcSHerbert Dürr  * distributed with this work for additional information
607d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
707d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
807d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
907d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
1007d7dbdcSHerbert Dürr  *
1107d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
1207d7dbdcSHerbert Dürr  *
1307d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
1407d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
1507d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1607d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
1707d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
1807d7dbdcSHerbert Dürr  * under the License.
1907d7dbdcSHerbert Dürr  *
2007d7dbdcSHerbert Dürr  *************************************************************/
213908dc91SLiu Zhe /**
223908dc91SLiu Zhe  * There are 8 build-in bullets. Verify those bullets can be applied successfully.
233908dc91SLiu Zhe  * insert text into a SD
243908dc91SLiu Zhe  * apply the 8 bullets one by one, and check
253908dc91SLiu Zhe  */
26323ac9c5SLi Feng Wang package fvt.uno.sd.bullet;
273908dc91SLiu Zhe 
283908dc91SLiu Zhe import static org.junit.Assert.assertEquals;
293908dc91SLiu Zhe import static testlib.uno.PageUtil.getDrawPageByIndex;
303908dc91SLiu Zhe import static testlib.uno.ShapeUtil.addPortion;
313908dc91SLiu Zhe import static testlib.uno.ShapeUtil.getPortion;
323908dc91SLiu Zhe 
333908dc91SLiu Zhe import java.io.File;
343908dc91SLiu Zhe import java.util.Arrays;
353908dc91SLiu Zhe import java.util.Collection;
363908dc91SLiu Zhe 
373908dc91SLiu Zhe import org.junit.After;
383908dc91SLiu Zhe import org.junit.AfterClass;
393908dc91SLiu Zhe import org.junit.Before;
403908dc91SLiu Zhe import org.junit.BeforeClass;
413908dc91SLiu Zhe import org.junit.Test;
423908dc91SLiu Zhe import org.junit.runner.RunWith;
433908dc91SLiu Zhe import org.junit.runners.Parameterized;
443908dc91SLiu Zhe import org.junit.runners.Parameterized.Parameters;
453908dc91SLiu Zhe import org.openoffice.test.common.FileUtil;
463908dc91SLiu Zhe import org.openoffice.test.common.Testspace;
473908dc91SLiu Zhe import org.openoffice.test.uno.UnoApp;
483908dc91SLiu Zhe 
493908dc91SLiu Zhe import testlib.uno.SDUtil;
503908dc91SLiu Zhe 
513908dc91SLiu Zhe import com.sun.star.beans.PropertyValue;
523908dc91SLiu Zhe import com.sun.star.beans.XPropertySet;
533908dc91SLiu Zhe import com.sun.star.container.XIndexReplace;
543908dc91SLiu Zhe import com.sun.star.drawing.XShape;
553908dc91SLiu Zhe import com.sun.star.lang.XComponent;
563908dc91SLiu Zhe import com.sun.star.style.NumberingType;
573908dc91SLiu Zhe import com.sun.star.uno.UnoRuntime;
583908dc91SLiu Zhe 
593908dc91SLiu Zhe 
603908dc91SLiu Zhe /**
613908dc91SLiu Zhe  * @author LouQL
623908dc91SLiu Zhe  *
633908dc91SLiu Zhe  */
643908dc91SLiu Zhe @RunWith(Parameterized.class)
653908dc91SLiu Zhe public class CheckBuildInBullet {
663908dc91SLiu Zhe 
673908dc91SLiu Zhe 	private static final UnoApp app = new UnoApp();
683908dc91SLiu Zhe 	private XComponent m_xSDComponent = null;
693908dc91SLiu Zhe 	private String m_filePath = null;
703908dc91SLiu Zhe 	private XPropertySet m_xtextProps = null;
713908dc91SLiu Zhe 	private String m_BulletChar = null;
723908dc91SLiu Zhe 	private String m_expectedBulletChar = null;
733908dc91SLiu Zhe 	/**
743908dc91SLiu Zhe 	 * @throws java.lang.Exception
753908dc91SLiu Zhe 	 */
763908dc91SLiu Zhe 
CheckBuildInBullet(String BulletChar, String expected)773908dc91SLiu Zhe 	public CheckBuildInBullet(String BulletChar, String expected) {
783908dc91SLiu Zhe         this.m_BulletChar = BulletChar;
793908dc91SLiu Zhe         m_expectedBulletChar = expected;
803908dc91SLiu Zhe     }
813908dc91SLiu Zhe 	@Parameters
data()823908dc91SLiu Zhe     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"}};
843908dc91SLiu Zhe         return Arrays.asList(bulletChar);
853908dc91SLiu Zhe     }
863908dc91SLiu Zhe 
873908dc91SLiu Zhe 	@BeforeClass
setUpBeforeClass()883908dc91SLiu Zhe 	public static void setUpBeforeClass() throws Exception {
893908dc91SLiu Zhe 		app.start();
903908dc91SLiu Zhe 		File temp = new File(Testspace.getPath("temp"));
913908dc91SLiu Zhe 		temp.mkdirs();
923908dc91SLiu Zhe 	}
933908dc91SLiu Zhe 
943908dc91SLiu Zhe 	/**
953908dc91SLiu Zhe 	 * @throws java.lang.Exception
963908dc91SLiu Zhe 	 */
973908dc91SLiu Zhe 	@AfterClass
tearDownAfterClass()983908dc91SLiu Zhe 	public static void tearDownAfterClass() throws Exception {
993908dc91SLiu Zhe 		app.close();
1003908dc91SLiu Zhe 	}
1013908dc91SLiu Zhe 
1023908dc91SLiu Zhe 	/**
1033908dc91SLiu Zhe 	 * @throws java.lang.Exception
1043908dc91SLiu Zhe 	 */
1053908dc91SLiu Zhe 	@Before
setUp()1063908dc91SLiu Zhe 	public void setUp() throws Exception {
107*de51bb97SLi Feng Wang 		m_filePath = Testspace.getPath("temp/CheckBuildInBullet.odp");
1083908dc91SLiu Zhe //		m_filePath = "F:/aa.odp";
1093908dc91SLiu Zhe 		if(FileUtil.fileExists(m_filePath))
1103908dc91SLiu Zhe 		{	//load
1113908dc91SLiu Zhe 			m_xtextProps = load();
1123908dc91SLiu Zhe 		}
1133908dc91SLiu Zhe 		else{
1143908dc91SLiu Zhe 			//create a sd
1153908dc91SLiu Zhe 			m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress"));
1163908dc91SLiu Zhe 			Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
1173908dc91SLiu Zhe 			Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0);
1183908dc91SLiu Zhe 			XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
1193908dc91SLiu Zhe 			m_xtextProps = addPortion(xfirstTextBox, "test Build-in Bullet", false);
1203908dc91SLiu Zhe 		}
1213908dc91SLiu Zhe 	}
1223908dc91SLiu Zhe 
1233908dc91SLiu Zhe 	/**
1243908dc91SLiu Zhe 	 * @throws java.lang.Exception
1253908dc91SLiu Zhe 	 */
1263908dc91SLiu Zhe 	@After
tearDown()1273908dc91SLiu Zhe 	public void tearDown() throws Exception {
1283908dc91SLiu Zhe 		app.closeDocument(m_xSDComponent);
129*de51bb97SLi Feng Wang 		FileUtil.deleteFile(Testspace.getPath("temp"));
1303908dc91SLiu Zhe 	}
load()1313908dc91SLiu Zhe 	private XPropertySet load() throws Exception{
1323908dc91SLiu Zhe 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
1333908dc91SLiu Zhe 				app.loadDocument(m_filePath));
1343908dc91SLiu Zhe 		Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
1353908dc91SLiu Zhe 		Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0);
1363908dc91SLiu Zhe 		XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
1373908dc91SLiu Zhe 		return getPortion(xfirstTextBox, 0);
1383908dc91SLiu Zhe 	}
1393908dc91SLiu Zhe 
1403908dc91SLiu Zhe 	@Test
testBuildInBullet()1413908dc91SLiu Zhe 	public void testBuildInBullet() throws Exception {
1423908dc91SLiu Zhe 
1433908dc91SLiu Zhe 		Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
1443908dc91SLiu Zhe 
1453908dc91SLiu Zhe 		XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
1463908dc91SLiu Zhe 	             XIndexReplace.class, numberingrules);
1473908dc91SLiu Zhe 
1483908dc91SLiu Zhe 		PropertyValue[] props = new PropertyValue[2];
1493908dc91SLiu Zhe 	    props[0] = new PropertyValue();
1503908dc91SLiu Zhe 	    props[0].Name = "NumberingType";
1513908dc91SLiu Zhe 	    props[0].Value = new Short(NumberingType.CHAR_SPECIAL );
1523908dc91SLiu Zhe 
1533908dc91SLiu Zhe 	    props[1] = new PropertyValue();
1543908dc91SLiu Zhe 	    props[1].Name = "BulletChar";
1553908dc91SLiu Zhe 	    props[1].Value = this.m_BulletChar;
1563908dc91SLiu Zhe 
1573908dc91SLiu Zhe 	    //set numberingType
1583908dc91SLiu Zhe 	    xReplace.replaceByIndex(0, props);
1593908dc91SLiu Zhe 	    m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
1603908dc91SLiu Zhe 	  //set numbering level to 0
1613908dc91SLiu Zhe 	    m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0));
1623908dc91SLiu Zhe 
1633908dc91SLiu Zhe 		app.saveDocument(m_xSDComponent, m_filePath);
1643908dc91SLiu Zhe 		app.closeDocument(m_xSDComponent);
1653908dc91SLiu Zhe 		//reopen
1663908dc91SLiu Zhe 		m_xtextProps = load();
1673908dc91SLiu Zhe 
1683908dc91SLiu Zhe 		Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
1693908dc91SLiu Zhe 
1703908dc91SLiu Zhe 		XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
1713908dc91SLiu Zhe 	             XIndexReplace.class, numberingrules2);
1723908dc91SLiu Zhe 
1733908dc91SLiu Zhe 		PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
1743908dc91SLiu Zhe 		assertEquals("NumberingType should be CHAR_SPECIAL", NumberingType.CHAR_SPECIAL, proValues2[0].Value);
1753908dc91SLiu Zhe 		assertEquals("BulletChar should be"+m_expectedBulletChar, m_expectedBulletChar, proValues2[4].Value);
1763908dc91SLiu Zhe 	}
1773908dc91SLiu Zhe }
178