1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 /** 22 * check character style 23 * 1. new a impress 24 * 2. insert one line text in the first textbox 25 * 3. set the font color to red 26 * 4. save, close, reopen, then check the font color 27 * 5. set the underline to single 28 * 6. save, close, reopen, then check the underline 29 * 7. set the font size to 12 30 * 8. save, close, reopen, then check the font size 31 * 9. set font style to Bold, Italic 32 * 10. save, close, reopen, then check the font style 33 */ 34 package fvt.uno.sd.character; 35 36 import static org.junit.Assert.*; 37 import static testlib.uno.SDUtil.saveFileAs; 38 39 import java.io.File; 40 import org.junit.After; 41 import org.junit.AfterClass; 42 import org.junit.Before; 43 import org.junit.BeforeClass; 44 import org.junit.Test; 45 import org.openoffice.test.common.FileUtil; 46 import org.openoffice.test.common.Testspace; 47 import org.openoffice.test.uno.UnoApp; 48 49 import testlib.uno.SDUtil; 50 51 import com.sun.star.beans.PropertyValue; 52 import com.sun.star.beans.XPropertySet; 53 import com.sun.star.container.XIndexAccess; 54 import com.sun.star.drawing.XDrawPage; 55 import com.sun.star.drawing.XDrawPages; 56 import com.sun.star.drawing.XDrawPagesSupplier; 57 import com.sun.star.drawing.XShapes; 58 import com.sun.star.frame.XStorable; 59 60 import com.sun.star.lang.XComponent; 61 62 import com.sun.star.text.XText; 63 import com.sun.star.uno.UnoRuntime; 64 65 /** 66 * @author LouQL 67 * 68 */ 69 public class CheckCharacterStyle { 70 71 private static final UnoApp app = new UnoApp(); 72 private XComponent m_xSDComponent = null; 73 private XText xShapeText = null; 74 private String filePath = null; 75 private XPropertySet xtextProps = null; 76 /** 77 * @throws java.lang.Exception 78 */ 79 @BeforeClass setUpConnection()80 public static void setUpConnection() throws Exception { 81 app.start(); 82 File temp = new File(Testspace.getPath("temp")); 83 temp.mkdirs(); 84 } 85 86 @AfterClass tearDownConnection()87 public static void tearDownConnection() throws Exception { 88 app.close(); 89 90 } 91 92 /** 93 * @throws java.lang.Exception 94 */ 95 @Before setUp()96 public void setUp() throws Exception { 97 filePath = Testspace.getPath("temp/CheckCharacterStyle.odp"); 98 if(FileUtil.fileExists(filePath)) 99 { //load 100 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 101 app.loadDocument(filePath)); 102 xShapeText = getFirstTextbox(); 103 } 104 else{ 105 //create a sd 106 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); 107 xShapeText = getFirstTextbox(); 108 xShapeText.setString("test"); 109 } 110 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 111 } 112 getFirstTextbox()113 private XText getFirstTextbox() throws Exception 114 { 115 Object firstPage = SDUtil.getPageByIndex(m_xSDComponent, 0); 116 Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 117 return (XText)UnoRuntime.queryInterface(XText.class, firstTextBox); 118 } 119 120 /** 121 * @throws java.lang.Exception 122 */ 123 @After tearDown()124 public void tearDown() throws Exception { 125 //close odp after each test 126 m_xSDComponent.dispose(); 127 128 //remove the temp file 129 FileUtil.deleteFile(Testspace.getPath("temp")); 130 } 131 132 @Test testFontColor()133 public void testFontColor() throws Exception{ 134 //set font color to red 135 xtextProps.setPropertyValue("CharColor", 0xFF0000); 136 // saveFileAs(m_xSDComponent, filePath, ".odp"); 137 app.saveDocument(m_xSDComponent, filePath); 138 m_xSDComponent.dispose(); 139 //reopen 140 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 141 app.loadDocument(filePath)); 142 xShapeText = getFirstTextbox(); 143 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 144 //check character styles 145 assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor")); 146 147 } 148 @Test testFontUnderline()149 public void testFontUnderline() throws Exception{ 150 //set font color to red 151 xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE); 152 app.saveDocument(m_xSDComponent, filePath); 153 m_xSDComponent.dispose(); 154 //reopen 155 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 156 app.loadDocument(filePath)); 157 xShapeText = getFirstTextbox(); 158 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 159 //check character styles 160 assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline")); 161 } 162 163 @Test testFontSize()164 public void testFontSize() throws Exception{ 165 //set font color to red 166 xtextProps.setPropertyValue("CharHeight", 12); 167 app.saveDocument(m_xSDComponent, filePath); 168 m_xSDComponent.dispose(); 169 //reopen 170 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 171 app.loadDocument(filePath)); 172 xShapeText = getFirstTextbox(); 173 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 174 //check character styles 175 assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString()); 176 } 177 @Test testFontBoldStyle()178 public void testFontBoldStyle() throws Exception { 179 //change the font style to Bold 180 xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD); 181 app.saveDocument(m_xSDComponent, filePath); 182 m_xSDComponent.dispose(); 183 //reopen 184 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 185 app.loadDocument(filePath)); 186 xShapeText = getFirstTextbox(); 187 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 188 assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight")); 189 } 190 191 @Test testFontItalicStyle()192 public void testFontItalicStyle() throws Exception { 193 //change the font style to Bold 194 xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC); 195 app.saveDocument(m_xSDComponent, filePath); 196 m_xSDComponent.dispose(); 197 //reopen 198 m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 199 app.loadDocument(filePath)); 200 xShapeText = getFirstTextbox(); 201 xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 202 assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture")); 203 } 204 } 205