107d7dbdcSHerbert Dürr /************************************************************** 207d7dbdcSHerbert Dürr * 307d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 407d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 507d7dbdcSHerbert Dürr * distributed with this work for additional information 607d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 707d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 807d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 907d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 1007d7dbdcSHerbert Dürr * 1107d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 1207d7dbdcSHerbert Dürr * 1307d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 1407d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 1507d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1607d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 1707d7dbdcSHerbert Dürr * specific language governing permissions and limitations 1807d7dbdcSHerbert Dürr * under the License. 1907d7dbdcSHerbert Dürr * 2007d7dbdcSHerbert 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.*; 37*28725c19SLi Feng Wang import static testlib.uno.SDUtil.saveFileAs; 38323ac9c5SLi Feng Wang 39323ac9c5SLi Feng Wang import java.io.File; 40323ac9c5SLi Feng Wang import org.junit.After; 41323ac9c5SLi Feng Wang import org.junit.AfterClass; 42323ac9c5SLi Feng Wang import org.junit.Before; 43323ac9c5SLi Feng Wang import org.junit.BeforeClass; 44323ac9c5SLi Feng Wang import org.junit.Test; 45323ac9c5SLi Feng Wang import org.openoffice.test.common.FileUtil; 46323ac9c5SLi Feng Wang import org.openoffice.test.common.Testspace; 47323ac9c5SLi Feng Wang import org.openoffice.test.uno.UnoApp; 48323ac9c5SLi Feng Wang 49323ac9c5SLi Feng Wang import testlib.uno.SDUtil; 50323ac9c5SLi Feng Wang 51323ac9c5SLi Feng Wang import com.sun.star.beans.PropertyValue; 52323ac9c5SLi Feng Wang import com.sun.star.beans.XPropertySet; 53323ac9c5SLi Feng Wang import com.sun.star.container.XIndexAccess; 54323ac9c5SLi Feng Wang import com.sun.star.drawing.XDrawPage; 55323ac9c5SLi Feng Wang import com.sun.star.drawing.XDrawPages; 56323ac9c5SLi Feng Wang import com.sun.star.drawing.XDrawPagesSupplier; 57323ac9c5SLi Feng Wang import com.sun.star.drawing.XShapes; 58323ac9c5SLi Feng Wang import com.sun.star.frame.XStorable; 59323ac9c5SLi Feng Wang 60323ac9c5SLi Feng Wang import com.sun.star.lang.XComponent; 61323ac9c5SLi Feng Wang 62323ac9c5SLi Feng Wang import com.sun.star.text.XText; 63323ac9c5SLi Feng Wang import com.sun.star.uno.UnoRuntime; 64323ac9c5SLi Feng Wang 65323ac9c5SLi Feng Wang /** 66323ac9c5SLi Feng Wang * @author LouQL 67323ac9c5SLi Feng Wang * 68323ac9c5SLi Feng Wang */ 69323ac9c5SLi Feng Wang public class CheckCharacterStyle { 70323ac9c5SLi Feng Wang 71323ac9c5SLi Feng Wang private static final UnoApp app = new UnoApp(); 72323ac9c5SLi Feng Wang private XComponent m_xSDComponent = null; 73323ac9c5SLi Feng Wang private XText xShapeText = null; 74323ac9c5SLi Feng Wang private String filePath = null; 75323ac9c5SLi Feng Wang private XPropertySet xtextProps = null; 76323ac9c5SLi Feng Wang /** 77323ac9c5SLi Feng Wang * @throws java.lang.Exception 78323ac9c5SLi Feng Wang */ 79323ac9c5SLi Feng Wang @BeforeClass setUpConnection()80323ac9c5SLi Feng Wang public static void setUpConnection() throws Exception { 81323ac9c5SLi Feng Wang app.start(); 82323ac9c5SLi Feng Wang File temp = new File(Testspace.getPath("temp")); 83323ac9c5SLi Feng Wang temp.mkdirs(); 84323ac9c5SLi Feng Wang } 85323ac9c5SLi Feng Wang 86323ac9c5SLi Feng Wang @AfterClass tearDownConnection()87323ac9c5SLi Feng Wang public static void tearDownConnection() throws Exception { 88323ac9c5SLi Feng Wang app.close(); 89*28725c19SLi Feng Wang 90323ac9c5SLi Feng Wang } 91323ac9c5SLi Feng Wang 92323ac9c5SLi Feng Wang /** 93323ac9c5SLi Feng Wang * @throws java.lang.Exception 94323ac9c5SLi Feng Wang */ 95323ac9c5SLi Feng Wang @Before setUp()96323ac9c5SLi Feng Wang public void setUp() throws Exception { 97*28725c19SLi Feng Wang filePath = Testspace.getPath("temp/CheckCharacterStyle.odp"); 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 getFirstTextbox()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 tearDown()124323ac9c5SLi Feng Wang public void tearDown() throws Exception { 125323ac9c5SLi Feng Wang //close odp after each test 126323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 127*28725c19SLi Feng Wang 128*28725c19SLi Feng Wang //remove the temp file 129*28725c19SLi Feng Wang FileUtil.deleteFile(Testspace.getPath("temp")); 130323ac9c5SLi Feng Wang } 131323ac9c5SLi Feng Wang 132323ac9c5SLi Feng Wang @Test testFontColor()133323ac9c5SLi Feng Wang public void testFontColor() throws Exception{ 134323ac9c5SLi Feng Wang //set font color to red 135323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharColor", 0xFF0000); 136*28725c19SLi Feng Wang // saveFileAs(m_xSDComponent, filePath, ".odp"); 137323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 138323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 139323ac9c5SLi Feng Wang //reopen 140323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 141323ac9c5SLi Feng Wang app.loadDocument(filePath)); 142323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 143323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 144323ac9c5SLi Feng Wang //check character styles 145323ac9c5SLi Feng Wang assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor")); 146323ac9c5SLi Feng Wang 147323ac9c5SLi Feng Wang } 148323ac9c5SLi Feng Wang @Test testFontUnderline()149323ac9c5SLi Feng Wang public void testFontUnderline() throws Exception{ 150323ac9c5SLi Feng Wang //set font color to red 151323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE); 152323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 153323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 154323ac9c5SLi Feng Wang //reopen 155323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 156323ac9c5SLi Feng Wang app.loadDocument(filePath)); 157323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 158323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 159323ac9c5SLi Feng Wang //check character styles 160323ac9c5SLi Feng Wang assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline")); 161323ac9c5SLi Feng Wang } 162323ac9c5SLi Feng Wang 163323ac9c5SLi Feng Wang @Test testFontSize()164323ac9c5SLi Feng Wang public void testFontSize() throws Exception{ 165323ac9c5SLi Feng Wang //set font color to red 166323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharHeight", 12); 167323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 168323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 169323ac9c5SLi Feng Wang //reopen 170323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 171323ac9c5SLi Feng Wang app.loadDocument(filePath)); 172323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 173323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 174323ac9c5SLi Feng Wang //check character styles 175323ac9c5SLi Feng Wang assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString()); 176323ac9c5SLi Feng Wang } 177323ac9c5SLi Feng Wang @Test testFontBoldStyle()178323ac9c5SLi Feng Wang public void testFontBoldStyle() throws Exception { 179323ac9c5SLi Feng Wang //change the font style to Bold 180323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD); 181323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 182323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 183323ac9c5SLi Feng Wang //reopen 184323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 185323ac9c5SLi Feng Wang app.loadDocument(filePath)); 186323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 187323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 188323ac9c5SLi Feng Wang assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight")); 189323ac9c5SLi Feng Wang } 190323ac9c5SLi Feng Wang 191323ac9c5SLi Feng Wang @Test testFontItalicStyle()192323ac9c5SLi Feng Wang public void testFontItalicStyle() throws Exception { 193323ac9c5SLi Feng Wang //change the font style to Bold 194323ac9c5SLi Feng Wang xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC); 195323ac9c5SLi Feng Wang app.saveDocument(m_xSDComponent, filePath); 196323ac9c5SLi Feng Wang m_xSDComponent.dispose(); 197323ac9c5SLi Feng Wang //reopen 198323ac9c5SLi Feng Wang m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 199323ac9c5SLi Feng Wang app.loadDocument(filePath)); 200323ac9c5SLi Feng Wang xShapeText = getFirstTextbox(); 201323ac9c5SLi Feng Wang xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 202323ac9c5SLi Feng Wang assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture")); 203323ac9c5SLi Feng Wang } 204323ac9c5SLi Feng Wang } 205