1 package fvt.uno.sw.puretext; 2 3 import static org.junit.Assert.*; 4 5 import org.junit.After; 6 import org.junit.Before; 7 import org.junit.Test; 8 import org.openoffice.test.common.FileUtil; 9 import org.openoffice.test.common.Testspace; 10 import org.openoffice.test.uno.UnoApp; 11 //import org.openoffice.test.vcl.Tester.*; 12 import com.sun.star.text.*; 13 import com.sun.star.beans.*; 14 import com.sun.star.frame.XStorable; 15 import com.sun.star.uno.UnoRuntime; 16 17 public class CharacterShadow { 18 private static final UnoApp app = new UnoApp(); 19 XText xText = null; 20 21 @Before 22 public void setUp() throws Exception { 23 app.start(); 24 25 } 26 27 @After 28 public void tearDown() throws Exception { 29 app.close(); 30 } 31 32 /* 33 * test character color 34 * 1.new a text document and insert some character 35 * 2.set character shadow 36 * 3.save and reopen the document 37 * 4.check the character color 38 */ 39 @Test 40 public void testCharacterShadowSetting() throws Exception { 41 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 42 xText = xTextDocument.getText(); 43 xText.setString("we are Chinese,they are American.We are all living in one earth!" 44 + "and we all love our home very much!!!"); 45 // create text cursor for selecting and formatting text 46 XTextCursor xTextCursor = xText.createTextCursor(); 47 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 48 xTextCursor.gotoStart(false); 49 xTextCursor.goRight((short) 102, true); 50 xCursorProps.setPropertyValue("CharShadowed", true); 51 //save to odt 52 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 53 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 54 aStoreProperties_odt[0] = new PropertyValue(); 55 aStoreProperties_odt[1] = new PropertyValue(); 56 aStoreProperties_odt[0].Name = "Override"; 57 aStoreProperties_odt[0].Value = true; 58 aStoreProperties_odt[1].Name = "FilterName"; 59 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 60 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 61 //save to doc 62 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 63 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 64 aStoreProperties_doc[0] = new PropertyValue(); 65 aStoreProperties_doc[1] = new PropertyValue(); 66 aStoreProperties_doc[0].Name = "Override"; 67 aStoreProperties_doc[0].Value = true; 68 aStoreProperties_doc[1].Name = "FilterName"; 69 aStoreProperties_doc[1].Value = "MS Word 97"; 70 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 71 app.closeDocument(xTextDocument); 72 73 //reopen the document and assert row height setting 74 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 75 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 76 //verify set property 77 assertEquals("assert character shadow",true,xCursorProps_assert_odt.getPropertyValue("CharShadowed")); 78 79 //reopen the document and assert row height setting 80 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 81 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 82 //verify set property 83 assertEquals("assert character shadow",true,xCursorProps_assert_doc.getPropertyValue("CharShadowed")); 84 } 85 } 86