13908dc91SLiu Zhe /**
23908dc91SLiu Zhe  * There are 8 build-in bullets. Verify those bullets can be applied successfully.
33908dc91SLiu Zhe  * insert text into a SD
43908dc91SLiu Zhe  * apply the 8 bullets one by one, and check
53908dc91SLiu Zhe  */
6*323ac9c5SLi Feng Wang package fvt.uno.sd.bullet;
73908dc91SLiu Zhe 
83908dc91SLiu Zhe import static org.junit.Assert.assertEquals;
93908dc91SLiu Zhe import static testlib.uno.PageUtil.getDrawPageByIndex;
103908dc91SLiu Zhe import static testlib.uno.ShapeUtil.addPortion;
113908dc91SLiu Zhe import static testlib.uno.ShapeUtil.getPortion;
123908dc91SLiu Zhe 
133908dc91SLiu Zhe import java.io.File;
143908dc91SLiu Zhe import java.util.Arrays;
153908dc91SLiu Zhe import java.util.Collection;
163908dc91SLiu Zhe 
173908dc91SLiu Zhe import org.junit.After;
183908dc91SLiu Zhe import org.junit.AfterClass;
193908dc91SLiu Zhe import org.junit.Before;
203908dc91SLiu Zhe import org.junit.BeforeClass;
213908dc91SLiu Zhe import org.junit.Test;
223908dc91SLiu Zhe import org.junit.runner.RunWith;
233908dc91SLiu Zhe import org.junit.runners.Parameterized;
243908dc91SLiu Zhe import org.junit.runners.Parameterized.Parameters;
253908dc91SLiu Zhe import org.openoffice.test.common.FileUtil;
263908dc91SLiu Zhe import org.openoffice.test.common.Testspace;
273908dc91SLiu Zhe import org.openoffice.test.uno.UnoApp;
283908dc91SLiu Zhe 
293908dc91SLiu Zhe import testlib.uno.SDUtil;
303908dc91SLiu Zhe 
313908dc91SLiu Zhe import com.sun.star.beans.PropertyValue;
323908dc91SLiu Zhe import com.sun.star.beans.XPropertySet;
333908dc91SLiu Zhe import com.sun.star.container.XIndexReplace;
343908dc91SLiu Zhe import com.sun.star.drawing.XShape;
353908dc91SLiu Zhe import com.sun.star.lang.XComponent;
363908dc91SLiu Zhe import com.sun.star.style.NumberingType;
373908dc91SLiu Zhe import com.sun.star.uno.UnoRuntime;
383908dc91SLiu Zhe 
393908dc91SLiu Zhe 
403908dc91SLiu Zhe /**
413908dc91SLiu Zhe  * @author LouQL
423908dc91SLiu Zhe  *
433908dc91SLiu Zhe  */
443908dc91SLiu Zhe @RunWith(Parameterized.class)
453908dc91SLiu Zhe public class CheckBuildInBullet {
463908dc91SLiu Zhe 
473908dc91SLiu Zhe 	private static final UnoApp app = new UnoApp();
483908dc91SLiu Zhe 	private XComponent m_xSDComponent = null;
493908dc91SLiu Zhe 	private String m_filePath = null;
503908dc91SLiu Zhe 	private XPropertySet m_xtextProps = null;
513908dc91SLiu Zhe 	private String m_BulletChar = null;
523908dc91SLiu Zhe 	private String m_expectedBulletChar = null;
533908dc91SLiu Zhe 	/**
543908dc91SLiu Zhe 	 * @throws java.lang.Exception
553908dc91SLiu Zhe 	 */
563908dc91SLiu Zhe 
573908dc91SLiu Zhe 	public CheckBuildInBullet(String BulletChar, String expected) {
583908dc91SLiu Zhe         this.m_BulletChar = BulletChar;
593908dc91SLiu Zhe         m_expectedBulletChar = expected;
603908dc91SLiu Zhe     }
613908dc91SLiu Zhe 	@Parameters
623908dc91SLiu Zhe     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"}};
643908dc91SLiu Zhe         return Arrays.asList(bulletChar);
653908dc91SLiu Zhe     }
663908dc91SLiu Zhe 
673908dc91SLiu Zhe 	@BeforeClass
683908dc91SLiu Zhe 	public static void setUpBeforeClass() throws Exception {
693908dc91SLiu Zhe 		app.start();
703908dc91SLiu Zhe 		File temp = new File(Testspace.getPath("temp"));
713908dc91SLiu Zhe 		temp.mkdirs();
723908dc91SLiu Zhe 	}
733908dc91SLiu Zhe 
743908dc91SLiu Zhe 	/**
753908dc91SLiu Zhe 	 * @throws java.lang.Exception
763908dc91SLiu Zhe 	 */
773908dc91SLiu Zhe 	@AfterClass
783908dc91SLiu Zhe 	public static void tearDownAfterClass() throws Exception {
793908dc91SLiu Zhe 		app.close();
803908dc91SLiu Zhe 		//remove the temp file
813908dc91SLiu Zhe 		FileUtil.deleteFile(Testspace.getPath("temp"));
823908dc91SLiu Zhe 	}
833908dc91SLiu Zhe 
843908dc91SLiu Zhe 	/**
853908dc91SLiu Zhe 	 * @throws java.lang.Exception
863908dc91SLiu Zhe 	 */
873908dc91SLiu Zhe 	@Before
883908dc91SLiu Zhe 	public void setUp() throws Exception {
893908dc91SLiu Zhe 		m_filePath = Testspace.getPath("temp/CheckBuildInBullet.odt");
903908dc91SLiu Zhe //		m_filePath = "F:/aa.odp";
913908dc91SLiu Zhe 		if(FileUtil.fileExists(m_filePath))
923908dc91SLiu Zhe 		{	//load
933908dc91SLiu Zhe 			m_xtextProps = load();
943908dc91SLiu Zhe 		}
953908dc91SLiu Zhe 		else{
963908dc91SLiu Zhe 			//create a sd
973908dc91SLiu Zhe 			m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress"));
983908dc91SLiu Zhe 			Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
993908dc91SLiu Zhe 			Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0);
1003908dc91SLiu Zhe 			XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
1013908dc91SLiu Zhe 			m_xtextProps = addPortion(xfirstTextBox, "test Build-in Bullet", false);
1023908dc91SLiu Zhe 		}
1033908dc91SLiu Zhe 	}
1043908dc91SLiu Zhe 
1053908dc91SLiu Zhe 	/**
1063908dc91SLiu Zhe 	 * @throws java.lang.Exception
1073908dc91SLiu Zhe 	 */
1083908dc91SLiu Zhe 	@After
1093908dc91SLiu Zhe 	public void tearDown() throws Exception {
1103908dc91SLiu Zhe 		app.closeDocument(m_xSDComponent);
1113908dc91SLiu Zhe 	}
1123908dc91SLiu Zhe 	private XPropertySet load() throws Exception{
1133908dc91SLiu Zhe 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
1143908dc91SLiu Zhe 				app.loadDocument(m_filePath));
1153908dc91SLiu Zhe 		Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
1163908dc91SLiu Zhe 		Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0);
1173908dc91SLiu Zhe 		XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
1183908dc91SLiu Zhe 		return getPortion(xfirstTextBox, 0);
1193908dc91SLiu Zhe 	}
1203908dc91SLiu Zhe 
1213908dc91SLiu Zhe 	@Test
1223908dc91SLiu Zhe 	public void testBuildInBullet() throws Exception {
1233908dc91SLiu Zhe 
1243908dc91SLiu Zhe 		Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
1253908dc91SLiu Zhe 
1263908dc91SLiu Zhe 		XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
1273908dc91SLiu Zhe 	             XIndexReplace.class, numberingrules);
1283908dc91SLiu Zhe 
1293908dc91SLiu Zhe 		PropertyValue[] props = new PropertyValue[2];
1303908dc91SLiu Zhe 	    props[0] = new PropertyValue();
1313908dc91SLiu Zhe 	    props[0].Name = "NumberingType";
1323908dc91SLiu Zhe 	    props[0].Value = new Short(NumberingType.CHAR_SPECIAL );
1333908dc91SLiu Zhe 
1343908dc91SLiu Zhe 	    props[1] = new PropertyValue();
1353908dc91SLiu Zhe 	    props[1].Name = "BulletChar";
1363908dc91SLiu Zhe 	    props[1].Value = this.m_BulletChar;
1373908dc91SLiu Zhe 
1383908dc91SLiu Zhe 	    //set numberingType
1393908dc91SLiu Zhe 	    xReplace.replaceByIndex(0, props);
1403908dc91SLiu Zhe 	    m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
1413908dc91SLiu Zhe 	  //set numbering level to 0
1423908dc91SLiu Zhe 	    m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0));
1433908dc91SLiu Zhe 
1443908dc91SLiu Zhe 		app.saveDocument(m_xSDComponent, m_filePath);
1453908dc91SLiu Zhe 		app.closeDocument(m_xSDComponent);
1463908dc91SLiu Zhe 		//reopen
1473908dc91SLiu Zhe 		m_xtextProps = load();
1483908dc91SLiu Zhe 
1493908dc91SLiu Zhe 		Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
1503908dc91SLiu Zhe 
1513908dc91SLiu Zhe 		XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
1523908dc91SLiu Zhe 	             XIndexReplace.class, numberingrules2);
1533908dc91SLiu Zhe 
1543908dc91SLiu Zhe 		PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
1553908dc91SLiu Zhe 		assertEquals("NumberingType should be CHAR_SPECIAL", NumberingType.CHAR_SPECIAL, proValues2[0].Value);
1563908dc91SLiu Zhe 		assertEquals("BulletChar should be"+m_expectedBulletChar, m_expectedBulletChar, proValues2[4].Value);
1573908dc91SLiu Zhe 	}
1583908dc91SLiu Zhe }
159