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; 23eba4d44aSLiu Zhe 24eba4d44aSLiu Zhe import static org.junit.Assert.*; 25eba4d44aSLiu Zhe 26eba4d44aSLiu Zhe import org.junit.After; 27eba4d44aSLiu Zhe import org.junit.Before; 28eba4d44aSLiu Zhe import org.junit.Ignore; 29eba4d44aSLiu Zhe import org.junit.Test; 30eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil; 31eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace; 32eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 33eba4d44aSLiu Zhe //import org.openoffice.test.vcl.Tester.*; 34eba4d44aSLiu Zhe import com.sun.star.text.*; 35eba4d44aSLiu Zhe import com.sun.star.beans.*; 36eba4d44aSLiu Zhe import com.sun.star.frame.XStorable; 37eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime; 38eba4d44aSLiu Zhe 39eba4d44aSLiu Zhe public class CharacterEmphasis { 40eba4d44aSLiu Zhe private static final UnoApp app = new UnoApp(); 41eba4d44aSLiu Zhe XText xText = null; 42eba4d44aSLiu Zhe 43eba4d44aSLiu Zhe @Before setUp()44eba4d44aSLiu Zhe public void setUp() throws Exception { 45eba4d44aSLiu Zhe app.start(); 46eba4d44aSLiu Zhe 47eba4d44aSLiu Zhe } 48eba4d44aSLiu Zhe 49eba4d44aSLiu Zhe @After tearDown()50eba4d44aSLiu Zhe public void tearDown() throws Exception { 51eba4d44aSLiu Zhe app.close(); 52eba4d44aSLiu Zhe } 53eba4d44aSLiu Zhe @Test@Ignore("Bug #120657 - [testUNO patch]charmode change to disable from enable when save to doc.") testCharacterEmphasisSetting()54eba4d44aSLiu Zhe public void testCharacterEmphasisSetting() throws Exception { 55eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 56eba4d44aSLiu Zhe xText = xTextDocument.getText(); 57eba4d44aSLiu Zhe xText.setString("We are Chinese,they are American. We are all living in one earth!" 58eba4d44aSLiu Zhe + "and we all love our home very much!!!We are Chinese,they are American. " + 59eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 60eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 61eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 62eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 63eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American." + 64eba4d44aSLiu Zhe " We are all living in one earth!We are Chinese,they are American. " + 65eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 66eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 67eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 68eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 69eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 70eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 71eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 72eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 73eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 74eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 75eba4d44aSLiu Zhe "We are all living in one earth!We are Chinese,they are American. " + 76eba4d44aSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 77eba4d44aSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 78eba4d44aSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 79eba4d44aSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 80eba4d44aSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 81eba4d44aSLiu Zhe "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 82eba4d44aSLiu Zhe "We are all living in one earth!"); 83eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 84eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 85eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 86eba4d44aSLiu Zhe xTextCursor.gotoStart(false); 87eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 88eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", true); 89eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.ACCENT_ABOVE)); 90eba4d44aSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 91eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 92eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 93eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.ACCENT_BELOW)); 94eba4d44aSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 95eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 96eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 97eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.CIRCLE_ABOVE)); 98eba4d44aSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 99eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 100eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", true); 101eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.CIRCLE_BELOW)); 102eba4d44aSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 103eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 104eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", true); 105eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DISK_ABOVE)); 106eba4d44aSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 107eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 108eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 109eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DISK_BELOW)); 110eba4d44aSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 111eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 112eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 113eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DOT_ABOVE)); 114eba4d44aSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 115eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 116eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 117eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.DOT_BELOW)); 118eba4d44aSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 119eba4d44aSLiu Zhe xTextCursor.goRight((short) 100, true); 120eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharWordMode", false); 121eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharEmphasis", new Short(com.sun.star.text.FontEmphasis.NONE)); 122eba4d44aSLiu Zhe //save to odt 123eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 124eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 125eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 126eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 127eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 128eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 129eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 130eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 131eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 132eba4d44aSLiu Zhe //save to doc 133eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 134eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 135eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 136eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 137eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 138eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 139eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 140eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 141eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 142eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 143eba4d44aSLiu Zhe 144eba4d44aSLiu Zhe //reopen the document and assert character emphasis 145eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 146eba4d44aSLiu Zhe XTextCursor xTextCursor_assert_odt = assertDocument_odt.getText().createTextCursor(); 147eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt); 148eba4d44aSLiu Zhe 149eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoStart(false); 150eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 151eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 152eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 153eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 154eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 155eba4d44aSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 156eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 157eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 158eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 159eba4d44aSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 160eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 161eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 162eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 163eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 164eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 165eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 166eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 167eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 168eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 169eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 170eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 171eba4d44aSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 172eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 173eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 174eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 175eba4d44aSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 176eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_ABOVE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 177eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 178eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 179eba4d44aSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 180eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_BELOW,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 181eba4d44aSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 182eba4d44aSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 183eba4d44aSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_odt.getPropertyValue("CharWordMode")); 184eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.NONE,xCursorProps_assert_odt.getPropertyValue("CharEmphasis")); 185eba4d44aSLiu Zhe 186eba4d44aSLiu Zhe //reopen the document and assert character emphasis 187eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 188eba4d44aSLiu Zhe XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor(); 189eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 190eba4d44aSLiu Zhe 191eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoStart(false); 192eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 193eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 194eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 195eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 196eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 197eba4d44aSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 198eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.ACCENT_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 199eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 200eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 201eba4d44aSLiu Zhe assertEquals("assert individual word setting",false,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 202eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 203eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 204eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 205eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 206eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.CIRCLE_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 207eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 208eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 209eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 210eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 211eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 212eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 213eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 214eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DISK_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 215eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 216eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 217eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 218eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_ABOVE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 219eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 220eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 221eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 222eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.DOT_BELOW,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 223eba4d44aSLiu Zhe xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 224eba4d44aSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 225eba4d44aSLiu Zhe assertEquals("assert individual word setting",true,xCursorProps_assert_doc.getPropertyValue("CharWordMode")); 226eba4d44aSLiu Zhe assertEquals("assert overline",com.sun.star.text.FontEmphasis.NONE,xCursorProps_assert_doc.getPropertyValue("CharEmphasis")); 227eba4d44aSLiu Zhe } 228eba4d44aSLiu Zhe } 229