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  *************************************************************/
21*07d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
239f0ca99bSLiu Zhe 
249f0ca99bSLiu Zhe import static org.junit.Assert.*;
259f0ca99bSLiu Zhe 
269f0ca99bSLiu Zhe import org.junit.After;
279f0ca99bSLiu Zhe import org.junit.Before;
289f0ca99bSLiu Zhe import org.junit.Ignore;
299f0ca99bSLiu Zhe import org.junit.Test;
309f0ca99bSLiu Zhe import org.openoffice.test.common.FileUtil;
319f0ca99bSLiu Zhe import org.openoffice.test.common.Testspace;
329f0ca99bSLiu Zhe import org.openoffice.test.uno.UnoApp;
339f0ca99bSLiu Zhe import com.sun.star.text.*;
349f0ca99bSLiu Zhe import com.sun.star.beans.*;
359f0ca99bSLiu Zhe import com.sun.star.frame.XStorable;
369f0ca99bSLiu Zhe import com.sun.star.uno.UnoRuntime;
379f0ca99bSLiu Zhe 
389f0ca99bSLiu Zhe public class ParagraphOutlineAndNumbering {
399f0ca99bSLiu Zhe 	private static final UnoApp app = new UnoApp();
409f0ca99bSLiu Zhe 	XText xText = null;
419f0ca99bSLiu Zhe 
429f0ca99bSLiu Zhe 	@Before
setUp()439f0ca99bSLiu Zhe 	public void setUp() throws Exception {
449f0ca99bSLiu Zhe 		app.start();
459f0ca99bSLiu Zhe 
469f0ca99bSLiu Zhe 	}
479f0ca99bSLiu Zhe 
489f0ca99bSLiu Zhe 	@After
tearDown()499f0ca99bSLiu Zhe 	public void tearDown() throws Exception {
509f0ca99bSLiu Zhe 		//app.close();
519f0ca99bSLiu Zhe 	}
529f0ca99bSLiu Zhe 	/*
539f0ca99bSLiu Zhe 	 * test paragraph background color
549f0ca99bSLiu Zhe 	 * 1.new a text document
559f0ca99bSLiu Zhe 	 * 2.insert some text
569f0ca99bSLiu Zhe 	 * 3.set paragraph outline and numbering
579f0ca99bSLiu Zhe 	 * 4.save and close the document
589f0ca99bSLiu Zhe 	 * 5.reload the saved document and check the paragraph outline and numbering
599f0ca99bSLiu Zhe 	 */
60af986861SLiu Zhe 	@Test@Ignore("Bug #120753 - [testUNO patch]paragraph outline level and numbering style change when save to doc")
testOutlineAndNumbering_NumberStyle()619f0ca99bSLiu Zhe 	public void testOutlineAndNumbering_NumberStyle() throws Exception {
629f0ca99bSLiu Zhe 
639f0ca99bSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
649f0ca99bSLiu Zhe 		xText = xTextDocument.getText();
659f0ca99bSLiu 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!" +
669f0ca99bSLiu Zhe 				"Hello,world!Hello,world!");
679f0ca99bSLiu Zhe 		XTextCursor xTextCursor=xText.createTextCursor();
689f0ca99bSLiu Zhe 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
699f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("OutlineLevel", (short)6);
709f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("NumberingStyleName", "Numbering 2");
719f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaIsNumberingRestart", true);
729f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("NumberingStartValue", (short)7);
739f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaLineNumberCount",true);
749f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaLineNumberStartValue",(long)4);
759f0ca99bSLiu Zhe 		//save to odt
769f0ca99bSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
779f0ca99bSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
789f0ca99bSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
799f0ca99bSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
809f0ca99bSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
819f0ca99bSLiu Zhe 		aStoreProperties_odt[0].Value = true;
829f0ca99bSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
839f0ca99bSLiu Zhe 		aStoreProperties_odt[1].Value = "writer8";
849f0ca99bSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
859f0ca99bSLiu Zhe 		//save to doc
869f0ca99bSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
879f0ca99bSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
889f0ca99bSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
899f0ca99bSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
909f0ca99bSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
919f0ca99bSLiu Zhe 		aStoreProperties_doc[0].Value = true;
929f0ca99bSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
939f0ca99bSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
949f0ca99bSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
959f0ca99bSLiu Zhe 		//app.closeDocument(xTextDocument);
969f0ca99bSLiu Zhe 
979f0ca99bSLiu Zhe 		//reopen the document
989f0ca99bSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
999f0ca99bSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
1009f0ca99bSLiu Zhe 		//verify paragraph outline and numbering
1019f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_odt.getPropertyValue("OutlineLevel"));
1029f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering","Numbering 2",xCursorProps_Assert_odt.getPropertyValue("NumberingStyleName"));
1039f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsNumberingRestart"));
1049f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)7,xCursorProps_Assert_odt.getPropertyValue("NumberingStartValue"));
1059f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberCount"));
1069f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberStartValue"));
1079f0ca99bSLiu Zhe 
1089f0ca99bSLiu Zhe 		//reopen the document
1099f0ca99bSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
1109f0ca99bSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
1119f0ca99bSLiu Zhe 		//verify paragraph outline and numbering
1129f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_doc.getPropertyValue("OutlineLevel"));
1139f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering","Numbering 2",xCursorProps_Assert_doc.getPropertyValue("NumberingStyleName"));
1149f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsNumberingRestart"));
1159f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)7,xCursorProps_Assert_doc.getPropertyValue("NumberingStartValue"));
1169f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberCount"));
1179f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberStartValue"));
1189f0ca99bSLiu Zhe 
1199f0ca99bSLiu Zhe 	}
120af986861SLiu Zhe 	@Test@Ignore("Bug #120753 - [testUNO patch]paragraph outline level and numbering style change when save to doc")
testOutlineAndNumbering_ListStyle()1219f0ca99bSLiu Zhe 	public void testOutlineAndNumbering_ListStyle() throws Exception {
1229f0ca99bSLiu Zhe 
1239f0ca99bSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
1249f0ca99bSLiu Zhe 		xText = xTextDocument.getText();
1259f0ca99bSLiu 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!" +
1269f0ca99bSLiu Zhe 				"Hello,world!Hello,world!");
1279f0ca99bSLiu Zhe 		XTextCursor xTextCursor=xText.createTextCursor();
1289f0ca99bSLiu Zhe 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
1299f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("OutlineLevel", (short)3);
1309f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("NumberingStyleName", "List 3");
1319f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaIsNumberingRestart", true);
1329f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("NumberingStartValue", (short)6);
1339f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaLineNumberCount",true);
1349f0ca99bSLiu Zhe 		xTextProps.setPropertyValue("ParaLineNumberStartValue",(long)4);
1359f0ca99bSLiu Zhe 		//save to odt
1369f0ca99bSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1379f0ca99bSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
1389f0ca99bSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
1399f0ca99bSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
1409f0ca99bSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
1419f0ca99bSLiu Zhe 		aStoreProperties_odt[0].Value = true;
1429f0ca99bSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
1439f0ca99bSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
1449f0ca99bSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
1459f0ca99bSLiu Zhe 		//save to doc
1469f0ca99bSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1479f0ca99bSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
1489f0ca99bSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
1499f0ca99bSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
1509f0ca99bSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
1519f0ca99bSLiu Zhe 		aStoreProperties_doc[0].Value = true;
1529f0ca99bSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
1539f0ca99bSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
1549f0ca99bSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
1559f0ca99bSLiu Zhe 		//app.closeDocument(xTextDocument);
1569f0ca99bSLiu Zhe 
1579f0ca99bSLiu Zhe 		//reopen the document
1589f0ca99bSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
1599f0ca99bSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
1609f0ca99bSLiu Zhe 		//verify paragraph outline and numbering
1619f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)3,xCursorProps_Assert_odt.getPropertyValue("OutlineLevel"));
1629f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering","List 3",xCursorProps_Assert_odt.getPropertyValue("NumberingStyleName"));
1639f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsNumberingRestart"));
1649f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_odt.getPropertyValue("NumberingStartValue"));
1659f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberCount"));
1669f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_odt.getPropertyValue("ParaLineNumberStartValue"));
1679f0ca99bSLiu Zhe 
1689f0ca99bSLiu Zhe 
1699f0ca99bSLiu Zhe 		//reopen the document
1709f0ca99bSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
1719f0ca99bSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
1729f0ca99bSLiu Zhe 		//verify paragraph outline and numbering
1739f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)3,xCursorProps_Assert_doc.getPropertyValue("OutlineLevel"));
1749f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering","List 3",xCursorProps_Assert_doc.getPropertyValue("NumberingStyleName"));
1759f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsNumberingRestart"));
1769f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(short)6,xCursorProps_Assert_doc.getPropertyValue("NumberingStartValue"));
1779f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",true,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberCount"));
1789f0ca99bSLiu Zhe 		assertEquals("assert paragraph outline and numbering",(long)4,xCursorProps_Assert_doc.getPropertyValue("ParaLineNumberStartValue"));
1799f0ca99bSLiu Zhe 
1809f0ca99bSLiu Zhe 	}
1819f0ca99bSLiu Zhe }
182