1*eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
26194dbcdSLiu Zhe 
36194dbcdSLiu Zhe import static org.junit.Assert.*;
46194dbcdSLiu Zhe 
56194dbcdSLiu Zhe import org.junit.After;
66194dbcdSLiu Zhe import org.junit.Before;
76194dbcdSLiu Zhe import org.junit.Test;
86194dbcdSLiu Zhe import org.openoffice.test.common.FileUtil;
96194dbcdSLiu Zhe import org.openoffice.test.common.Testspace;
106194dbcdSLiu Zhe import org.openoffice.test.uno.UnoApp;
116194dbcdSLiu Zhe 
126194dbcdSLiu Zhe import com.sun.star.style.DropCapFormat;
136194dbcdSLiu Zhe import com.sun.star.text.*;
146194dbcdSLiu Zhe import com.sun.star.beans.*;
156194dbcdSLiu Zhe import com.sun.star.frame.XStorable;
166194dbcdSLiu Zhe import com.sun.star.uno.UnoRuntime;
176194dbcdSLiu Zhe 
186194dbcdSLiu Zhe public class ParagraphDropcap {
196194dbcdSLiu Zhe 	private static final UnoApp app = new UnoApp();
206194dbcdSLiu Zhe 	XText xText = null;
216194dbcdSLiu Zhe 
226194dbcdSLiu Zhe 	@Before
236194dbcdSLiu Zhe 	public void setUp() throws Exception {
246194dbcdSLiu Zhe 		app.start();
256194dbcdSLiu Zhe 
266194dbcdSLiu Zhe 	}
276194dbcdSLiu Zhe 
286194dbcdSLiu Zhe 	@After
296194dbcdSLiu Zhe 	public void tearDown() throws Exception {
306194dbcdSLiu Zhe 		app.close();
316194dbcdSLiu Zhe 	}
326194dbcdSLiu Zhe 	/*
336194dbcdSLiu Zhe 	 * test paragraph background color
346194dbcdSLiu Zhe 	 * 1.new a text document
356194dbcdSLiu Zhe 	 * 2.insert some text
366194dbcdSLiu Zhe 	 * 3.set paragraph drop
376194dbcdSLiu Zhe 	 * 4.save and close the document
386194dbcdSLiu Zhe 	 * 5.reload the saved document and check the paragraph drop cap
396194dbcdSLiu Zhe 	 */
406194dbcdSLiu Zhe 	@Test
416194dbcdSLiu Zhe 	public void testParagraphDropcapSetting() throws Exception {
426194dbcdSLiu Zhe 
436194dbcdSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
446194dbcdSLiu Zhe 		xText = xTextDocument.getText();
456194dbcdSLiu Zhe 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
466194dbcdSLiu Zhe 				"Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!");
476194dbcdSLiu Zhe 		// create text cursor for selecting and formatting text
486194dbcdSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
496194dbcdSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
506194dbcdSLiu Zhe 		//set paragraph dropcaps
516194dbcdSLiu Zhe 		DropCapFormat dropcapFormat=new DropCapFormat();
526194dbcdSLiu Zhe 		dropcapFormat.Lines=3;
536194dbcdSLiu Zhe 		dropcapFormat.Distance=101;
546194dbcdSLiu Zhe 		dropcapFormat.Count=9;
556194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("DropCapFormat",dropcapFormat);
566194dbcdSLiu Zhe 		//xCursorProps.setPropertyValue("DropCapWholeWord",true);
576194dbcdSLiu Zhe 		//save to odt
586194dbcdSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
596194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
606194dbcdSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
616194dbcdSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
626194dbcdSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
636194dbcdSLiu Zhe 		aStoreProperties_odt[0].Value = true;
646194dbcdSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
656194dbcdSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
666194dbcdSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
676194dbcdSLiu Zhe 		//save to doc
686194dbcdSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
696194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
706194dbcdSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
716194dbcdSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
726194dbcdSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
736194dbcdSLiu Zhe 		aStoreProperties_doc[0].Value = true;
746194dbcdSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
756194dbcdSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
766194dbcdSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
776194dbcdSLiu Zhe 		app.closeDocument(xTextDocument);
786194dbcdSLiu Zhe 
796194dbcdSLiu Zhe 		//reopen the document
806194dbcdSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
816194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
826194dbcdSLiu Zhe 		//verify paragraph dropcap
836194dbcdSLiu Zhe 		DropCapFormat dropcapFormat_assert_odt = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_odt.getPropertyValue("DropCapFormat"));
846194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",9,dropcapFormat_assert_odt.Count);
856194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_odt.Lines);
866194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_odt.Distance);
876194dbcdSLiu Zhe 
886194dbcdSLiu Zhe 		//reopen the document
896194dbcdSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
906194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
916194dbcdSLiu Zhe 		//verify paragraph dropcap
926194dbcdSLiu Zhe 		DropCapFormat dropcapFormat_assert_doc = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_doc.getPropertyValue("DropCapFormat"));
936194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",9,dropcapFormat_assert_doc.Count);
946194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_doc.Lines);
956194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_doc.Distance);
966194dbcdSLiu Zhe 	}
976194dbcdSLiu Zhe 	@Test
986194dbcdSLiu Zhe 	public void testParagraphDropcapWholewordSetting() throws Exception {
996194dbcdSLiu Zhe 
1006194dbcdSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
1016194dbcdSLiu Zhe 		xText = xTextDocument.getText();
1026194dbcdSLiu Zhe 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
1036194dbcdSLiu Zhe 				"Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!");
1046194dbcdSLiu Zhe 		// create text cursor for selecting and formatting text
1056194dbcdSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
1066194dbcdSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
1076194dbcdSLiu Zhe 		//set paragraph dropcaps
1086194dbcdSLiu Zhe 		DropCapFormat dropcapFormat=new DropCapFormat();
1096194dbcdSLiu Zhe 		dropcapFormat.Lines=3;
1106194dbcdSLiu Zhe 		dropcapFormat.Distance=101;
1116194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("DropCapFormat",dropcapFormat);
1126194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("DropCapWholeWord",true);
1136194dbcdSLiu Zhe 		//save to odt
1146194dbcdSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1156194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
1166194dbcdSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
1176194dbcdSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
1186194dbcdSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
1196194dbcdSLiu Zhe 		aStoreProperties_odt[0].Value = true;
1206194dbcdSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
1216194dbcdSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
1226194dbcdSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
1236194dbcdSLiu Zhe 		//save to doc
1246194dbcdSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1256194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
1266194dbcdSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
1276194dbcdSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
1286194dbcdSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
1296194dbcdSLiu Zhe 		aStoreProperties_doc[0].Value = true;
1306194dbcdSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
1316194dbcdSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
1326194dbcdSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
1336194dbcdSLiu Zhe 		app.closeDocument(xTextDocument);
1346194dbcdSLiu Zhe 
1356194dbcdSLiu Zhe 		//reopen the document
1366194dbcdSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
1376194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
1386194dbcdSLiu Zhe 		//verify paragraph dropcap
1396194dbcdSLiu Zhe 		DropCapFormat dropcapFormat_assert_odt = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_odt.getPropertyValue("DropCapFormat"));
1406194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",true,xCursorProps_Assert_odt.getPropertyValue("DropCapWholeWord"));
1416194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_odt.Lines);
1426194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_odt.Distance);
1436194dbcdSLiu Zhe 
1446194dbcdSLiu Zhe 		//reopen the document
1456194dbcdSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
1466194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
1476194dbcdSLiu Zhe 		//verify paragraph dropcap
1486194dbcdSLiu Zhe 		DropCapFormat dropcapFormat_assert_doc = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_doc.getPropertyValue("DropCapFormat"));
1496194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_doc.Lines);
1506194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_doc.Distance);
1516194dbcdSLiu Zhe 		//when save to doc,the DropCapWholeWord option will disable,and enable dropcapFormat.count
1526194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",false,xCursorProps_Assert_doc.getPropertyValue("DropCapWholeWord"));
1536194dbcdSLiu Zhe 	}
1546194dbcdSLiu Zhe }
155