1*07d7dbdcSHerbert Dürr /************************************************************** 2*07d7dbdcSHerbert Dürr * 3*07d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 4*07d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 5*07d7dbdcSHerbert Dürr * distributed with this work for additional information 6*07d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 7*07d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 8*07d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 9*07d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 10*07d7dbdcSHerbert Dürr * 11*07d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 12*07d7dbdcSHerbert Dürr * 13*07d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 14*07d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 15*07d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*07d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 17*07d7dbdcSHerbert Dürr * specific language governing permissions and limitations 18*07d7dbdcSHerbert Dürr * under the License. 19*07d7dbdcSHerbert Dürr * 20*07d7dbdcSHerbert Dürr *************************************************************/ 21323ac9c5SLi Feng Wang /** 22323ac9c5SLi Feng Wang * check character style 23323ac9c5SLi Feng Wang * 1. new a impress 24323ac9c5SLi Feng Wang * 2. insert one line text in the first textbox 25323ac9c5SLi Feng Wang * 3. set the font color to red 26323ac9c5SLi Feng Wang * 4. save, close, reopen, then check the font color 27323ac9c5SLi Feng Wang * 5. set the underline to single 28323ac9c5SLi Feng Wang * 6. save, close, reopen, then check the underline 29323ac9c5SLi Feng Wang * 7. set the font size to 12 30323ac9c5SLi Feng Wang * 8. save, close, reopen, then check the font size 31323ac9c5SLi Feng Wang * 9. set font style to Bold, Italic 32323ac9c5SLi Feng Wang * 10. save, close, reopen, then check the font style 33323ac9c5SLi Feng Wang */ 34323ac9c5SLi Feng Wang package fvt.uno.sd.character; 35323ac9c5SLi Feng Wang 36323ac9c5SLi Feng Wang import static org.junit.Assert.*; 37323ac9c5SLi Feng Wang 38323ac9c5SLi Feng Wang import java.io.File; 39323ac9c5SLi Feng Wang import org.junit.After; 40323ac9c5SLi Feng Wang import org.junit.AfterClass; 41323ac9c5SLi Feng Wang import org.junit.Before; 42323ac9c5SLi Feng Wang import org.junit.BeforeClass; 43323ac9c5SLi Feng Wang import org.junit.Test; 44323ac9c5SLi Feng Wang import org.openoffice.test.common.FileUtil; 45323ac9c5SLi Feng Wang import org.openoffice.test.common.Testspace; 46323ac9c5SLi Feng Wang import org.openoffice.test.uno.UnoApp; 47323ac9c5SLi Feng Wang 48323ac9c5SLi Feng Wang import testlib.uno.SDUtil; 49323ac9c5SLi Feng Wang 50323ac9c5SLi Feng Wang import com.sun.star.beans.PropertyValue; 51323ac9c5SLi Feng Wang import com.sun.star.beans.XPropertySet; 52323ac9c5SLi Feng Wang import com.sun.star.container.XIndexAccess; 53323ac9c5SLi Feng Wang import com.sun.star.drawing.XDrawPage; 54323ac9c5SLi Feng Wang import com.sun.star.drawing.XDrawPages; 55323ac9c5SLi Feng Wang import com.sun.star.drawing.XDrawPagesSupplier; 56323ac9c5SLi Feng Wang import com.sun.star.drawing.XShapes; 57323ac9c5SLi Feng Wang import com.sun.star.frame.XStorable; 58323ac9c5SLi Feng Wang 59323ac9c5SLi Feng Wang import com.sun.star.lang.XComponent; 60323ac9c5SLi Feng Wang 61323ac9c5SLi Feng Wang import com.sun.star.text.XText; 62323ac9c5SLi Feng Wang import com.sun.star.uno.UnoRuntime; 63323ac9c5SLi Feng Wang 64323ac9c5SLi Feng Wang /** 65323ac9c5SLi Feng Wang * @author LouQL 66323ac9c5SLi Feng Wang * 67323ac9c5SLi Feng Wang */ 68323ac9c5SLi Feng Wang public class CheckCharacterStyle { 69323ac9c5SLi Feng Wang 70323ac9c5SLi Feng Wang private static final UnoApp app = new UnoApp(); 71323ac9c5SLi Feng Wang private XComponent m_xSDComponent = null; 72323ac9c5SLi Feng Wang private XText xShapeText = null; 73323ac9c5SLi Feng Wang private String filePath = null; 74323ac9c5SLi Feng Wang private XPropertySet xtextProps = null; 75323ac9c5SLi Feng Wang /** 76323ac9c5SLi Feng Wang * @throws java.lang.Exception 77323ac9c5SLi Feng Wang */ 78323ac9c5SLi Feng Wang @BeforeClass 79323ac9c5SLi Feng Wang public static void setUpConnection() throws Exception { 80323ac9c5SLi Feng Wang app.start(); 81323ac9c5SLi Feng Wang File temp = new File(Testspace.getPath("temp")); 82323ac9c5SLi Feng Wang temp.mkdirs(); 83323ac9c5SLi Feng Wang } 84323ac9c5SLi Feng Wang 85323ac9c5SLi Feng Wang @AfterClass 86323ac9c5SLi Feng Wang public static void tearDownConnection() throws Exception { 87323ac9c5SLi Feng Wang app.close(); 88323ac9c5SLi Feng Wang //remove the temp file 89323ac9c5SLi Feng Wang FileUtil.deleteFile(Testspace.getPath("temp")); 90323ac9c5SLi Feng Wang } 91323ac9c5SLi Feng Wang 92323ac9c5SLi Feng Wang /** 93323ac9c5SLi Feng Wang * @throws java.lang.Exception 94323ac9c5SLi Feng Wang */ 95323ac9c5SLi Feng Wang @Before 96323ac9c5SLi Feng Wang public void setUp() throws Exception { 97323ac9c5SLi Feng Wang filePath = Testspace.getPath("temp/CheckCharacterStyle.odt"); 98323ac9c5SLi Feng Wang if(FileUtil.fileExists(filePath)) 99323ac9c5SLi Feng Wang { //load 100323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 101323ac9c5SLi Feng Wang app.loadDocument(filePath)); 102323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 103323ac9c5SLi Feng Wang } 104323ac9c5SLi Feng Wang else{ 105323ac9c5SLi Feng Wang //create a sd 106323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); 107323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 108323ac9c5SLi Feng Wang xShapeText.setString("test"); 109323ac9c5SLi Feng Wang } 110323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 111323ac9c5SLi Feng Wang } 112323ac9c5SLi Feng Wang 113323ac9c5SLi Feng Wang private XText getFirstTextbox() throws Exception 114323ac9c5SLi Feng Wang { 115323ac9c5SLi Feng Wang Object firstPage = SDUtil.getPageByIndex(m_xSDComponent, 0); 116323ac9c5SLi Feng Wang Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 117323ac9c5SLi Feng Wang return (XText)UnoRuntime.queryInterface(XText.class, firstTextBox); 118323ac9c5SLi Feng Wang } 119323ac9c5SLi Feng Wang 120323ac9c5SLi Feng Wang /** 121323ac9c5SLi Feng Wang * @throws java.lang.Exception 122323ac9c5SLi Feng Wang */ 123323ac9c5SLi Feng Wang @After 124323ac9c5SLi Feng Wang public void tearDown() throws Exception { 125323ac9c5SLi Feng Wang //close odp after each test 126323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 127323ac9c5SLi Feng Wang } 128323ac9c5SLi Feng Wang 129323ac9c5SLi Feng Wang @Test 130323ac9c5SLi Feng Wang public void testFontColor() throws Exception{ 131323ac9c5SLi Feng Wang //set font color to red 132323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharColor", 0xFF0000); 133323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 134323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 135323ac9c5SLi Feng Wang //reopen 136323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 137323ac9c5SLi Feng Wang app.loadDocument(filePath)); 138323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 139323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 140323ac9c5SLi Feng Wang //check character styles 141323ac9c5SLi Feng Wang assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor")); 142323ac9c5SLi Feng Wang 143323ac9c5SLi Feng Wang } 144323ac9c5SLi Feng Wang @Test 145323ac9c5SLi Feng Wang public void testFontUnderline() throws Exception{ 146323ac9c5SLi Feng Wang //set font color to red 147323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE); 148323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 149323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 150323ac9c5SLi Feng Wang //reopen 151323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 152323ac9c5SLi Feng Wang app.loadDocument(filePath)); 153323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 154323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 155323ac9c5SLi Feng Wang //check character styles 156323ac9c5SLi Feng Wang assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline")); 157323ac9c5SLi Feng Wang } 158323ac9c5SLi Feng Wang 159323ac9c5SLi Feng Wang @Test 160323ac9c5SLi Feng Wang public void testFontSize() throws Exception{ 161323ac9c5SLi Feng Wang //set font color to red 162323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharHeight", 12); 163323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 164323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 165323ac9c5SLi Feng Wang //reopen 166323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 167323ac9c5SLi Feng Wang app.loadDocument(filePath)); 168323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 169323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 170323ac9c5SLi Feng Wang //check character styles 171323ac9c5SLi Feng Wang assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString()); 172323ac9c5SLi Feng Wang } 173323ac9c5SLi Feng Wang @Test 174323ac9c5SLi Feng Wang public void testFontBoldStyle() throws Exception { 175323ac9c5SLi Feng Wang //change the font style to Bold 176323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD); 177323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 178323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 179323ac9c5SLi Feng Wang //reopen 180323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 181323ac9c5SLi Feng Wang app.loadDocument(filePath)); 182323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 183323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 184323ac9c5SLi Feng Wang assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight")); 185323ac9c5SLi Feng Wang } 186323ac9c5SLi Feng Wang 187323ac9c5SLi Feng Wang @Test 188323ac9c5SLi Feng Wang public void testFontItalicStyle() throws Exception { 189323ac9c5SLi Feng Wang //change the font style to Bold 190323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC); 191323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 192323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 193323ac9c5SLi Feng Wang //reopen 194323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 195323ac9c5SLi Feng Wang app.loadDocument(filePath)); 196323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 197323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 198323ac9c5SLi Feng Wang assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture")); 199323ac9c5SLi Feng Wang } 200323ac9c5SLi Feng Wang } 201