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; 2387127aedSLiu Zhe 2487127aedSLiu Zhe import static org.junit.Assert.*; 2587127aedSLiu Zhe 2687127aedSLiu Zhe import org.junit.After; 2787127aedSLiu Zhe import org.junit.Before; 2887127aedSLiu Zhe import org.junit.Ignore; 2987127aedSLiu Zhe import org.junit.Test; 3087127aedSLiu Zhe import org.openoffice.test.common.FileUtil; 3187127aedSLiu Zhe import org.openoffice.test.common.Testspace; 3287127aedSLiu Zhe import org.openoffice.test.uno.UnoApp; 3387127aedSLiu Zhe import com.sun.star.text.*; 3487127aedSLiu Zhe import com.sun.star.beans.*; 3587127aedSLiu Zhe import com.sun.star.frame.XStorable; 3687127aedSLiu Zhe import com.sun.star.uno.UnoRuntime; 3787127aedSLiu Zhe 3887127aedSLiu Zhe public class ParagraphIndentAndSpacing { 3987127aedSLiu Zhe private static final UnoApp app = new UnoApp(); 4087127aedSLiu Zhe XText xText = null; 4187127aedSLiu Zhe 4287127aedSLiu Zhe @Before setUp()4387127aedSLiu Zhe public void setUp() throws Exception { 4487127aedSLiu Zhe app.start(); 4587127aedSLiu Zhe 4687127aedSLiu Zhe } 4787127aedSLiu Zhe 4887127aedSLiu Zhe @After tearDown()4987127aedSLiu Zhe public void tearDown() throws Exception { 5087127aedSLiu Zhe app.close(); 5187127aedSLiu Zhe } 5287127aedSLiu Zhe /* 5387127aedSLiu Zhe * test paragraph spacing 5487127aedSLiu Zhe * 1.new a text document 5587127aedSLiu Zhe * 2.insert some text 5687127aedSLiu Zhe * 3.set paragraph spacing:before text,after text,above paragraph,below paragraph 5787127aedSLiu Zhe * 4.save to odt and close it 5887127aedSLiu Zhe * 5.reopen the saved document and check the paragraph spacing 5987127aedSLiu Zhe */ 6087127aedSLiu Zhe @Test testParagraphSpacingSetting()6187127aedSLiu Zhe public void testParagraphSpacingSetting() throws Exception { 6287127aedSLiu Zhe 6387127aedSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 6487127aedSLiu Zhe xText = xTextDocument.getText(); 6587127aedSLiu 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!" + 6687127aedSLiu Zhe "Hello,world!Hello,world!"); 6787127aedSLiu Zhe // create text cursor for selecting and formatting text 6887127aedSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 6987127aedSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 7087127aedSLiu Zhe //set paragraph margin with page border 7187127aedSLiu Zhe xCursorProps.setPropertyValue("ParaLeftMargin",2000); 7287127aedSLiu Zhe xCursorProps.setPropertyValue("ParaRightMargin",3000); 7387127aedSLiu Zhe xCursorProps.setPropertyValue("ParaTopMargin",1000); 7487127aedSLiu Zhe xCursorProps.setPropertyValue("ParaBottomMargin",4000); 7587127aedSLiu Zhe xCursorProps.setPropertyValue("ParaFirstLineIndent",4000); 7687127aedSLiu Zhe 7787127aedSLiu Zhe //save to odt 7887127aedSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 7987127aedSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 8087127aedSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 8187127aedSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 8287127aedSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 8387127aedSLiu Zhe aStoreProperties_odt[0].Value = true; 8487127aedSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 8587127aedSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 8687127aedSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 8787127aedSLiu Zhe //save to doc 8887127aedSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 8987127aedSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 9087127aedSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 9187127aedSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 9287127aedSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 9387127aedSLiu Zhe aStoreProperties_doc[0].Value = true; 9487127aedSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 9587127aedSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 9687127aedSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 9787127aedSLiu Zhe app.closeDocument(xTextDocument); 9887127aedSLiu Zhe 9987127aedSLiu Zhe //reopen the document and assert line spacing 10087127aedSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 10187127aedSLiu Zhe XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 10287127aedSLiu Zhe //verify paragraph indent and spacing 10387127aedSLiu Zhe assertEquals("assert before text margin",2000,xCursorProps_Assert_odt.getPropertyValue("ParaLeftMargin")); 10487127aedSLiu Zhe assertEquals("assert after text margin",3000,xCursorProps_Assert_odt.getPropertyValue("ParaRightMargin")); 10587127aedSLiu Zhe assertEquals("assert above paragraph margin",1000,xCursorProps_Assert_odt.getPropertyValue("ParaTopMargin")); 10687127aedSLiu Zhe assertEquals("assert below paragraph margin",4001,xCursorProps_Assert_odt.getPropertyValue("ParaBottomMargin")); 10787127aedSLiu Zhe assertEquals("assert first line indent",4001,xCursorProps_Assert_odt.getPropertyValue("ParaFirstLineIndent")); 10887127aedSLiu Zhe assertEquals("assert paragraph first line is no autoindent",false,xCursorProps_Assert_odt.getPropertyValue("ParaIsAutoFirstLineIndent")); 10987127aedSLiu Zhe 11087127aedSLiu Zhe //reopen the document and assert line spacing 11187127aedSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 11287127aedSLiu Zhe XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 11387127aedSLiu Zhe //verify paragraph indent and spacing 11487127aedSLiu Zhe assertEquals("assert before text margin",2000,xCursorProps_Assert_doc.getPropertyValue("ParaLeftMargin")); 11587127aedSLiu Zhe assertEquals("assert after text margin",3000,xCursorProps_Assert_doc.getPropertyValue("ParaRightMargin")); 11687127aedSLiu Zhe assertEquals("assert above paragraph margin",1000,xCursorProps_Assert_doc.getPropertyValue("ParaTopMargin")); 11787127aedSLiu Zhe assertEquals("assert below paragraph margin",4001,xCursorProps_Assert_doc.getPropertyValue("ParaBottomMargin")); 11887127aedSLiu Zhe assertEquals("assert first line indent",4001,xCursorProps_Assert_doc.getPropertyValue("ParaFirstLineIndent")); 11987127aedSLiu Zhe assertEquals("assert paragraph first line is no autoindent",false,xCursorProps_Assert_doc.getPropertyValue("ParaIsAutoFirstLineIndent")); 12087127aedSLiu Zhe } 121af986861SLiu Zhe @Test@Ignore("Bug #120646 - [testUNO patch]the auto indent effect of first line lost when save to doc") testParagraphIndent()12287127aedSLiu Zhe public void testParagraphIndent() throws Exception { 12387127aedSLiu Zhe 12487127aedSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 12587127aedSLiu Zhe xText = xTextDocument.getText(); 12687127aedSLiu 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!" + 12787127aedSLiu Zhe "Hello,world!Hello,world!"); 12887127aedSLiu Zhe // create text cursor for selecting and formatting text 12987127aedSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 13087127aedSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 13187127aedSLiu Zhe //set paragraph margin with page border 13287127aedSLiu Zhe xCursorProps.setPropertyValue("ParaIsAutoFirstLineIndent",true); 13387127aedSLiu Zhe 13487127aedSLiu Zhe //save to odt 13587127aedSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 13687127aedSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 13787127aedSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 13887127aedSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 13987127aedSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 14087127aedSLiu Zhe aStoreProperties_odt[0].Value = true; 14187127aedSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 14287127aedSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 14387127aedSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 14487127aedSLiu Zhe //save to doc 14587127aedSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 14687127aedSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 14787127aedSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 14887127aedSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 14987127aedSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 15087127aedSLiu Zhe aStoreProperties_doc[0].Value = true; 15187127aedSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 15287127aedSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 15387127aedSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 15487127aedSLiu Zhe app.closeDocument(xTextDocument); 15587127aedSLiu Zhe 15687127aedSLiu Zhe 15787127aedSLiu Zhe //reopen the document and assert paragraph indent 15887127aedSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 15987127aedSLiu Zhe XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 16087127aedSLiu Zhe //verify paragraph auto indent 16187127aedSLiu Zhe assertEquals("assert paragraph first line is autoindent",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsAutoFirstLineIndent")); 16287127aedSLiu Zhe 16387127aedSLiu Zhe //reopen the document and assert paragraph indent 16487127aedSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 16587127aedSLiu Zhe XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 16687127aedSLiu Zhe //verify paragraph auto indent 16787127aedSLiu Zhe assertEquals("assert paragraph first line is autoindent",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsAutoFirstLineIndent")); 16887127aedSLiu Zhe } 16987127aedSLiu Zhe 17087127aedSLiu Zhe } 171