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