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.Test; 2987127aedSLiu Zhe import org.openoffice.test.common.FileUtil; 3087127aedSLiu Zhe import org.openoffice.test.common.Testspace; 3187127aedSLiu Zhe import org.openoffice.test.uno.UnoApp; 3287127aedSLiu Zhe import com.sun.star.text.*; 3387127aedSLiu Zhe import com.sun.star.beans.*; 3487127aedSLiu Zhe import com.sun.star.frame.XStorable; 3587127aedSLiu Zhe import com.sun.star.uno.UnoRuntime; 3687127aedSLiu Zhe 3787127aedSLiu Zhe public class ParagraphBackColor { 3887127aedSLiu Zhe private static final UnoApp app = new UnoApp(); 3987127aedSLiu Zhe XText xText = null; 4087127aedSLiu Zhe 4187127aedSLiu Zhe @Before setUp()4287127aedSLiu Zhe public void setUp() throws Exception { 4387127aedSLiu Zhe app.start(); 4487127aedSLiu Zhe 4587127aedSLiu Zhe } 4687127aedSLiu Zhe 4787127aedSLiu Zhe @After tearDown()4887127aedSLiu Zhe public void tearDown() throws Exception { 4987127aedSLiu Zhe app.close(); 5087127aedSLiu Zhe } 5187127aedSLiu Zhe /* 5287127aedSLiu Zhe * test paragraph background color 5387127aedSLiu Zhe * 1.new a text document 5487127aedSLiu Zhe * 2.insert some text 5587127aedSLiu Zhe * 3.set paragraph background with color 5687127aedSLiu Zhe * 4.save and close the document 5787127aedSLiu Zhe * 5.reload the saved document and check the paragraph background color 5887127aedSLiu Zhe */ 5987127aedSLiu Zhe @Test testParagraphBackColorSetting()6087127aedSLiu Zhe public void testParagraphBackColorSetting() throws Exception { 6187127aedSLiu Zhe 6287127aedSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 6387127aedSLiu Zhe xText = xTextDocument.getText(); 6487127aedSLiu 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!" + 6587127aedSLiu Zhe "Hello,world!Hello,world!"); 6687127aedSLiu Zhe // create text cursor for selecting and formatting text 6787127aedSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 6887127aedSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 6987127aedSLiu Zhe //set paragraph background color 7087127aedSLiu Zhe xCursorProps.setPropertyValue("ParaBackColor",0x0000FF00); 7187127aedSLiu Zhe //save to odt 7287127aedSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 7387127aedSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 7487127aedSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 7587127aedSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 7687127aedSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 7787127aedSLiu Zhe aStoreProperties_odt[0].Value = true; 7887127aedSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 7987127aedSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 8087127aedSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 8187127aedSLiu Zhe //save to doc 8287127aedSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 8387127aedSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 8487127aedSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 8587127aedSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 8687127aedSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 8787127aedSLiu Zhe aStoreProperties_doc[0].Value = true; 8887127aedSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 8987127aedSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 9087127aedSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 9187127aedSLiu Zhe app.closeDocument(xTextDocument); 9287127aedSLiu Zhe 9387127aedSLiu Zhe //reopen the document 9487127aedSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 9587127aedSLiu Zhe XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 9687127aedSLiu Zhe //verify paragraph background color 9787127aedSLiu Zhe assertEquals("assert first paragraph line spacing is fix",0x0000FF00,xCursorProps_Assert_odt.getPropertyValue("ParaBackColor")); 9887127aedSLiu Zhe 9987127aedSLiu Zhe //reopen the document 10087127aedSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 10187127aedSLiu Zhe XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 10287127aedSLiu Zhe //verify paragraph background color 10387127aedSLiu Zhe assertEquals("assert first paragraph line spacing is fix",0x0000FF00,xCursorProps_Assert_doc.getPropertyValue("ParaBackColor")); 10487127aedSLiu Zhe } 10587127aedSLiu Zhe } 106