107d7dbdcSHerbert Dürr /************************************************************** 207d7dbdcSHerbert Dürr * 307d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 407d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 507d7dbdcSHerbert Dürr * distributed with this work for additional information 607d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 707d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 807d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 907d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 1007d7dbdcSHerbert Dürr * 1107d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 1207d7dbdcSHerbert Dürr * 1307d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 1407d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 1507d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1607d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 1707d7dbdcSHerbert Dürr * specific language governing permissions and limitations 1807d7dbdcSHerbert Dürr * under the License. 1907d7dbdcSHerbert Dürr * 2007d7dbdcSHerbert Dürr *************************************************************/ 2107d7dbdcSHerbert 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.Test; 29352c0eacSLiu Zhe import org.openoffice.test.common.FileUtil; 30352c0eacSLiu Zhe import org.openoffice.test.common.Testspace; 31352c0eacSLiu Zhe import org.openoffice.test.uno.UnoApp; 32352c0eacSLiu Zhe import com.sun.star.text.*; 33352c0eacSLiu Zhe import com.sun.star.beans.*; 34352c0eacSLiu Zhe import com.sun.star.frame.XStorable; 35352c0eacSLiu Zhe import com.sun.star.uno.UnoRuntime; 36352c0eacSLiu Zhe 37352c0eacSLiu Zhe 38352c0eacSLiu Zhe public class CharacterStrikeThrough { 39352c0eacSLiu Zhe private static final UnoApp app = new UnoApp(); 40352c0eacSLiu Zhe XText xText = null; 41352c0eacSLiu Zhe 42352c0eacSLiu Zhe @Before setUp()43352c0eacSLiu Zhe public void setUp() throws Exception { 44352c0eacSLiu Zhe app.start(); 45352c0eacSLiu Zhe 46352c0eacSLiu Zhe } 47352c0eacSLiu Zhe 48352c0eacSLiu Zhe @After tearDown()49352c0eacSLiu Zhe public void tearDown() throws Exception { 50352c0eacSLiu Zhe app.close(); 51352c0eacSLiu Zhe } 52352c0eacSLiu Zhe 53*44cf0280SCarl Marcum @Test testCharacterStrikeThroughSetting()54352c0eacSLiu Zhe public void testCharacterStrikeThroughSetting() 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.We are all living in one earth!" 59352c0eacSLiu Zhe + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!" 60352c0eacSLiu Zhe + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!" 61352c0eacSLiu Zhe + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!" 62352c0eacSLiu Zhe + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!" 63352c0eacSLiu Zhe + "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!" 64352c0eacSLiu Zhe + "and we all love our home very much!!!"); 65352c0eacSLiu Zhe // create text cursor for selecting and formatting text 66352c0eacSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 67352c0eacSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 68352c0eacSLiu Zhe xTextCursor.gotoStart(false); 69352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 70352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.BOLD)); 71352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 72352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 73352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.DONTKNOW)); 74352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 75352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 76352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.DOUBLE)); 77352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 78352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 79352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.NONE)); 80352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 81352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 82352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.SINGLE)); 83352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 84352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 85352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.SLASH)); 86352c0eacSLiu Zhe xTextCursor.gotoRange(xTextCursor, false); 87352c0eacSLiu Zhe xTextCursor.goRight((short) 100, true); 88352c0eacSLiu Zhe xCursorProps.setPropertyValue("CharStrikeout", new Short(com.sun.star.awt.FontStrikeout.X)); 89352c0eacSLiu Zhe //save to odt 90352c0eacSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 91352c0eacSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 92352c0eacSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 93352c0eacSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 94352c0eacSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 95352c0eacSLiu Zhe aStoreProperties_odt[0].Value = true; 96352c0eacSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 97352c0eacSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 98352c0eacSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 99352c0eacSLiu Zhe //save to doc 100352c0eacSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 101352c0eacSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 102352c0eacSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 103352c0eacSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 104352c0eacSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 105352c0eacSLiu Zhe aStoreProperties_doc[0].Value = true; 106352c0eacSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 107352c0eacSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 108352c0eacSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 109352c0eacSLiu Zhe app.closeDocument(xTextDocument); 110352c0eacSLiu Zhe 111352c0eacSLiu Zhe //reopen the document and assert row height setting 112352c0eacSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 113352c0eacSLiu Zhe XTextCursor xTextCursor_assert_odt=assertDocument_odt.getText().createTextCursor(); 114352c0eacSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt); 115352c0eacSLiu Zhe //verify set property 116352c0eacSLiu Zhe xTextCursor_assert_odt.gotoStart(false); 117352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 118352c0eacSLiu Zhe assertEquals("assert strikethrough is bold",com.sun.star.awt.FontStrikeout.BOLD,xCursorProps_assert_odt.getPropertyValue("CharStrikeout")); 119352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 120352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 121352c0eacSLiu Zhe assertEquals("assert strikethrough is don'tknow",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout")); 122352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 123352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 124352c0eacSLiu Zhe assertEquals("assert strikethrough is double",com.sun.star.awt.FontStrikeout.DOUBLE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout")); 125352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 126352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 127352c0eacSLiu Zhe assertEquals("assert strikethrough is without",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout")); 128352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 129352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 130352c0eacSLiu Zhe assertEquals("assert strikethrough is single",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_odt.getPropertyValue("CharStrikeout")); 131352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 132352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 133352c0eacSLiu Zhe assertEquals("assert strikethrough is with /",com.sun.star.awt.FontStrikeout.SLASH,xCursorProps_assert_odt.getPropertyValue("CharStrikeout")); 134352c0eacSLiu Zhe xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false); 135352c0eacSLiu Zhe xTextCursor_assert_odt.goRight((short) 100, true); 136352c0eacSLiu Zhe assertEquals("assert strikethrough is with X",com.sun.star.awt.FontStrikeout.X,xCursorProps_assert_odt.getPropertyValue("CharStrikeout")); 137352c0eacSLiu Zhe 138352c0eacSLiu Zhe //reopen the document and assert row height setting 139352c0eacSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 140352c0eacSLiu Zhe XTextCursor xTextCursor_assert_doc=assertDocument_doc.getText().createTextCursor(); 141352c0eacSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 142352c0eacSLiu Zhe //verify set property 143*44cf0280SCarl Marcum // Bug #120656 - [testUNO patch]bold,/,X strike through change to single when save to doc 144352c0eacSLiu Zhe xTextCursor_assert_doc.gotoStart(false); 145352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 146*44cf0280SCarl Marcum assertEquals("for .doc assert strikethrough is SINGLE instead of bold",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout")); 147*44cf0280SCarl Marcum xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 148352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 149*44cf0280SCarl Marcum assertEquals("for .doc assert strikethrough is SINGLE instead of don'tknow",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout")); 150*44cf0280SCarl Marcum xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 151352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 152352c0eacSLiu Zhe assertEquals("assert strikethrough is double",com.sun.star.awt.FontStrikeout.DOUBLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout")); 153*44cf0280SCarl Marcum xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 154352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 155352c0eacSLiu Zhe assertEquals("assert strikethrough is without",com.sun.star.awt.FontStrikeout.NONE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout")); 156*44cf0280SCarl Marcum xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 157352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 158352c0eacSLiu Zhe assertEquals("assert strikethrough is single",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout")); 159*44cf0280SCarl Marcum xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 160352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 161*44cf0280SCarl Marcum assertEquals("for .doc assert strikethrough is SINGLE instead of /",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout")); 162*44cf0280SCarl Marcum xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 163352c0eacSLiu Zhe xTextCursor_assert_doc.goRight((short) 100, true); 164*44cf0280SCarl Marcum assertEquals("for .doc assert strikethrough is SINGLE instead of X",com.sun.star.awt.FontStrikeout.SINGLE,xCursorProps_assert_doc.getPropertyValue("CharStrikeout")); 165352c0eacSLiu Zhe } 166352c0eacSLiu Zhe } 167