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.puretext; 23352c0eacSLiu Zhe 24352c0eacSLiu Zhe import static org.junit.Assert.*; 25352c0eacSLiu Zhe 26352c0eacSLiu Zhe import org.junit.After; 27352c0eacSLiu Zhe import org.junit.Before; 28352c0eacSLiu Zhe import org.junit.Ignore; 29352c0eacSLiu Zhe import org.junit.Test; 30352c0eacSLiu Zhe import org.openoffice.test.common.FileUtil; 31352c0eacSLiu Zhe import org.openoffice.test.common.Testspace; 32352c0eacSLiu Zhe import org.openoffice.test.uno.UnoApp; 33352c0eacSLiu Zhe //import org.openoffice.test.vcl.Tester.*; 34352c0eacSLiu Zhe import com.sun.star.text.*; 35352c0eacSLiu Zhe import com.sun.star.beans.*; 36352c0eacSLiu Zhe import com.sun.star.frame.XStorable; 37352c0eacSLiu Zhe import com.sun.star.uno.UnoRuntime; 38352c0eacSLiu Zhe 39352c0eacSLiu Zhe public class CharacterEmphasis { 40352c0eacSLiu Zhe private static final UnoApp app = new UnoApp(); 41352c0eacSLiu Zhe XText xText = null; 42352c0eacSLiu Zhe 43352c0eacSLiu Zhe @Before setUp()44352c0eacSLiu Zhe public void setUp() throws Exception { 45352c0eacSLiu Zhe app.start(); 46352c0eacSLiu Zhe 47352c0eacSLiu Zhe } 48352c0eacSLiu Zhe 49352c0eacSLiu Zhe @After tearDown()50352c0eacSLiu Zhe public void tearDown() throws Exception { 51352c0eacSLiu Zhe app.close(); 52352c0eacSLiu Zhe } 53932de486SLiu Zhe @Test@Ignore("Bug #120657 - [testUNO patch]charmode change to disable from enable when save to doc.") testCharacterEmphasisSetting()54352c0eacSLiu Zhe public void testCharacterEmphasisSetting() throws Exception { 55352c0eacSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 56352c0eacSLiu Zhe xText = xTextDocument.getText(); 57352c0eacSLiu Zhe xText.setString("We are Chinese,they are American. We are all living in one earth!" 58352c0eacSLiu Zhe + "and we all love our home very much!!!We are Chinese,they are American. " + 59352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 60352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 61352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 62352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 63352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American." + 64352c0eacSLiu Zhe " We are all living in one earth!We are Chinese,they are American. " + 65352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 66352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 67352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 68352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 69352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 70352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 71352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 72352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 73352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 74352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 75352c0eacSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 76352c0eacSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 77352c0eacSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 78352c0eacSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 79352c0eacSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 80352c0eacSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 81352c0eacSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 82352c0eacSLiu Zhe "We are all living in one earth!"); 83352c0eacSLiu Zhe // create text cursor for selecting and formatting text 84352c0eacSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 85352c0eacSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 86352c0eacSLiu Zhe xTextCursor.gotoStart(false); 87352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 88352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", true); 89352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.ACCENT_ABOVE)); 90352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 91352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 92352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 93352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.ACCENT_BELOW)); 94352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 95352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 96352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 97352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.CIRCLE_ABOVE)); 98352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 99352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 100352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", true); 101352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.CIRCLE_BELOW)); 102352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 103352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 104352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", true); 105352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DISK_ABOVE)); 106352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 107352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 108352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 109352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DISK_BELOW)); 110352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 111352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 112352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 113352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DOT_ABOVE)); 114352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 115352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 116352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 117352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DOT_BELOW)); 118352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 119352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 120352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 121352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.NONE)); 122352c0eacSLiu Zhe //save to odt 123352c0eacSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 124352c0eacSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 125352c0eacSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 126352c0eacSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 127352c0eacSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 128352c0eacSLiu Zhe aStoreProperties_odt[0].Value = true; 129352c0eacSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 130352c0eacSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 131352c0eacSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 132352c0eacSLiu Zhe //save to doc 133352c0eacSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 134352c0eacSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 135352c0eacSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 136352c0eacSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 137352c0eacSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 138352c0eacSLiu Zhe aStoreProperties_doc[0].Value = true; 139352c0eacSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 140352c0eacSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 141352c0eacSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 142352c0eacSLiu Zhe app.closeDocument(xTextDocument); 143352c0eacSLiu Zhe 144352c0eacSLiu Zhe //reopen the document and assert character emphasis 145352c0eacSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 146352c0eacSLiu Zhe XTextCursor xTextCursor_assert_odt = assertDocument_odt.getText().createTextCursor(); 147352c0eacSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt); 148352c0eacSLiu Zhe 149352c0eacSLiu Zhe xTextCursor_assert_odt.gotoStart(false); 150352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 151352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 152352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 153352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 154352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 155352c0eacSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 156352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 157352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 158352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 159352c0eacSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 160352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 161352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 162352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 163352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 164352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 165352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 166352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 167352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 168352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 169352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 170352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 171352c0eacSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 172352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 173352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 174352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 175352c0eacSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 176352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 177352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 178352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 179352c0eacSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 180352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 181352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 182352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 183352c0eacSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 184352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.NONE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 185352c0eacSLiu Zhe 186352c0eacSLiu Zhe //reopen the document and assert character emphasis 187352c0eacSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 188352c0eacSLiu Zhe XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor(); 189352c0eacSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 190352c0eacSLiu Zhe 191352c0eacSLiu Zhe xTextCursor_assert_doc.gotoStart(false); 192352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 193352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 194352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 195352c0eacSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 196352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 197352c0eacSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 198352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 199352c0eacSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 200352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 201352c0eacSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 202352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 203352c0eacSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 204352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 205352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 206352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 207352c0eacSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 208352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 209352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 210352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 211352c0eacSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 212352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 213352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 214352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 215352c0eacSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 216352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 217352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 218352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 219352c0eacSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 220352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 221352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 222352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 223352c0eacSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 224352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 225352c0eacSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 226352c0eacSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.NONE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 227352c0eacSLiu Zhe } 228352c0eacSLiu Zhe } 229