107d7dbdcSHerbert Dürr /************************************************************** 207d7dbdcSHerbert Dürr * 307d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 407d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 507d7dbdcSHerbert Dürr * distributed with this work for additional information 607d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 707d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 807d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 907d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 1007d7dbdcSHerbert Dürr * 1107d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 1207d7dbdcSHerbert Dürr * 1307d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 1407d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 1507d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1607d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 1707d7dbdcSHerbert Dürr * specific language governing permissions and limitations 1807d7dbdcSHerbert Dürr * under the License. 1907d7dbdcSHerbert Dürr * 2007d7dbdcSHerbert Dürr *************************************************************/ 2107d7dbdcSHerbert Dürr 22eba4d44aSLiu Zhe package fvt.uno.sw.paragraph; 23eba4d44aSLiu Zhe 24eba4d44aSLiu Zhe import static org.junit.Assert.*; 25eba4d44aSLiu Zhe 26eba4d44aSLiu Zhe import org.junit.After; 27eba4d44aSLiu Zhe import org.junit.Before; 28eba4d44aSLiu Zhe import org.junit.Ignore; 29eba4d44aSLiu Zhe import org.junit.Test; 30eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil; 31eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace; 32eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 33eba4d44aSLiu Zhe 34eba4d44aSLiu Zhe import com.sun.star.style.NumberingType; 35eba4d44aSLiu Zhe import com.sun.star.text.*; 36eba4d44aSLiu Zhe import com.sun.star.beans.*; 37eba4d44aSLiu Zhe import com.sun.star.container.XIndexAccess; 38eba4d44aSLiu Zhe import com.sun.star.container.XIndexReplace; 39eba4d44aSLiu Zhe import com.sun.star.frame.XStorable; 40eba4d44aSLiu Zhe import com.sun.star.lang.XMultiServiceFactory; 41eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime; 42eba4d44aSLiu Zhe 43eba4d44aSLiu Zhe public class ParagraphNumberingAndBullet_CharacterBullet { 44eba4d44aSLiu Zhe private static final UnoApp app = new UnoApp(); 45eba4d44aSLiu Zhe XText xText = null; 46eba4d44aSLiu Zhe 47eba4d44aSLiu Zhe @Before setUp()48eba4d44aSLiu Zhe public void setUp() throws Exception { 49eba4d44aSLiu Zhe app.start(); 50eba4d44aSLiu Zhe 51eba4d44aSLiu Zhe } 52eba4d44aSLiu Zhe 53eba4d44aSLiu Zhe @After tearDown()54eba4d44aSLiu Zhe public void tearDown() throws Exception { 55eba4d44aSLiu Zhe //app.close(); 56eba4d44aSLiu Zhe } 57eba4d44aSLiu Zhe /* 58eba4d44aSLiu Zhe * test paragraph background color 59eba4d44aSLiu Zhe * 1.new a text document 60eba4d44aSLiu Zhe * 2.insert some text 61eba4d44aSLiu Zhe * 3.set paragraph bullet 62eba4d44aSLiu Zhe * 4.save and close the document 63eba4d44aSLiu Zhe * 5.reload the saved document and check the paragraph bullet 64eba4d44aSLiu Zhe */ 65eba4d44aSLiu Zhe @Test @Ignore("Bug #120963 - [testUNO patch]the bullet character font style change to other font style character when save to doc.") testNumberingAndBullet_CharacterBullet1()66eba4d44aSLiu Zhe public void testNumberingAndBullet_CharacterBullet1() throws Exception { 67eba4d44aSLiu Zhe 68eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 69eba4d44aSLiu Zhe xText = xTextDocument.getText(); 70eba4d44aSLiu 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!" + 71eba4d44aSLiu Zhe "Hello,world!Hello,world!"); 72*06fb39a1SJohn Bampton //create cursor to select paragraph and formatting paragraph 73eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 74eba4d44aSLiu Zhe //create paragraph property set 75eba4d44aSLiu Zhe XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 76eba4d44aSLiu Zhe //create document service factory 77eba4d44aSLiu Zhe XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 78eba4d44aSLiu Zhe //set numbering character 79eba4d44aSLiu Zhe XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 80eba4d44aSLiu Zhe PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()}; 81eba4d44aSLiu Zhe propsRule[0].Name = "NumberingType"; 82eba4d44aSLiu Zhe propsRule[0].Value = NumberingType.CHAR_SPECIAL; 83eba4d44aSLiu Zhe propsRule[1].Name = "BulletId"; 84eba4d44aSLiu Zhe propsRule[1].Value = (short)8226; 85eba4d44aSLiu Zhe XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 86eba4d44aSLiu Zhe xReplaceRule.replaceByIndex(0, propsRule); 87eba4d44aSLiu Zhe //set paragraph numbering and bullet character 88eba4d44aSLiu Zhe xTextProps.setPropertyValue("NumberingRules", xNumRule); 89eba4d44aSLiu Zhe //save to odt 90eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 91eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 92eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 93eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 94eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 95eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 96eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 97eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "writer8"; 98eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 99eba4d44aSLiu Zhe //save to doc 100eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 101eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 102eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 103eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 104eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 105eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 106eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 107eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 108eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 109eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 110eba4d44aSLiu Zhe 111eba4d44aSLiu Zhe //reopen the document 112eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 113eba4d44aSLiu Zhe XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 114eba4d44aSLiu Zhe XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 115eba4d44aSLiu Zhe XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 116eba4d44aSLiu Zhe PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 117eba4d44aSLiu Zhe //verify paragraph numbering and bullet alignment 118eba4d44aSLiu Zhe assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 119eba4d44aSLiu Zhe assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_odt[11].Value); 120eba4d44aSLiu Zhe assertEquals("assert numbering and bullet","BulletId",propsRule_assert_odt[12].Name); 121eba4d44aSLiu Zhe assertEquals("assert numbering and bullet",(short)8226,propsRule_assert_odt[12].Value); 122eba4d44aSLiu Zhe 123eba4d44aSLiu Zhe //reopen the document 124eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 125eba4d44aSLiu Zhe XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 126eba4d44aSLiu Zhe XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 127eba4d44aSLiu Zhe PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 128eba4d44aSLiu Zhe //verify paragraph numbering and bullet alignment 129eba4d44aSLiu Zhe assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 130eba4d44aSLiu Zhe assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value); 131eba4d44aSLiu Zhe assertEquals("assert numbering and bullet","BulletId",propsRule_assert_doc[12].Name); 132eba4d44aSLiu Zhe assertEquals("assert numbering and bullet",(short)8226,propsRule_assert_doc[12].Value); 133eba4d44aSLiu Zhe } 134eba4d44aSLiu Zhe @Test @Ignore("Bug #120963 - [testUNO patch]the bullet character font style change to other font style character when save to doc.") testNumberingAndBullet_CharacterBullet2()135eba4d44aSLiu Zhe public void testNumberingAndBullet_CharacterBullet2() throws Exception { 136eba4d44aSLiu Zhe 137eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 138eba4d44aSLiu Zhe xText = xTextDocument.getText(); 139eba4d44aSLiu 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!" + 140eba4d44aSLiu Zhe "Hello,world!Hello,world!"); 141*06fb39a1SJohn Bampton //create cursor to select paragraph and formatting paragraph 142eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 143eba4d44aSLiu Zhe //create paragraph property set 144eba4d44aSLiu Zhe XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 145eba4d44aSLiu Zhe //create document service factory 146eba4d44aSLiu Zhe XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 147eba4d44aSLiu Zhe //set numbering character 148eba4d44aSLiu Zhe XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 149eba4d44aSLiu Zhe PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()}; 150eba4d44aSLiu Zhe propsRule[0].Name = "NumberingType"; 151eba4d44aSLiu Zhe propsRule[0].Value = NumberingType.CHAR_SPECIAL; 152eba4d44aSLiu Zhe propsRule[1].Name = "BulletId"; 153eba4d44aSLiu Zhe propsRule[1].Value = (short)9679; 154eba4d44aSLiu Zhe XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 155eba4d44aSLiu Zhe xReplaceRule.replaceByIndex(0, propsRule); 156eba4d44aSLiu Zhe //set paragraph numbering and bullet character 157eba4d44aSLiu Zhe xTextProps.setPropertyValue("NumberingRules", xNumRule); 158eba4d44aSLiu Zhe //save to odt 159eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 160eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 161eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 162eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 163eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 164eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 165eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 166eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "writer8"; 167eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 168eba4d44aSLiu Zhe //save to doc 169eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 170eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 171eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 172eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 173eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 174eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 175eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 176eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 177eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 178eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 179eba4d44aSLiu Zhe 180eba4d44aSLiu Zhe //reopen the document 181eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 182eba4d44aSLiu Zhe XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 183eba4d44aSLiu Zhe XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 184eba4d44aSLiu Zhe XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 185eba4d44aSLiu Zhe PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 186eba4d44aSLiu Zhe //verify paragraph numbering and bullet alignment 187eba4d44aSLiu Zhe assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 188eba4d44aSLiu Zhe assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_odt[11].Value); 189eba4d44aSLiu Zhe assertEquals("assert numbering and bullet","BulletId",propsRule_assert_odt[12].Name); 190eba4d44aSLiu Zhe assertEquals("assert numbering and bullet",(short)9679,propsRule_assert_odt[12].Value); 191eba4d44aSLiu Zhe 192eba4d44aSLiu Zhe //reopen the document 193eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 194eba4d44aSLiu Zhe XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 195eba4d44aSLiu Zhe XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 196eba4d44aSLiu Zhe PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 197eba4d44aSLiu Zhe //verify paragraph numbering and bullet alignment 198eba4d44aSLiu Zhe assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 199eba4d44aSLiu Zhe assertEquals("assert numbering and bullet",NumberingType.CHAR_SPECIAL,propsRule_assert_doc[11].Value); 200eba4d44aSLiu Zhe assertEquals("assert numbering and bullet","BulletId",propsRule_assert_doc[12].Name); 201eba4d44aSLiu Zhe assertEquals("assert numbering and bullet",(short)9679,propsRule_assert_doc[12].Value); 202eba4d44aSLiu Zhe } 203eba4d44aSLiu Zhe } 204