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 *************************************************************/ 212d72893bSLiu Zhe /** 222d72893bSLiu Zhe * check character style 232d72893bSLiu Zhe * 1. new a impress 242d72893bSLiu Zhe * 2. insert one line text in the first textbox 252d72893bSLiu Zhe * 3. set the font color to red 262d72893bSLiu Zhe * 4. save, close, reopen, then check the font color 272d72893bSLiu Zhe * 5. set the underline to single 282d72893bSLiu Zhe * 6. save, close, reopen, then check the underline 292d72893bSLiu Zhe * 7. set the font size to 12 302d72893bSLiu Zhe * 8. save, close, reopen, then check the font size 312d72893bSLiu Zhe * 9. set font style to Bold, Italic 322d72893bSLiu Zhe * 10. save, close, reopen, then check the font style 332d72893bSLiu Zhe */ 34323ac9c5SLi Feng Wang package fvt.uno.sd.character; 352d72893bSLiu Zhe 362d72893bSLiu Zhe import static org.junit.Assert.*; 372d72893bSLiu Zhe 382d72893bSLiu Zhe import java.io.File; 392d72893bSLiu Zhe import org.junit.After; 402d72893bSLiu Zhe import org.junit.AfterClass; 412d72893bSLiu Zhe import org.junit.Before; 422d72893bSLiu Zhe import org.junit.BeforeClass; 432d72893bSLiu Zhe import org.junit.Test; 442d72893bSLiu Zhe import org.openoffice.test.common.FileUtil; 452d72893bSLiu Zhe import org.openoffice.test.common.Testspace; 462d72893bSLiu Zhe import org.openoffice.test.uno.UnoApp; 472d72893bSLiu Zhe 48f0480a3dSLiu Zhe import testlib.uno.SDUtil; 492d72893bSLiu Zhe 502d72893bSLiu Zhe import com.sun.star.beans.PropertyValue; 512d72893bSLiu Zhe import com.sun.star.beans.XPropertySet; 522d72893bSLiu Zhe import com.sun.star.container.XIndexAccess; 532d72893bSLiu Zhe import com.sun.star.drawing.XDrawPage; 542d72893bSLiu Zhe import com.sun.star.drawing.XDrawPages; 552d72893bSLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier; 562d72893bSLiu Zhe import com.sun.star.drawing.XShapes; 572d72893bSLiu Zhe import com.sun.star.frame.XStorable; 582d72893bSLiu Zhe 592d72893bSLiu Zhe import com.sun.star.lang.XComponent; 602d72893bSLiu Zhe 612d72893bSLiu Zhe import com.sun.star.text.XText; 622d72893bSLiu Zhe import com.sun.star.uno.UnoRuntime; 632d72893bSLiu Zhe 642d72893bSLiu Zhe /** 652d72893bSLiu Zhe * @author LouQL 662d72893bSLiu Zhe * 672d72893bSLiu Zhe */ 682d72893bSLiu Zhe public class CheckCharacterStyle { 692d72893bSLiu Zhe 702d72893bSLiu Zhe private static final UnoApp app = new UnoApp(); 712d72893bSLiu Zhe private XComponent m_xSDComponent = null; 722d72893bSLiu Zhe private XText xShapeText = null; 732d72893bSLiu Zhe private String filePath = null; 742d72893bSLiu Zhe private XPropertySet xtextProps = null; 752d72893bSLiu Zhe /** 762d72893bSLiu Zhe * @throws java.lang.Exception 772d72893bSLiu Zhe */ 782d72893bSLiu Zhe @BeforeClass 792d72893bSLiu Zhe public static void setUpConnection() throws Exception { 802d72893bSLiu Zhe app.start(); 812d72893bSLiu Zhe File temp = new File(Testspace.getPath("temp")); 822d72893bSLiu Zhe temp.mkdirs(); 832d72893bSLiu Zhe } 842d72893bSLiu Zhe 852d72893bSLiu Zhe @AfterClass 862d72893bSLiu Zhe public static void tearDownConnection() throws Exception { 872d72893bSLiu Zhe app.close(); 882d72893bSLiu Zhe //remove the temp file 892d72893bSLiu Zhe FileUtil.deleteFile(Testspace.getPath("temp")); 902d72893bSLiu Zhe } 912d72893bSLiu Zhe 922d72893bSLiu Zhe /** 932d72893bSLiu Zhe * @throws java.lang.Exception 942d72893bSLiu Zhe */ 952d72893bSLiu Zhe @Before 962d72893bSLiu Zhe public void setUp() throws Exception { 972d72893bSLiu Zhe filePath = Testspace.getPath("temp/CheckCharacterStyle.odt"); 982d72893bSLiu Zhe if(FileUtil.fileExists(filePath)) 992d72893bSLiu Zhe { //load 1002d72893bSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 1012d72893bSLiu Zhe app.loadDocument(filePath)); 1022d72893bSLiu Zhe xShapeText = getFirstTextbox(); 1032d72893bSLiu Zhe } 1042d72893bSLiu Zhe else{ 1052d72893bSLiu Zhe //create a sd 1062d72893bSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); 1072d72893bSLiu Zhe xShapeText = getFirstTextbox(); 1082d72893bSLiu Zhe xShapeText.setString("test"); 1092d72893bSLiu Zhe } 1102d72893bSLiu Zhe xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 1112d72893bSLiu Zhe } 1122d72893bSLiu Zhe 1132d72893bSLiu Zhe private XText getFirstTextbox() throws Exception 1142d72893bSLiu Zhe { 1152d72893bSLiu Zhe Object firstPage = SDUtil.getPageByIndex(m_xSDComponent, 0); 1162d72893bSLiu Zhe Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); 1172d72893bSLiu Zhe return (XText)UnoRuntime.queryInterface(XText.class, firstTextBox); 1182d72893bSLiu Zhe } 1192d72893bSLiu Zhe 1202d72893bSLiu Zhe /** 1212d72893bSLiu Zhe * @throws java.lang.Exception 1222d72893bSLiu Zhe */ 1232d72893bSLiu Zhe @After 1242d72893bSLiu Zhe public void tearDown() throws Exception { 1252d72893bSLiu Zhe //close odp after each test 1262d72893bSLiu Zhe m_xSDComponent.dispose(); 1272d72893bSLiu Zhe } 1282d72893bSLiu Zhe 1292d72893bSLiu Zhe @Test 1302d72893bSLiu Zhe public void testFontColor() throws Exception{ 1312d72893bSLiu Zhe //set font color to red 1322d72893bSLiu Zhe xtextProps.setPropertyValue("CharColor", 0xFF0000); 1332d72893bSLiu Zhe app.saveDocument(m_xSDComponent, filePath); 1342d72893bSLiu Zhe m_xSDComponent.dispose(); 1352d72893bSLiu Zhe //reopen 1362d72893bSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 1372d72893bSLiu Zhe app.loadDocument(filePath)); 1382d72893bSLiu Zhe xShapeText = getFirstTextbox(); 1392d72893bSLiu Zhe xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 1402d72893bSLiu Zhe //check character styles 1412d72893bSLiu Zhe assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor")); 1422d72893bSLiu Zhe 1432d72893bSLiu Zhe } 1442d72893bSLiu Zhe @Test 1452d72893bSLiu Zhe public void testFontUnderline() throws Exception{ 1462d72893bSLiu Zhe //set font color to red 1472d72893bSLiu Zhe xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE); 1482d72893bSLiu Zhe app.saveDocument(m_xSDComponent, filePath); 1492d72893bSLiu Zhe m_xSDComponent.dispose(); 1502d72893bSLiu Zhe //reopen 1512d72893bSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 1522d72893bSLiu Zhe app.loadDocument(filePath)); 1532d72893bSLiu Zhe xShapeText = getFirstTextbox(); 1542d72893bSLiu Zhe xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 1552d72893bSLiu Zhe //check character styles 1562d72893bSLiu Zhe assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline")); 1572d72893bSLiu Zhe } 1582d72893bSLiu Zhe 1592d72893bSLiu Zhe @Test 1602d72893bSLiu Zhe public void testFontSize() throws Exception{ 1612d72893bSLiu Zhe //set font color to red 1622d72893bSLiu Zhe xtextProps.setPropertyValue("CharHeight", 12); 1632d72893bSLiu Zhe app.saveDocument(m_xSDComponent, filePath); 1642d72893bSLiu Zhe m_xSDComponent.dispose(); 1652d72893bSLiu Zhe //reopen 1662d72893bSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 1672d72893bSLiu Zhe app.loadDocument(filePath)); 1682d72893bSLiu Zhe xShapeText = getFirstTextbox(); 1692d72893bSLiu Zhe xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 1702d72893bSLiu Zhe //check character styles 1712d72893bSLiu Zhe assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString()); 1722d72893bSLiu Zhe } 1732d72893bSLiu Zhe @Test 1742d72893bSLiu Zhe public void testFontBoldStyle() throws Exception { 1752d72893bSLiu Zhe //change the font style to Bold 1762d72893bSLiu Zhe xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD); 1772d72893bSLiu Zhe app.saveDocument(m_xSDComponent, filePath); 1782d72893bSLiu Zhe m_xSDComponent.dispose(); 1792d72893bSLiu Zhe //reopen 1802d72893bSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 1812d72893bSLiu Zhe app.loadDocument(filePath)); 1822d72893bSLiu Zhe xShapeText = getFirstTextbox(); 1832d72893bSLiu Zhe xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 1842d72893bSLiu Zhe assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight")); 1852d72893bSLiu Zhe } 1862d72893bSLiu Zhe 1872d72893bSLiu Zhe @Test 1882d72893bSLiu Zhe public void testFontItalicStyle() throws Exception { 1892d72893bSLiu Zhe //change the font style to Bold 1902d72893bSLiu Zhe xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC); 1912d72893bSLiu Zhe app.saveDocument(m_xSDComponent, filePath); 1922d72893bSLiu Zhe m_xSDComponent.dispose(); 1932d72893bSLiu Zhe //reopen 1942d72893bSLiu Zhe m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 1952d72893bSLiu Zhe app.loadDocument(filePath)); 1962d72893bSLiu Zhe xShapeText = getFirstTextbox(); 1972d72893bSLiu Zhe xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); 1982d72893bSLiu Zhe assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture")); 1992d72893bSLiu Zhe } 2002d72893bSLiu Zhe } 201