Author: liuzhe
Date: Tue Aug 21 06:47:41 2012
New Revision: 1375397
URL: http://svn.apache.org/viewvc?rev=1375397&view=rev
Log:
#120631# - [testuno]Check the Build-In Bullet
Patch by: Lou Qing Le<[email protected]>
Review by: Liu Zhe <[email protected]>
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckBuildInBullet.java
Modified:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java
incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java
incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java
incubator/ooo/trunk/main/test/testuno/source/testlib/uno/ShapeUtil.java
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckBuildInBullet.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckBuildInBullet.java?rev=1375397&view=auto
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckBuildInBullet.java
(added)
+++
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckBuildInBullet.java
Tue Aug 21 06:47:41 2012
@@ -0,0 +1,158 @@
+/**
+ * There are 8 build-in bullets. Verify those bullets can be applied
successfully.
+ * insert text into a SD
+ * apply the 8 bullets one by one, and check
+ */
+package testcase.uno.sd;
+
+import static org.junit.Assert.assertEquals;
+import static testlib.uno.PageUtil.getDrawPageByIndex;
+import static testlib.uno.ShapeUtil.addPortion;
+import static testlib.uno.ShapeUtil.getPortion;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+
+import testlib.uno.SDUtil;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XIndexReplace;
+import com.sun.star.drawing.XShape;
+import com.sun.star.lang.XComponent;
+import com.sun.star.style.NumberingType;
+import com.sun.star.uno.UnoRuntime;
+
+
+/**
+ * @author LouQL
+ *
+ */
+@RunWith(Parameterized.class)
+public class CheckBuildInBullet {
+
+ private static final UnoApp app = new UnoApp();
+ private XComponent m_xSDComponent = null;
+ private String m_filePath = null;
+ private XPropertySet m_xtextProps = null;
+ private String m_BulletChar = null;
+ private String m_expectedBulletChar = null;
+ /**
+ * @throws java.lang.Exception
+ */
+
+ public CheckBuildInBullet(String BulletChar, String expected) {
+ this.m_BulletChar = BulletChar;
+ m_expectedBulletChar = expected;
+ }
+ @Parameters
+ public static Collection<String[]> data() {
+ String[][] bulletChar = new String[][] {{"â","â"}, {"â¢","â¢"},
{"î","î"},{"î","î"},{"â","â"}, {"â¢","â¢"},
{"â","â"},{"â","â"}};
+ return Arrays.asList(bulletChar);
+ }
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ app.start();
+ File temp = new File(Testspace.getPath("temp"));
+ temp.mkdirs();
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ app.close();
+ //remove the temp file
+ FileUtil.deleteFile(Testspace.getPath("temp"));
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ m_filePath = Testspace.getPath("temp/CheckBuildInBullet.odt");
+// m_filePath = "F:/aa.odp";
+ if(FileUtil.fileExists(m_filePath))
+ { //load
+ m_xtextProps = load();
+ }
+ else{
+ //create a sd
+ m_xSDComponent = (XComponent)
UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress"));
+ Object firstPage = getDrawPageByIndex(m_xSDComponent,
0);
+ Object firstTextBox =
SDUtil.getShapeOfPageByIndex(firstPage, 0);
+ XShape xfirstTextBox =
(XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
+ m_xtextProps = addPortion(xfirstTextBox, "test Build-in
Bullet", false);
+ }
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ app.closeDocument(m_xSDComponent);
+ }
+ private XPropertySet load() throws Exception{
+ m_xSDComponent = (XComponent)
UnoRuntime.queryInterface(XComponent.class,
+ app.loadDocument(m_filePath));
+ Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
+ Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage,
0);
+ XShape xfirstTextBox =
(XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
+ return getPortion(xfirstTextBox, 0);
+ }
+
+ @Test
+ public void testBuildInBullet() throws Exception {
+
+ Object numberingrules =
m_xtextProps.getPropertyValue("NumberingRules");
+
+ XIndexReplace xReplace = (XIndexReplace)
UnoRuntime.queryInterface(
+ XIndexReplace.class, numberingrules);
+
+ PropertyValue[] props = new PropertyValue[2];
+ props[0] = new PropertyValue();
+ props[0].Name = "NumberingType";
+ props[0].Value = new Short(NumberingType.CHAR_SPECIAL );
+
+ props[1] = new PropertyValue();
+ props[1].Name = "BulletChar";
+ props[1].Value = this.m_BulletChar;
+
+ //set numberingType
+ xReplace.replaceByIndex(0, props);
+ m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
+ //set numbering level to 0
+ m_xtextProps.setPropertyValue("NumberingLevel", new
Short((short)0));
+
+ app.saveDocument(m_xSDComponent, m_filePath);
+ app.closeDocument(m_xSDComponent);
+ //reopen
+ m_xtextProps = load();
+
+ Object numberingrules2 =
m_xtextProps.getPropertyValue("NumberingRules");
+
+ XIndexReplace xReplace2 = (XIndexReplace)
UnoRuntime.queryInterface(
+ XIndexReplace.class, numberingrules2);
+
+ PropertyValue[] proValues2 =
(PropertyValue[])xReplace2.getByIndex(0);
+ assertEquals("NumberingType should be CHAR_SPECIAL",
NumberingType.CHAR_SPECIAL, proValues2[0].Value);
+ assertEquals("BulletChar should be"+m_expectedBulletChar,
m_expectedBulletChar, proValues2[4].Value);
+ }
+}
Modified:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java?rev=1375397&r1=1375396&r2=1375397&view=diff
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java
(original)
+++
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sd/CheckCharacterStyle.java
Tue Aug 21 06:47:41 2012
@@ -48,7 +48,6 @@ import com.sun.star.uno.UnoRuntime;
public class CheckCharacterStyle {
private static final UnoApp app = new UnoApp();
- private static final SDUtil SDUtil = new SDUtil();
private XComponent m_xSDComponent = null;
private XText xShapeText = null;
private String filePath = null;
Modified: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java?rev=1375397&r1=1375396&r2=1375397&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java
(original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java Tue
Aug 21 06:47:41 2012
@@ -57,7 +57,7 @@ public class SCUtil {
private static HashMap filterName = new HashMap();
- public SCUtil() {
+ private SCUtil() {
}
Modified: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java?rev=1375397&r1=1375396&r2=1375397&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java
(original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java Tue
Aug 21 06:47:41 2012
@@ -7,10 +7,7 @@ import com.sun.star.container.XIndexAcce
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.drawing.XShapes;
-import com.sun.star.lang.IndexOutOfBoundsException;
-import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XComponent;
-import com.sun.star.text.XText;
import com.sun.star.uno.UnoRuntime;
/**
@@ -19,30 +16,21 @@ import com.sun.star.uno.UnoRuntime;
*/
public class SDUtil {
- /**
- * @throws WrappedTargetException
- * @throws
- * @throws java.lang.Exception
- */
- public SDUtil(){
-
+ private SDUtil() {
+
}
-
- public Object getPageByIndex(XComponent doc, int index) throws
Exception{
- XDrawPagesSupplier xDrawPagesSupplier =
- (XDrawPagesSupplier)UnoRuntime.queryInterface(
- XDrawPagesSupplier.class, doc);
-
- Object drawPages = xDrawPagesSupplier.getDrawPages();
- XIndexAccess xIndexedDrawPages =
(XIndexAccess)UnoRuntime.queryInterface(
- XIndexAccess.class, drawPages);
- return xIndexedDrawPages.getByIndex(index);
+
+ public static Object getPageByIndex(XComponent doc, int index) throws
Exception {
+ XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier)
UnoRuntime.queryInterface(XDrawPagesSupplier.class, doc);
+ Object drawPages = xDrawPagesSupplier.getDrawPages();
+ XIndexAccess xIndexedDrawPages = (XIndexAccess)
UnoRuntime.queryInterface(XIndexAccess.class, drawPages);
+ return xIndexedDrawPages.getByIndex(index);
}
-
- public Object getShapeOfPageByIndex(Object page, int index) throws
Exception{
- XDrawPage xDrawPage =
(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, page);
- XShapes m_xdrawShapes =
(XShapes)UnoRuntime.queryInterface(XShapes.class, xDrawPage);
- return m_xdrawShapes.getByIndex(index);
+
+ public static Object getShapeOfPageByIndex(Object page, int index)
throws Exception {
+ XDrawPage xDrawPage = (XDrawPage)
UnoRuntime.queryInterface(XDrawPage.class, page);
+ XShapes m_xdrawShapes = (XShapes)
UnoRuntime.queryInterface(XShapes.class, xDrawPage);
+ return m_xdrawShapes.getByIndex(index);
}
}
Modified:
incubator/ooo/trunk/main/test/testuno/source/testlib/uno/ShapeUtil.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/ShapeUtil.java?rev=1375397&r1=1375396&r2=1375397&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/ShapeUtil.java
(original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/ShapeUtil.java Tue
Aug 21 06:47:41 2012
@@ -25,6 +25,7 @@ package testlib.uno;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
@@ -33,6 +34,7 @@ import com.sun.star.awt.Size;
import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XEnumerationAccess;
@@ -118,6 +120,32 @@ public class ShapeUtil {
XPropertySet.class, xTextRange);
return xPropSet;
}
+
+ /**
+ * get a paragraph in a shape. the return value is the PropertySet of
the text
+ * range that specified by the index
+ */
+ public static XPropertySet getPortion(XShape xShape, int index) throws
NoSuchElementException, WrappedTargetException {
+ XEnumerationAccess m_paraAccess =
(XEnumerationAccess)UnoRuntime.queryInterface(XEnumerationAccess.class, xShape);
+ XEnumeration xParaEnum = m_paraAccess.createEnumeration();
+ XPropertySet xPropSet = null;
+ int i=0;
+ while(xParaEnum.hasMoreElements())
+ {
+ if(i == index)
+ {
+ Object aPortionObj = xParaEnum.nextElement();
+ XTextRange xTextRange =
(XTextRange)UnoRuntime.queryInterface(XTextRange.class, aPortionObj);
+//
System.out.println(xTextRange.getText().getString());
+ xPropSet = (XPropertySet)
UnoRuntime.queryInterface(
+ XPropertySet.class, xTextRange);
+ break;
+ }
+ else i++;
+ }
+ return xPropSet;
+ }
+
/**
* try to get text of a shape