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; 234a089d9bSLiu Zhe 244a089d9bSLiu Zhe import static org.junit.Assert.*; 254a089d9bSLiu Zhe 264a089d9bSLiu Zhe import org.junit.After; 274a089d9bSLiu Zhe import org.junit.Before; 284a089d9bSLiu Zhe import org.junit.Test; 294a089d9bSLiu Zhe import org.openoffice.test.common.FileUtil; 304a089d9bSLiu Zhe import org.openoffice.test.common.Testspace; 314a089d9bSLiu Zhe import org.openoffice.test.uno.UnoApp; 324a089d9bSLiu Zhe 334a089d9bSLiu Zhe import com.sun.star.style.NumberingType; 344a089d9bSLiu Zhe import com.sun.star.text.*; 354a089d9bSLiu Zhe import com.sun.star.beans.*; 364a089d9bSLiu Zhe import com.sun.star.container.XIndexAccess; 374a089d9bSLiu Zhe import com.sun.star.container.XIndexReplace; 384a089d9bSLiu Zhe import com.sun.star.frame.XStorable; 394a089d9bSLiu Zhe import com.sun.star.lang.XMultiServiceFactory; 404a089d9bSLiu Zhe import com.sun.star.uno.UnoRuntime; 414a089d9bSLiu Zhe 424a089d9bSLiu Zhe public class ParagraphNumberingAndBulletIndentAtAndAlignAt { 434a089d9bSLiu Zhe private static final UnoApp app = new UnoApp(); 444a089d9bSLiu Zhe XText xText = null; 454a089d9bSLiu Zhe 464a089d9bSLiu Zhe @Before setUp()474a089d9bSLiu Zhe public void setUp() throws Exception { 484a089d9bSLiu Zhe app.start(); 494a089d9bSLiu Zhe 504a089d9bSLiu Zhe } 514a089d9bSLiu Zhe 524a089d9bSLiu Zhe @After tearDown()534a089d9bSLiu Zhe public void tearDown() throws Exception { 544a089d9bSLiu Zhe app.close(); 554a089d9bSLiu Zhe } 564a089d9bSLiu Zhe /* 574a089d9bSLiu Zhe * test paragraph background color 584a089d9bSLiu Zhe * 1.new a text document 594a089d9bSLiu Zhe * 2.insert some text 604a089d9bSLiu Zhe * 3.set paragraph outline and numbering 614a089d9bSLiu Zhe * 4.save and close the document 624a089d9bSLiu Zhe * 5.reload the saved document and check the paragraph outline and numbering 634a089d9bSLiu Zhe */ 644a089d9bSLiu Zhe @Test testNumberingBulletIndentAtAndAlignAt()654a089d9bSLiu Zhe public void testNumberingBulletIndentAtAndAlignAt() throws Exception { 664a089d9bSLiu Zhe 674a089d9bSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 684a089d9bSLiu Zhe xText = xTextDocument.getText(); 694a089d9bSLiu Zhe xText.setString("we are Chinese,they are American.\nwe are all living in one earth!Hello,world!\nHello,world!Hello,world!Hello,world!Hello,world!\nHello,world!" + 704a089d9bSLiu Zhe "Hello,world!Hello,world!"); 714a089d9bSLiu Zhe //create cursor to select paragraph and formating paragraph 724a089d9bSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 734a089d9bSLiu Zhe //create paragraph property set 744a089d9bSLiu Zhe XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 754a089d9bSLiu Zhe //create document service factory 764a089d9bSLiu Zhe XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 774a089d9bSLiu Zhe //set numbering character 784a089d9bSLiu Zhe XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 794a089d9bSLiu Zhe PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue(),new PropertyValue()}; 804a089d9bSLiu Zhe propsRule[0].Name = "NumberingType"; 814a089d9bSLiu Zhe propsRule[0].Value = NumberingType.ARABIC; 824a089d9bSLiu Zhe propsRule[1].Name = "IndentAt"; 834a089d9bSLiu Zhe propsRule[1].Value = 499; 844a089d9bSLiu Zhe propsRule[2].Name = "FirstLineIndent"; 854a089d9bSLiu Zhe propsRule[2].Value = 199; 864a089d9bSLiu Zhe XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 874a089d9bSLiu Zhe xReplaceRule.replaceByIndex(0, propsRule); 884a089d9bSLiu Zhe //set paragraph numbering and bullet character 894a089d9bSLiu Zhe xTextProps.setPropertyValue("NumberingRules", xNumRule); 904a089d9bSLiu Zhe //save to odt 914a089d9bSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 924a089d9bSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 934a089d9bSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 944a089d9bSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 954a089d9bSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 964a089d9bSLiu Zhe aStoreProperties_odt[0].Value = true; 974a089d9bSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 984a089d9bSLiu Zhe aStoreProperties_odt[1].Value = "writer8"; 994a089d9bSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 1004a089d9bSLiu Zhe //save to doc 1014a089d9bSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 1024a089d9bSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 1034a089d9bSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 1044a089d9bSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 1054a089d9bSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 1064a089d9bSLiu Zhe aStoreProperties_doc[0].Value = true; 1074a089d9bSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 1084a089d9bSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 1094a089d9bSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 1104a089d9bSLiu Zhe app.closeDocument(xTextDocument); 1114a089d9bSLiu Zhe 1124a089d9bSLiu Zhe //reopen the document 1134a089d9bSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 1144a089d9bSLiu Zhe XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 1154a089d9bSLiu Zhe XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 1164a089d9bSLiu Zhe XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 1174a089d9bSLiu Zhe PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 1184a089d9bSLiu Zhe //verify paragraph numbering and bullet alignment 1194a089d9bSLiu Zhe assertEquals("assert numbering and bullet","IndentAt",propsRule_assert_odt[10].Name); 1204a089d9bSLiu Zhe assertEquals("assert numbering and bullet",499,propsRule_assert_odt[10].Value); 1214a089d9bSLiu Zhe assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 1224a089d9bSLiu Zhe assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value); 1234a089d9bSLiu Zhe assertEquals("assert numbering and bullet","FirstLineIndent",propsRule_assert_odt[9].Name); 1244a089d9bSLiu Zhe assertEquals("assert numbering and bullet",199,propsRule_assert_odt[9].Value); 1254a089d9bSLiu Zhe 1264a089d9bSLiu Zhe //reopen the document 1274a089d9bSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 1284a089d9bSLiu Zhe XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 1294a089d9bSLiu Zhe XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 1304a089d9bSLiu Zhe PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 1314a089d9bSLiu Zhe //verify paragraph numbering and bullet alignment 1324a089d9bSLiu Zhe assertEquals("assert numbering and bullet","IndentAt",propsRule_assert_doc[10].Name); 1334a089d9bSLiu Zhe assertEquals("assert numbering and bullet",499,propsRule_assert_doc[10].Value); 1344a089d9bSLiu Zhe assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 1354a089d9bSLiu Zhe assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value); 1364a089d9bSLiu Zhe assertEquals("assert numbering and bullet","FirstLineIndent",propsRule_assert_doc[9].Name); 1374a089d9bSLiu Zhe assertEquals("assert numbering and bullet",199,propsRule_assert_doc[9].Value); 1384a089d9bSLiu Zhe } 1394a089d9bSLiu Zhe } 140