1*eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
29f0ca99bSLiu Zhe 
39f0ca99bSLiu Zhe import static org.junit.Assert.*;
49f0ca99bSLiu Zhe 
59f0ca99bSLiu Zhe import org.junit.After;
69f0ca99bSLiu Zhe import org.junit.Before;
79f0ca99bSLiu Zhe import org.junit.Ignore;
89f0ca99bSLiu Zhe import org.junit.Test;
99f0ca99bSLiu Zhe import org.openoffice.test.common.FileUtil;
109f0ca99bSLiu Zhe import org.openoffice.test.common.Testspace;
119f0ca99bSLiu Zhe import org.openoffice.test.uno.UnoApp;
129f0ca99bSLiu Zhe import com.sun.star.text.*;
139f0ca99bSLiu Zhe import com.sun.star.beans.*;
149f0ca99bSLiu Zhe import com.sun.star.frame.XStorable;
159f0ca99bSLiu Zhe import com.sun.star.uno.UnoRuntime;
169f0ca99bSLiu Zhe 
179f0ca99bSLiu Zhe public class ParagraphOutlineAndNumbering {
189f0ca99bSLiu Zhe 	private static final UnoApp app = new UnoApp();
199f0ca99bSLiu Zhe 	XText xText = null;
209f0ca99bSLiu Zhe 
219f0ca99bSLiu Zhe 	@Before
229f0ca99bSLiu Zhe 	public void setUp() throws Exception {
239f0ca99bSLiu Zhe 		app.start();
249f0ca99bSLiu Zhe 
259f0ca99bSLiu Zhe 	}
269f0ca99bSLiu Zhe 
279f0ca99bSLiu Zhe 	@After
289f0ca99bSLiu Zhe 	public void tearDown() throws Exception {
299f0ca99bSLiu Zhe 		//app.close();
309f0ca99bSLiu Zhe 	}
319f0ca99bSLiu Zhe 	/*
329f0ca99bSLiu Zhe 	 * test paragraph background color
339f0ca99bSLiu Zhe 	 * 1.new a text document
349f0ca99bSLiu Zhe 	 * 2.insert some text
359f0ca99bSLiu Zhe 	 * 3.set paragraph outline and numbering
369f0ca99bSLiu Zhe 	 * 4.save and close the document
379f0ca99bSLiu Zhe 	 * 5.reload the saved document and check the paragraph outline and numbering
389f0ca99bSLiu Zhe 	 */
39af986861SLiu Zhe 	@Test@Ignore("Bug #120753 - [testUNO patch]paragraph outline level and numbering style change when save to doc")
409f0ca99bSLiu Zhe 	public void testOutlineAndNumbering_NumberStyle() throws Exception {
419f0ca99bSLiu Zhe 
429f0ca99bSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
439f0ca99bSLiu Zhe 		xText = xTextDocument.getText();
449f0ca99bSLiu Zhe 		xText.setString("we are Chinese,they are American.\nwe are all living in one earth!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!Hello,world!" +
459f0ca99bSLiu Zhe 				"Hello,world!Hello,world!");
469f0ca99bSLiu Zhe 		XTextCursor xTextCursor=xText.createTextCursor();
479f0ca99bSLiu Zhe 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
489f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("OutlineLevel", (short)6);
499f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("NumberingStyleName", "Numbering 2");
509f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaIsNumberingRestart", true);
519f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("NumberingStartValue", (short)7);
529f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaLineNumberCount",true);
539f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaLineNumberStartValue",(long)4);
549f0ca99bSLiu Zhe 		//save to odt
559f0ca99bSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
569f0ca99bSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
579f0ca99bSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
589f0ca99bSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
599f0ca99bSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
609f0ca99bSLiu Zhe 		aStoreProperties_odt[0].Value = true;
619f0ca99bSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
629f0ca99bSLiu Zhe 		aStoreProperties_odt[1].Value = "writer8";
639f0ca99bSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
649f0ca99bSLiu Zhe 		//save to doc
659f0ca99bSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
669f0ca99bSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
679f0ca99bSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
689f0ca99bSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
699f0ca99bSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
709f0ca99bSLiu Zhe 		aStoreProperties_doc[0].Value = true;
719f0ca99bSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
729f0ca99bSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
739f0ca99bSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
749f0ca99bSLiu Zhe 		//app.closeDocument(xTextDocument);
759f0ca99bSLiu Zhe 
769f0ca99bSLiu Zhe 		//reopen the document
779f0ca99bSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
789f0ca99bSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
799f0ca99bSLiu Zhe 		//verify paragraph outline and numbering
809f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_odt.getPropertyValue("OutlineLevel"));
819f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering","Numbering 2",xCursorProps_Assert_odt.getPropertyValue("NumberingStyleName"));
829f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsNumberingRestart"));
839f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)7,xCursorProps_Assert_odt.getPropertyValue("NumberingStartValue"));
849f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberCount"));
859f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberStartValue"));
869f0ca99bSLiu Zhe 
879f0ca99bSLiu Zhe 		//reopen the document
889f0ca99bSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
899f0ca99bSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
909f0ca99bSLiu Zhe 		//verify paragraph outline and numbering
919f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_doc.getPropertyValue("OutlineLevel"));
929f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering","Numbering 2",xCursorProps_Assert_doc.getPropertyValue("NumberingStyleName"));
939f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsNumberingRestart"));
949f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)7,xCursorProps_Assert_doc.getPropertyValue("NumberingStartValue"));
959f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberCount"));
969f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberStartValue"));
979f0ca99bSLiu Zhe 
989f0ca99bSLiu Zhe 	}
99af986861SLiu Zhe 	@Test@Ignore("Bug #120753 - [testUNO patch]paragraph outline level and numbering style change when save to doc")
1009f0ca99bSLiu Zhe 	public void testOutlineAndNumbering_ListStyle() throws Exception {
1019f0ca99bSLiu Zhe 
1029f0ca99bSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
1039f0ca99bSLiu Zhe 		xText = xTextDocument.getText();
1049f0ca99bSLiu Zhe 		xText.setString("we are Chinese,they are American.\nwe are all living in one earth!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!Hello,world!" +
1059f0ca99bSLiu Zhe 				"Hello,world!Hello,world!");
1069f0ca99bSLiu Zhe 		XTextCursor xTextCursor=xText.createTextCursor();
1079f0ca99bSLiu Zhe 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
1089f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("OutlineLevel", (short)3);
1099f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("NumberingStyleName", "List 3");
1109f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaIsNumberingRestart", true);
1119f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("NumberingStartValue", (short)6);
1129f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaLineNumberCount",true);
1139f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaLineNumberStartValue",(long)4);
1149f0ca99bSLiu Zhe 		//save to odt
1159f0ca99bSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1169f0ca99bSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
1179f0ca99bSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
1189f0ca99bSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
1199f0ca99bSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
1209f0ca99bSLiu Zhe 		aStoreProperties_odt[0].Value = true;
1219f0ca99bSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
1229f0ca99bSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
1239f0ca99bSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
1249f0ca99bSLiu Zhe 		//save to doc
1259f0ca99bSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1269f0ca99bSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
1279f0ca99bSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
1289f0ca99bSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
1299f0ca99bSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
1309f0ca99bSLiu Zhe 		aStoreProperties_doc[0].Value = true;
1319f0ca99bSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
1329f0ca99bSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
1339f0ca99bSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
1349f0ca99bSLiu Zhe 		//app.closeDocument(xTextDocument);
1359f0ca99bSLiu Zhe 
1369f0ca99bSLiu Zhe 		//reopen the document
1379f0ca99bSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
1389f0ca99bSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
1399f0ca99bSLiu Zhe 		//verify paragraph outline and numbering
1409f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)3,xCursorProps_Assert_odt.getPropertyValue("OutlineLevel"));
1419f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering","List 3",xCursorProps_Assert_odt.getPropertyValue("NumberingStyleName"));
1429f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsNumberingRestart"));
1439f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_odt.getPropertyValue("NumberingStartValue"));
1449f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberCount"));
1459f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberStartValue"));
1469f0ca99bSLiu Zhe 
1479f0ca99bSLiu Zhe 
1489f0ca99bSLiu Zhe 		//reopen the document
1499f0ca99bSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
1509f0ca99bSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
1519f0ca99bSLiu Zhe 		//verify paragraph outline and numbering
1529f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)3,xCursorProps_Assert_doc.getPropertyValue("OutlineLevel"));
1539f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering","List 3",xCursorProps_Assert_doc.getPropertyValue("NumberingStyleName"));
1549f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsNumberingRestart"));
1559f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_doc.getPropertyValue("NumberingStartValue"));
1569f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberCount"));
1579f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberStartValue"));
1589f0ca99bSLiu Zhe 
1599f0ca99bSLiu Zhe 	}
1609f0ca99bSLiu Zhe }
161