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.Ignore; 29 import org.junit.Test; 30 import org.openoffice.test.common.FileUtil; 31 import org.openoffice.test.common.Testspace; 32 import org.openoffice.test.uno.UnoApp; 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 CharacterPosition { 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 testCharacterSuperscriptSetting()54 public void testCharacterSuperscriptSetting() 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!!!"); 59 // create text cursor for selecting and formatting text 60 XTextCursor xTextCursor = xText.createTextCursor(); 61 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 62 xTextCursor.gotoStart(false); 63 xTextCursor.goRight((short) 102, true); 64 xCursorProps.setPropertyValue("CharEscapement", (short)29); 65 xCursorProps.setPropertyValue("CharEscapementHeight", (byte)50); 66 //save to odt 67 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 68 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 69 aStoreProperties_odt[0] = new PropertyValue(); 70 aStoreProperties_odt[1] = new PropertyValue(); 71 aStoreProperties_odt[0].Name = "Override"; 72 aStoreProperties_odt[0].Value = true; 73 aStoreProperties_odt[1].Name = "FilterName"; 74 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 75 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 76 //save to doc 77 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 78 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 79 aStoreProperties_doc[0] = new PropertyValue(); 80 aStoreProperties_doc[1] = new PropertyValue(); 81 aStoreProperties_doc[0].Name = "Override"; 82 aStoreProperties_doc[0].Value = true; 83 aStoreProperties_doc[1].Name = "FilterName"; 84 aStoreProperties_doc[1].Value = "MS Word 97"; 85 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 86 app.closeDocument(xTextDocument); 87 88 //reopen the document and assert character position setting 89 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 90 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 91 //verify set property 92 assertEquals("assert character position",(short)29,xCursorProps_assert_odt.getPropertyValue("CharEscapement")); 93 assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight")); 94 95 //reopen the document and assert character position setting 96 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 97 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 98 //verify set property 99 assertEquals("assert character position",(short)29,xCursorProps_assert_doc.getPropertyValue("CharEscapement")); 100 assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight")); 101 } 102 @Test@Ignore("Bug #120674 - [testUNO patch]the lower and relative font size value of subscript change when save to doc.") testCharacterSubscriptSetting()103 public void testCharacterSubscriptSetting() throws Exception { 104 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 105 xText = xTextDocument.getText(); 106 xText.setString("we are Chinese,they are American.We are all living in one earth!" 107 + "and we all love our home very much!!!"); 108 // create text cursor for selecting and formatting text 109 XTextCursor xTextCursor = xText.createTextCursor(); 110 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 111 xTextCursor.gotoStart(false); 112 xTextCursor.goRight((short) 102, true); 113 xCursorProps.setPropertyValue("CharEscapement", (short)-29); 114 xCursorProps.setPropertyValue("CharEscapementHeight", (byte)50); 115 //save to odt 116 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 117 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 118 aStoreProperties_odt[0] = new PropertyValue(); 119 aStoreProperties_odt[1] = new PropertyValue(); 120 aStoreProperties_odt[0].Name = "Override"; 121 aStoreProperties_odt[0].Value = true; 122 aStoreProperties_odt[1].Name = "FilterName"; 123 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 124 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 125 //save to doc 126 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 127 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 128 aStoreProperties_doc[0] = new PropertyValue(); 129 aStoreProperties_doc[1] = new PropertyValue(); 130 aStoreProperties_doc[0].Name = "Override"; 131 aStoreProperties_doc[0].Value = true; 132 aStoreProperties_doc[1].Name = "FilterName"; 133 aStoreProperties_doc[1].Value = "MS Word 97"; 134 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 135 app.closeDocument(xTextDocument); 136 137 //reopen the document and assert character position setting 138 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 139 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 140 //verify set property 141 assertEquals("assert character position",(short)-29,xCursorProps_assert_odt.getPropertyValue("CharEscapement")); 142 assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight")); 143 144 //reopen the document and assert character position setting 145 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 146 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 147 //verify set property 148 assertEquals("assert character position",(short)-29,xCursorProps_assert_doc.getPropertyValue("CharEscapement")); 149 assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight")); 150 } 151 @Test testCharacterDefaultPositionSetting()152 public void testCharacterDefaultPositionSetting() throws Exception { 153 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 154 xText = xTextDocument.getText(); 155 xText.setString("we are Chinese,they are American.We are all living in one earth!" 156 + "and we all love our home very much!!!"); 157 // create text cursor for selecting and formatting text 158 XTextCursor xTextCursor = xText.createTextCursor(); 159 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 160 xTextCursor.gotoStart(false); 161 xTextCursor.goRight((short) 102, true); 162 xCursorProps.setPropertyValue("CharEscapement", (short)0); 163 xCursorProps.setPropertyValue("CharEscapementHeight", (byte)100); 164 //save to odt 165 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 166 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 167 aStoreProperties_odt[0] = new PropertyValue(); 168 aStoreProperties_odt[1] = new PropertyValue(); 169 aStoreProperties_odt[0].Name = "Override"; 170 aStoreProperties_odt[0].Value = true; 171 aStoreProperties_odt[1].Name = "FilterName"; 172 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 173 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 174 //save to doc 175 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 176 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 177 aStoreProperties_doc[0] = new PropertyValue(); 178 aStoreProperties_doc[1] = new PropertyValue(); 179 aStoreProperties_doc[0].Name = "Override"; 180 aStoreProperties_doc[0].Value = true; 181 aStoreProperties_doc[1].Name = "FilterName"; 182 aStoreProperties_doc[1].Value = "MS Word 97"; 183 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 184 app.closeDocument(xTextDocument); 185 186 //reopen the document and assert character position setting 187 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 188 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 189 //verify set property 190 assertEquals("assert character position",(short)0,xCursorProps_assert_odt.getPropertyValue("CharEscapement")); 191 assertEquals("assert character position",(byte)100,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight")); 192 193 //reopen the document and assert character position setting 194 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 195 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 196 //verify set property 197 assertEquals("assert character position",(short)0,xCursorProps_assert_doc.getPropertyValue("CharEscapement")); 198 assertEquals("assert character position",(byte)100,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight")); 199 } 200 } 201