--- org/openoffice/test/uno/UnoApp.java (revision 1373681) +++ org/openoffice/test/uno/UnoApp.java (working copy) @@ -21,6 +21,7 @@ package org.openoffice.test.uno; +import java.io.File; import java.util.Timer; import java.util.TimerTask; @@ -34,6 +35,7 @@ import com.sun.star.comp.helper.Bootstrap; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XDesktop; +import com.sun.star.frame.XStorable; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XMultiServiceFactory; @@ -150,6 +152,12 @@ return componentLoader.loadComponentFromURL("private:factory/" + type, "_blank", 0, new PropertyValue[0]); } + public void SaveDocument(XComponent doc, String toPath) throws Exception { + XStorable m_xstorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, doc); + String fileUrl = FileUtil.getUrl(new File(toPath)); + m_xstorable.storeAsURL(fileUrl, new PropertyValue[0]); + } + public void closeDocument(XComponent doc) { try { XModifiable modified = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, doc); --- testcase/uno/sd/CheckCharacterStyle.java (revision 0) +++ testcase/uno/sd/CheckCharacterStyle.java (working copy) @@ -0,0 +1,181 @@ +/** + * check character style + * 1. new a impress + * 2. insert one line text in the first textbox + * 3. set the font color to red + * 4. save, close, reopen, then check the font color + * 5. set the underline to single + * 6. save, close, reopen, then check the underline + * 7. set the font size to 12 + * 8. save, close, reopen, then check the font size + * 9. set font style to Bold, Italic + * 10. save, close, reopen, then check the font style + */ +package testcase.uno.sd; + +import static org.junit.Assert.*; + +import java.io.File; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.common.FileUtil; +import org.openoffice.test.common.Testspace; +import org.openoffice.test.uno.UnoApp; + +import testlib.uno.SDUnoUtil; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XIndexAccess; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.drawing.XShapes; +import com.sun.star.frame.XStorable; + +import com.sun.star.lang.XComponent; + +import com.sun.star.text.XText; +import com.sun.star.uno.UnoRuntime; + +/** + * @author LouQL + * + */ +public class CheckCharacterStyle { + + private static final UnoApp app = new UnoApp(); + private static final SDUnoUtil SDUtil = new SDUnoUtil(); + private XComponent m_xSDComponent = null; + private XText xShapeText = null; + private String filePath = null; + private XPropertySet xtextProps = null; + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpConnection() throws Exception { + app.start(); + File temp = new File(Testspace.getPath("temp")); + temp.mkdirs(); + } + + @AfterClass + public static void tearDownConnection() throws Exception { + app.close(); + //remove the temp file + FileUtil.deleteFile(Testspace.getPath("temp")); + } + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + filePath = Testspace.getPath("temp/CheckCharacterStyle.odt"); + if(FileUtil.fileExists(filePath)) + { //load + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, + app.loadDocument(filePath)); + xShapeText = getFirstTextbox(); + } + else{ + //create a sd + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); + xShapeText = getFirstTextbox(); + xShapeText.setString("test"); + } + xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); + } + + private XText getFirstTextbox() throws Exception + { + Object firstPage = SDUtil.getPageByIndex(m_xSDComponent, 0); + Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); + return (XText)UnoRuntime.queryInterface(XText.class, firstTextBox); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + //close odp after each test + m_xSDComponent.dispose(); + } + + @Test + public void testFontColor() throws Exception{ + //set font color to red + xtextProps.setPropertyValue("CharColor", 0xFF0000); + app.SaveDocument(m_xSDComponent, filePath); + m_xSDComponent.dispose(); + //reopen + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, + app.loadDocument(filePath)); + xShapeText = getFirstTextbox(); + xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); + //check character styles + assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor")); + + } + @Test + public void testFontUnderline() throws Exception{ + //set font color to red + xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE); + app.SaveDocument(m_xSDComponent, filePath); + m_xSDComponent.dispose(); + //reopen + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, + app.loadDocument(filePath)); + xShapeText = getFirstTextbox(); + xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); + //check character styles + assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline")); + } + + @Test + public void testFontSize() throws Exception{ + //set font color to red + xtextProps.setPropertyValue("CharHeight", 12); + app.SaveDocument(m_xSDComponent, filePath); + m_xSDComponent.dispose(); + //reopen + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, + app.loadDocument(filePath)); + xShapeText = getFirstTextbox(); + xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); + //check character styles + assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString()); + } + @Test + public void testFontBoldStyle() throws Exception { + //change the font style to Bold + xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD); + app.SaveDocument(m_xSDComponent, filePath); + m_xSDComponent.dispose(); + //reopen + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, + app.loadDocument(filePath)); + xShapeText = getFirstTextbox(); + xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); + assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight")); + } + + @Test + public void testFontItalicStyle() throws Exception { + //change the font style to Bold + xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC); + app.SaveDocument(m_xSDComponent, filePath); + m_xSDComponent.dispose(); + //reopen + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, + app.loadDocument(filePath)); + xShapeText = getFirstTextbox(); + xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); + assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture")); + } +} --- testlib/uno/SDUnoUtil.java (revision 0) +++ testlib/uno/SDUnoUtil.java (working copy) @@ -0,0 +1,48 @@ +/** + * + */ +package testlib.uno; + +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; + +/** + * + * + */ +public class SDUnoUtil { + + /** + * @throws WrappedTargetException + * @throws + * @throws java.lang.Exception + */ + public SDUnoUtil(){ + + } + + 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 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); + } + +}