1 /** 2 * check character style 3 * 1. new a impress 4 * 2. insert one line text in the first textbox 5 * 3. set the font color to red 6 * 4. save, close, reopen, then check the font color 7 * 5. set the underline to single 8 * 6. save, close, reopen, then check the underline 9 * 7. set the font size to 12 10 * 8. save, close, reopen, then check the font size 11 * 9. set font style to Bold, Italic 12 * 10. save, close, reopen, then check the font style 13 */ 14 package fvt.uno.sd.character; 15 16 import static org.junit.Assert.*; 17 18 import java.io.File; 19 import org.junit.After; 20 import org.junit.AfterClass; 21 import org.junit.Before; 22 import org.junit.BeforeClass; 23 import org.junit.Test; 24 import org.openoffice.test.common.FileUtil; 25 import org.openoffice.test.common.Testspace; 26 import org.openoffice.test.uno.UnoApp; 27 28 import testlib.uno.SDUtil; 29 30 import com.sun.star.beans.PropertyValue; 31 import com.sun.star.beans.XPropertySet; 32 import com.sun.star.container.XIndexAccess; 33 import com.sun.star.drawing.XDrawPage; 34 import com.sun.star.drawing.XDrawPages; 35 import com.sun.star.drawing.XDrawPagesSupplier; 36 import com.sun.star.drawing.XShapes; 37 import com.sun.star.frame.XStorable; 38 39 import com.sun.star.lang.XComponent; 40 41 import com.sun.star.text.XText; 42 import com.sun.star.uno.UnoRuntime; 43 44 /** 45 * @author LouQL 46 * 47 */ 48 public class CheckCharacterStyle { 49 50 private static final UnoApp app = new UnoApp(); 51 private XComponent m_xSDComponent = null; 52 private XText xShapeText = null; 53 private String filePath = null; 54 private XPropertySet xtextProps = null; 55 /** 56 * @throws java.lang.Exception 57 */ 58 @BeforeClass 59 public static void setUpConnection() throws Exception { 60 app.start(); 61 File temp = new File(Testspace.getPath("temp")); 62 temp.mkdirs(); 63 } 64 65 @AfterClass 66 public static void tearDownConnection() throws Exception { 67 app.close(); 68 //remove the temp file 69 FileUtil.deleteFile(Testspace.getPath("temp")); 70 } 71 72 /** 73 * @throws java.lang.Exception 74 */ 75 @Before 76 public void setUp() throws Exception { 77 filePath = Testspace.getPath("temp/CheckCharacterStyle.odt"); 78 if(FileUtil.fileExists(filePath)) 79 { //load 80 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 81 app.loadDocument(filePath)); 82 xShapeText = getFirstTextbox(); 83 } 84 else{ 85 //create a sd 86 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); 87 xShapeText = getFirstTextbox(); 88 xShapeText.setString("test"); 89 } 90 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 91 } 92 93 private XText getFirstTextbox() throws Exception 94 { 95 Object firstPage = SDUtil.getPageByIndex(m_xSDComponent, 0); 96 Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 97 return (XText)UnoRuntime.queryInterface(XText.class, firstTextBox); 98 } 99 100 /** 101 * @throws java.lang.Exception 102 */ 103 @After 104 public void tearDown() throws Exception { 105 //close odp after each test 106 m_xSDComponent.dispose(); 107 } 108 109 @Test 110 public void testFontColor() throws Exception{ 111 //set font color to red 112 xtextProps.setPropertyValue("CharColor", 0xFF0000); 113 app.saveDocument(m_xSDComponent, filePath); 114 m_xSDComponent.dispose(); 115 //reopen 116 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 117 app.loadDocument(filePath)); 118 xShapeText = getFirstTextbox(); 119 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 120 //check character styles 121 assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor")); 122 123 } 124 @Test 125 public void testFontUnderline() throws Exception{ 126 //set font color to red 127 xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE); 128 app.saveDocument(m_xSDComponent, filePath); 129 m_xSDComponent.dispose(); 130 //reopen 131 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 132 app.loadDocument(filePath)); 133 xShapeText = getFirstTextbox(); 134 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 135 //check character styles 136 assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline")); 137 } 138 139 @Test 140 public void testFontSize() throws Exception{ 141 //set font color to red 142 xtextProps.setPropertyValue("CharHeight", 12); 143 app.saveDocument(m_xSDComponent, filePath); 144 m_xSDComponent.dispose(); 145 //reopen 146 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 147 app.loadDocument(filePath)); 148 xShapeText = getFirstTextbox(); 149 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 150 //check character styles 151 assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString()); 152 } 153 @Test 154 public void testFontBoldStyle() throws Exception { 155 //change the font style to Bold 156 xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD); 157 app.saveDocument(m_xSDComponent, filePath); 158 m_xSDComponent.dispose(); 159 //reopen 160 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 161 app.loadDocument(filePath)); 162 xShapeText = getFirstTextbox(); 163 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 164 assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight")); 165 } 166 167 @Test 168 public void testFontItalicStyle() throws Exception { 169 //change the font style to Bold 170 xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC); 171 app.saveDocument(m_xSDComponent, filePath); 172 m_xSDComponent.dispose(); 173 //reopen 174 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 175 app.loadDocument(filePath)); 176 xShapeText = getFirstTextbox(); 177 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 178 assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture")); 179 } 180 } 181