1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package fvt.uno.sw.puretext; 23 24 import static org.junit.Assert.*; 25 26 import org.junit.After; 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.openoffice.test.common.FileUtil; 30 import org.openoffice.test.common.Testspace; 31 import org.openoffice.test.uno.UnoApp; 32 //import org.openoffice.test.vcl.Tester.*; 33 import com.sun.star.text.*; 34 import com.sun.star.beans.*; 35 import com.sun.star.frame.XStorable; 36 import com.sun.star.uno.UnoRuntime; 37 38 public class CharacterRelief { 39 private static final UnoApp app = new UnoApp(); 40 XText xText = null; 41 42 @Before setUp()43 public void setUp() throws Exception { 44 app.start(); 45 46 } 47 48 @After tearDown()49 public void tearDown() throws Exception { 50 app.close(); 51 } 52 53 @Test testCharacterReliefSetting()54 public void testCharacterReliefSetting() throws Exception { 55 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 56 xText = xTextDocument.getText(); 57 xText.setString("we are Chinese,they are American.We are all living in one earth!" 58 + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!" 59 + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!" 60 + "and we all love our home very much!!!"); 61 // create text cursor for selecting and formatting text 62 XTextCursor xTextCursor = xText.createTextCursor(); 63 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 64 xTextCursor.gotoStart(false); 65 xTextCursor.goRight((short) 102, true); 66 xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.EMBOSSED)); 67 xTextCursor.gotoRange(xTextCursor, false); 68 xTextCursor.goRight((short) 102, true); 69 xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.ENGRAVED)); 70 xTextCursor.gotoRange(xTextCursor, false); 71 xTextCursor.goRight((short) 102, true); 72 xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.NONE)); 73 //save to odt 74 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 75 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 76 aStoreProperties_odt[0] = new PropertyValue(); 77 aStoreProperties_odt[1] = new PropertyValue(); 78 aStoreProperties_odt[0].Name = "Override"; 79 aStoreProperties_odt[0].Value = true; 80 aStoreProperties_odt[1].Name = "FilterName"; 81 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 82 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 83 //save to doc 84 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 85 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 86 aStoreProperties_doc[0] = new PropertyValue(); 87 aStoreProperties_doc[1] = new PropertyValue(); 88 aStoreProperties_doc[0].Name = "Override"; 89 aStoreProperties_doc[0].Value = true; 90 aStoreProperties_doc[1].Name = "FilterName"; 91 aStoreProperties_doc[1].Value = "MS Word 97"; 92 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 93 app.closeDocument(xTextDocument); 94 95 //reopen the document and assert row height setting 96 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 97 XTextCursor xTextCursor_assert_odt=assertDocument_odt.getText().createTextCursor(); 98 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt); 99 //verify set property 100 xTextCursor_assert_odt.gotoStart(false); 101 xTextCursor_assert_odt.goRight((short) 102, true); 102 assertEquals("assert character relief",com.sun.star.text.FontRelief.EMBOSSED,xCursorProps_assert_odt.getPropertyValue("CharRelief")); 103 xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 104 xTextCursor_assert_odt.goRight((short) 102, true); 105 assertEquals("assert character relief",com.sun.star.text.FontRelief.ENGRAVED,xCursorProps_assert_odt.getPropertyValue("CharRelief")); 106 xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 107 xTextCursor_assert_odt.goRight((short) 102, true); 108 assertEquals("assert character relief",com.sun.star.text.FontRelief.NONE,xCursorProps_assert_odt.getPropertyValue("CharRelief")); 109 110 //reopen the document and assert row height setting 111 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 112 XTextCursor xTextCursor_assert_doc=assertDocument_doc.getText().createTextCursor(); 113 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 114 //verify set property 115 xTextCursor_assert_doc.gotoStart(false); 116 xTextCursor_assert_doc.goRight((short) 102, true); 117 assertEquals("assert character relief",com.sun.star.text.FontRelief.EMBOSSED,xCursorProps_assert_doc.getPropertyValue("CharRelief")); 118 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 119 xTextCursor_assert_doc.goRight((short) 102, true); 120 assertEquals("assert character relief",com.sun.star.text.FontRelief.ENGRAVED,xCursorProps_assert_doc.getPropertyValue("CharRelief")); 121 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 122 xTextCursor_assert_doc.goRight((short) 102, true); 123 assertEquals("assert character relief",com.sun.star.text.FontRelief.NONE,xCursorProps_assert_doc.getPropertyValue("CharRelief")); 124 } 125 } 126