1 package testcase.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 com.sun.star.text.*; 12 import com.sun.star.beans.*; 13 import com.sun.star.frame.XStorable; 14 import com.sun.star.uno.UnoRuntime; 15 16 public class CharacterSpacing { 17 private static final UnoApp app = new UnoApp(); 18 XText xText = null; 19 20 @Before 21 public void setUp() throws Exception { 22 app.start(); 23 24 } 25 26 @After 27 public void tearDown() throws Exception { 28 app.close(); 29 } 30 31 @Test 32 public void testCharacterSpacing_Default() throws Exception { 33 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 34 xText = xTextDocument.getText(); 35 xText.setString("we are Chinese,they are American.We are all living in one earth!" 36 + "and we all love our home very much!!!"); 37 // create text cursor for selecting and formatting text 38 XTextCursor xTextCursor = xText.createTextCursor(); 39 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 40 xTextCursor.gotoStart(false); 41 xTextCursor.goRight((short) 102, true); 42 xCursorProps.setPropertyValue("CharAutoKerning", true); 43 //save to odt 44 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 45 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 46 aStoreProperties_odt[0] = new PropertyValue(); 47 aStoreProperties_odt[1] = new PropertyValue(); 48 aStoreProperties_odt[0].Name = "Override"; 49 aStoreProperties_odt[0].Value = true; 50 aStoreProperties_odt[1].Name = "FilterName"; 51 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 52 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 53 //save to doc 54 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 55 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 56 aStoreProperties_doc[0] = new PropertyValue(); 57 aStoreProperties_doc[1] = new PropertyValue(); 58 aStoreProperties_doc[0].Name = "Override"; 59 aStoreProperties_doc[0].Value = true; 60 aStoreProperties_doc[1].Name = "FilterName"; 61 aStoreProperties_doc[1].Value = "MS Word 97"; 62 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 63 app.closeDocument(xTextDocument); 64 65 //reopen the document and assert row height setting 66 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 67 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 68 //verify set property 69 assertEquals("assert character color",true,xCursorProps_assert_odt.getPropertyValue("CharAutoKerning")); 70 71 //reopen the document and assert row height setting 72 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 73 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 74 //verify set property 75 assertEquals("assert character color",true,xCursorProps_assert_doc.getPropertyValue("CharAutoKerning")); 76 } 77 @Test 78 public void testCharacterSpacing_Expand() throws Exception { 79 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 80 xText = xTextDocument.getText(); 81 xText.setString("we are Chinese,they are American.We are all living in one earth!" 82 + "and we all love our home very much!!!"); 83 // create text cursor for selecting and formatting text 84 XTextCursor xTextCursor = xText.createTextCursor(); 85 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 86 xTextCursor.gotoStart(false); 87 xTextCursor.goRight((short) 102, true); 88 xCursorProps.setPropertyValue("CharKerning", (short)101); 89 //save to odt 90 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 91 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 92 aStoreProperties_odt[0] = new PropertyValue(); 93 aStoreProperties_odt[1] = new PropertyValue(); 94 aStoreProperties_odt[0].Name = "Override"; 95 aStoreProperties_odt[0].Value = true; 96 aStoreProperties_odt[1].Name = "FilterName"; 97 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 98 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 99 //save to doc 100 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 101 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 102 aStoreProperties_doc[0] = new PropertyValue(); 103 aStoreProperties_doc[1] = new PropertyValue(); 104 aStoreProperties_doc[0].Name = "Override"; 105 aStoreProperties_doc[0].Value = true; 106 aStoreProperties_doc[1].Name = "FilterName"; 107 aStoreProperties_doc[1].Value = "MS Word 97"; 108 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 109 app.closeDocument(xTextDocument); 110 111 //reopen the document and assert row height setting 112 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 113 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 114 //verify set property 115 assertEquals("assert character color",(short)101,xCursorProps_assert_odt.getPropertyValue("CharKerning")); 116 117 //reopen the document and assert row height setting 118 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 119 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 120 //verify set property 121 assertEquals("assert character color",(short)101,xCursorProps_assert_doc.getPropertyValue("CharKerning")); 122 } 123 @Test 124 public void testCharacterSpacing_Condens() throws Exception { 125 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 126 xText = xTextDocument.getText(); 127 xText.setString("we are Chinese,they are American.We are all living in one earth!" 128 + "and we all love our home very much!!!"); 129 // create text cursor for selecting and formatting text 130 XTextCursor xTextCursor = xText.createTextCursor(); 131 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 132 xTextCursor.gotoStart(false); 133 xTextCursor.goRight((short) 102, true); 134 xCursorProps.setPropertyValue("CharKerning", (short)-101); 135 //save to odt 136 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 137 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 138 aStoreProperties_odt[0] = new PropertyValue(); 139 aStoreProperties_odt[1] = new PropertyValue(); 140 aStoreProperties_odt[0].Name = "Override"; 141 aStoreProperties_odt[0].Value = true; 142 aStoreProperties_odt[1].Name = "FilterName"; 143 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 144 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 145 //save to doc 146 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 147 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 148 aStoreProperties_doc[0] = new PropertyValue(); 149 aStoreProperties_doc[1] = new PropertyValue(); 150 aStoreProperties_doc[0].Name = "Override"; 151 aStoreProperties_doc[0].Value = true; 152 aStoreProperties_doc[1].Name = "FilterName"; 153 aStoreProperties_doc[1].Value = "MS Word 97"; 154 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 155 app.closeDocument(xTextDocument); 156 157 //reopen the document and assert row height setting 158 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 159 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 160 //verify set property 161 assertEquals("assert character color",(short)-101,xCursorProps_assert_odt.getPropertyValue("CharKerning")); 162 163 //reopen the document and assert row height setting 164 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 165 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 166 //verify set property 167 assertEquals("assert character color",(short)-101,xCursorProps_assert_doc.getPropertyValue("CharKerning")); 168 } 169 } 170