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  *************************************************************/
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.*;
37*28725c19SLi Feng Wang import static testlib.uno.SDUtil.saveFileAs;
382d72893bSLiu Zhe 
392d72893bSLiu Zhe import java.io.File;
402d72893bSLiu Zhe import org.junit.After;
412d72893bSLiu Zhe import org.junit.AfterClass;
422d72893bSLiu Zhe import org.junit.Before;
432d72893bSLiu Zhe import org.junit.BeforeClass;
442d72893bSLiu Zhe import org.junit.Test;
452d72893bSLiu Zhe import org.openoffice.test.common.FileUtil;
462d72893bSLiu Zhe import org.openoffice.test.common.Testspace;
472d72893bSLiu Zhe import org.openoffice.test.uno.UnoApp;
482d72893bSLiu Zhe 
49f0480a3dSLiu Zhe import testlib.uno.SDUtil;
502d72893bSLiu Zhe 
512d72893bSLiu Zhe import com.sun.star.beans.PropertyValue;
522d72893bSLiu Zhe import com.sun.star.beans.XPropertySet;
532d72893bSLiu Zhe import com.sun.star.container.XIndexAccess;
542d72893bSLiu Zhe import com.sun.star.drawing.XDrawPage;
552d72893bSLiu Zhe import com.sun.star.drawing.XDrawPages;
562d72893bSLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier;
572d72893bSLiu Zhe import com.sun.star.drawing.XShapes;
582d72893bSLiu Zhe import com.sun.star.frame.XStorable;
592d72893bSLiu Zhe 
602d72893bSLiu Zhe import com.sun.star.lang.XComponent;
612d72893bSLiu Zhe 
622d72893bSLiu Zhe import com.sun.star.text.XText;
632d72893bSLiu Zhe import com.sun.star.uno.UnoRuntime;
642d72893bSLiu Zhe 
652d72893bSLiu Zhe /**
662d72893bSLiu Zhe  * @author LouQL
672d72893bSLiu Zhe  *
682d72893bSLiu Zhe  */
692d72893bSLiu Zhe public class CheckCharacterStyle {
702d72893bSLiu Zhe 
712d72893bSLiu Zhe 	private static final UnoApp app = new UnoApp();
722d72893bSLiu Zhe 	private XComponent m_xSDComponent = null;
732d72893bSLiu Zhe 	private XText xShapeText = null;
742d72893bSLiu Zhe 	private String filePath = null;
752d72893bSLiu Zhe 	private XPropertySet xtextProps = null;
762d72893bSLiu Zhe 	/**
772d72893bSLiu Zhe 	 * @throws java.lang.Exception
782d72893bSLiu Zhe 	 */
792d72893bSLiu Zhe 	@BeforeClass
setUpConnection()802d72893bSLiu Zhe 	public static void setUpConnection() throws Exception {
812d72893bSLiu Zhe 		app.start();
822d72893bSLiu Zhe 		File temp = new File(Testspace.getPath("temp"));
832d72893bSLiu Zhe 		temp.mkdirs();
842d72893bSLiu Zhe 	}
852d72893bSLiu Zhe 
862d72893bSLiu Zhe 	@AfterClass
tearDownConnection()872d72893bSLiu Zhe 	public static void tearDownConnection() throws Exception {
882d72893bSLiu Zhe 		app.close();
89*28725c19SLi Feng Wang 
902d72893bSLiu Zhe 	}
912d72893bSLiu Zhe 
922d72893bSLiu Zhe 	/**
932d72893bSLiu Zhe 	 * @throws java.lang.Exception
942d72893bSLiu Zhe 	 */
952d72893bSLiu Zhe 	@Before
setUp()962d72893bSLiu Zhe 	public void setUp() throws Exception {
97*28725c19SLi Feng Wang 		filePath = Testspace.getPath("temp/CheckCharacterStyle.odp");
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 
getFirstTextbox()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
tearDown()1242d72893bSLiu Zhe 	public void tearDown() throws Exception {
1252d72893bSLiu Zhe 		//close odp after each test
1262d72893bSLiu Zhe 		m_xSDComponent.dispose();
127*28725c19SLi Feng Wang 
128*28725c19SLi Feng Wang 		//remove the temp file
129*28725c19SLi Feng Wang 		FileUtil.deleteFile(Testspace.getPath("temp"));
1302d72893bSLiu Zhe 	}
1312d72893bSLiu Zhe 
1322d72893bSLiu Zhe 	@Test
testFontColor()1332d72893bSLiu Zhe 	public void testFontColor() throws Exception{
1342d72893bSLiu Zhe 		//set font color to red
1352d72893bSLiu Zhe 		xtextProps.setPropertyValue("CharColor", 0xFF0000);
136*28725c19SLi Feng Wang //		saveFileAs(m_xSDComponent, filePath, ".odp");
1372d72893bSLiu Zhe 		app.saveDocument(m_xSDComponent, filePath);
1382d72893bSLiu Zhe 		m_xSDComponent.dispose();
1392d72893bSLiu Zhe 		//reopen
1402d72893bSLiu Zhe 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
1412d72893bSLiu Zhe 					app.loadDocument(filePath));
1422d72893bSLiu Zhe 		xShapeText = getFirstTextbox();
1432d72893bSLiu Zhe 		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
1442d72893bSLiu Zhe 		//check character styles
1452d72893bSLiu Zhe 		assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor"));
1462d72893bSLiu Zhe 
1472d72893bSLiu Zhe 	}
1482d72893bSLiu Zhe 	@Test
testFontUnderline()1492d72893bSLiu Zhe 	public void testFontUnderline() throws Exception{
1502d72893bSLiu Zhe 		//set font color to red
1512d72893bSLiu Zhe 		xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE);
1522d72893bSLiu Zhe 		app.saveDocument(m_xSDComponent, filePath);
1532d72893bSLiu Zhe 		m_xSDComponent.dispose();
1542d72893bSLiu Zhe 		//reopen
1552d72893bSLiu Zhe 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
1562d72893bSLiu Zhe 					app.loadDocument(filePath));
1572d72893bSLiu Zhe 		xShapeText = getFirstTextbox();
1582d72893bSLiu Zhe 		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
1592d72893bSLiu Zhe 		//check character styles
1602d72893bSLiu Zhe 		assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline"));
1612d72893bSLiu Zhe 	}
1622d72893bSLiu Zhe 
1632d72893bSLiu Zhe 	@Test
testFontSize()1642d72893bSLiu Zhe 	public void testFontSize() throws Exception{
1652d72893bSLiu Zhe 		//set font color to red
1662d72893bSLiu Zhe 		xtextProps.setPropertyValue("CharHeight", 12);
1672d72893bSLiu Zhe 		app.saveDocument(m_xSDComponent, filePath);
1682d72893bSLiu Zhe 		m_xSDComponent.dispose();
1692d72893bSLiu Zhe 		//reopen
1702d72893bSLiu Zhe 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
1712d72893bSLiu Zhe 					app.loadDocument(filePath));
1722d72893bSLiu Zhe 		xShapeText = getFirstTextbox();
1732d72893bSLiu Zhe 		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
1742d72893bSLiu Zhe 		//check character styles
1752d72893bSLiu Zhe 		assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString());
1762d72893bSLiu Zhe 	}
1772d72893bSLiu Zhe 	@Test
testFontBoldStyle()1782d72893bSLiu Zhe 	public void testFontBoldStyle() throws Exception  {
1792d72893bSLiu Zhe 		//change the font style to Bold
1802d72893bSLiu Zhe 		xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD);
1812d72893bSLiu Zhe 		app.saveDocument(m_xSDComponent, filePath);
1822d72893bSLiu Zhe 		m_xSDComponent.dispose();
1832d72893bSLiu Zhe 		//reopen
1842d72893bSLiu Zhe 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
1852d72893bSLiu Zhe 					app.loadDocument(filePath));
1862d72893bSLiu Zhe 		xShapeText = getFirstTextbox();
1872d72893bSLiu Zhe 		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
1882d72893bSLiu Zhe 		assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight"));
1892d72893bSLiu Zhe 	}
1902d72893bSLiu Zhe 
1912d72893bSLiu Zhe 	@Test
testFontItalicStyle()1922d72893bSLiu Zhe 	public void testFontItalicStyle() throws Exception  {
1932d72893bSLiu Zhe 		//change the font style to Bold
1942d72893bSLiu Zhe 		xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC);
1952d72893bSLiu Zhe 		app.saveDocument(m_xSDComponent, filePath);
1962d72893bSLiu Zhe 		m_xSDComponent.dispose();
1972d72893bSLiu Zhe 		//reopen
1982d72893bSLiu Zhe 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
1992d72893bSLiu Zhe 					app.loadDocument(filePath));
2002d72893bSLiu Zhe 		xShapeText = getFirstTextbox();
2012d72893bSLiu Zhe 		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
2022d72893bSLiu Zhe 		assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture"));
2032d72893bSLiu Zhe 	}
2042d72893bSLiu Zhe }
205