Kaydet (Commit) 6aaad06e authored tarafından Liu Zhe's avatar Liu Zhe

#120631# - [testuno]Check the Build-In Bullet

Patch by: Lou Qing Le<louqingle@gmail.com>
Review by: Liu Zhe <aliuzhe@gmail.com>
üst 87e2b468
/**
* 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);
}
}
......@@ -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;
......
......@@ -57,7 +57,7 @@ public class SCUtil {
private static HashMap filterName = new HashMap();
public SCUtil() {
private SCUtil() {
}
......
......@@ -7,10 +7,7 @@ import com.sun.star.container.XIndexAccess;
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,29 +16,20 @@ 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);
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);
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);
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);
}
......
......@@ -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;
......@@ -119,6 +121,32 @@ public class ShapeUtil {
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
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment