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