package fvt.uno.sw.puretext; import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openoffice.test.common.FileUtil; import org.openoffice.test.common.Testspace; import org.openoffice.test.uno.UnoApp; //import org.openoffice.test.vcl.Tester.*; import com.sun.star.text.*; import com.sun.star.beans.*; import com.sun.star.frame.XStorable; import com.sun.star.uno.UnoRuntime; public class CharacterChangeCase { private static final UnoApp app = new UnoApp(); XText xText = null; @Before public void setUp() throws Exception { app.start(); } @After public void tearDown() throws Exception { app.close(); } @Test public void testCharacterLowerCaseSetting() throws Exception { XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document xText = xTextDocument.getText(); // simply set whole text as one string xText.setString("We are Chinese they are American We are all living in one earth " + "And we all love our home very much!!!"); // create text cursor for selecting and formatting text XTextCursor xTextCursor = xText.createTextCursor(); XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); xTextCursor.gotoStart(false); xTextCursor.goRight((short) 102, true); xCursorProps.setPropertyValue("CharCaseMap",new Short(com.sun.star.style.CaseMap.LOWERCASE)); //save to doc XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; aStoreProperties_doc[0] = new PropertyValue(); aStoreProperties_doc[1] = new PropertyValue(); aStoreProperties_doc[0].Name = "Override"; aStoreProperties_doc[0].Value = true; aStoreProperties_doc[1].Name = "FilterName"; aStoreProperties_doc[1].Value = "MS Word 97"; xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); //save to odt XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; aStoreProperties_odt[0] = new PropertyValue(); aStoreProperties_odt[1] = new PropertyValue(); aStoreProperties_odt[0].Name = "Override"; aStoreProperties_odt[0].Value = true; aStoreProperties_odt[1].Name = "FilterName"; aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); app.closeDocument(xTextDocument); //reopen the document and assert case map XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.LOWERCASE,xCursorProps_assert_odt.getPropertyValue("CharCaseMap")); //when save to doc,lower case setting by UNO API lost,change to default. //reopen the document and assert case map XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.NONE,xCursorProps_assert_doc.getPropertyValue("CharCaseMap")); } @Test public void testCharacterUpperCaseSetting() throws Exception { XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document xText = xTextDocument.getText(); // simply set whole text as one string xText.setString("we are Chinese,they are American.We are all living in one earth!" + "and we all love our home very much!!!"); // create text cursor for selecting and formatting text XTextCursor xTextCursor = xText.createTextCursor(); XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); xTextCursor.gotoStart(false); xTextCursor.goRight((short) 102, true); xCursorProps.setPropertyValue("CharCaseMap",com.sun.star.style.CaseMap.UPPERCASE); //save to odt XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; aStoreProperties_odt[0] = new PropertyValue(); aStoreProperties_odt[1] = new PropertyValue(); aStoreProperties_odt[0].Name = "Override"; aStoreProperties_odt[0].Value = true; aStoreProperties_odt[1].Name = "FilterName"; aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); //save to doc XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; aStoreProperties_doc[0] = new PropertyValue(); aStoreProperties_doc[1] = new PropertyValue(); aStoreProperties_doc[0].Name = "Override"; aStoreProperties_doc[0].Value = true; aStoreProperties_doc[1].Name = "FilterName"; aStoreProperties_doc[1].Value = "MS Word 97"; xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); app.closeDocument(xTextDocument); //reopen the document and assert row height setting XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.UPPERCASE,xCursorProps_assert_odt.getPropertyValue("CharCaseMap")); //reopen the document and assert row height setting XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.UPPERCASE,xCursorProps_assert_doc.getPropertyValue("CharCaseMap")); } @Test public void testCharacterSmallCapsSetting() throws Exception { XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document xText = xTextDocument.getText(); // simply set whole text as one string xText.setString("we are Chinese,they are American.We are all living in one earth!" + "and we all love our home very much!!!"); // create text cursor for selecting and formatting text XTextCursor xTextCursor = xText.createTextCursor(); XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); xTextCursor.gotoStart(false); xTextCursor.goRight((short) 102, true); xCursorProps.setPropertyValue("CharCaseMap",com.sun.star.style.CaseMap.SMALLCAPS); //save to odt XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; aStoreProperties_odt[0] = new PropertyValue(); aStoreProperties_odt[1] = new PropertyValue(); aStoreProperties_odt[0].Name = "Override"; aStoreProperties_odt[0].Value = true; aStoreProperties_odt[1].Name = "FilterName"; aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); //save to doc XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; aStoreProperties_doc[0] = new PropertyValue(); aStoreProperties_doc[1] = new PropertyValue(); aStoreProperties_doc[0].Name = "Override"; aStoreProperties_doc[0].Value = true; aStoreProperties_doc[1].Name = "FilterName"; aStoreProperties_doc[1].Value = "MS Word 97"; xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); app.closeDocument(xTextDocument); //reopen the document and assert row height setting XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.SMALLCAPS,xCursorProps_assert_odt.getPropertyValue("CharCaseMap")); //reopen the document and assert row height setting XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.SMALLCAPS,xCursorProps_assert_doc.getPropertyValue("CharCaseMap")); } @Test public void testCharacterCapitalEveryWordSetting() throws Exception { XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document xText = xTextDocument.getText(); // simply set whole text as one string xText.setString("we are Chinese they are American we are all living in one earth " + "and we all love our home very much!!!"); // create text cursor for selecting and formatting text XTextCursor xTextCursor = xText.createTextCursor(); XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); xTextCursor.gotoStart(false); xTextCursor.goRight((short) 110, true); xCursorProps.setPropertyValue("CharCaseMap",new Short(com.sun.star.style.CaseMap.TITLE)); //save to odt XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; aStoreProperties_odt[0] = new PropertyValue(); aStoreProperties_odt[1] = new PropertyValue(); aStoreProperties_odt[0].Name = "Override"; aStoreProperties_odt[0].Value = true; aStoreProperties_odt[1].Name = "FilterName"; aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); //save to doc XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; aStoreProperties_doc[0] = new PropertyValue(); aStoreProperties_doc[1] = new PropertyValue(); aStoreProperties_doc[0].Name = "Override"; aStoreProperties_doc[0].Value = true; aStoreProperties_doc[1].Name = "FilterName"; aStoreProperties_doc[1].Value = "MS Word 97"; xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); app.closeDocument(xTextDocument); //reopen the document and assert row height setting XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.TITLE,xCursorProps_assert_odt.getPropertyValue("CharCaseMap")); //reopen the document and assert row height setting XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); //verify set property,when save to doc and reopen,the proeprty value change to default,but display is normally assertEquals("assert character casemap",com.sun.star.style.CaseMap.NONE,xCursorProps_assert_doc.getPropertyValue("CharCaseMap")); } @Test public void testCharacterNoCaseSetting() throws Exception { XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document xText = xTextDocument.getText(); // simply set whole text as one string xText.setString("we are Chinese they are American we are all living in one earth " + "and we all love our home very much!!!"); // create text cursor for selecting and formatting text XTextCursor xTextCursor = xText.createTextCursor(); XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); xTextCursor.gotoStart(false); xTextCursor.goRight((short) 110, true); xCursorProps.setPropertyValue("CharCaseMap",new Short(com.sun.star.style.CaseMap.NONE)); //save to odt XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; aStoreProperties_odt[0] = new PropertyValue(); aStoreProperties_odt[1] = new PropertyValue(); aStoreProperties_odt[0].Name = "Override"; aStoreProperties_odt[0].Value = true; aStoreProperties_odt[1].Name = "FilterName"; aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); //save to doc XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; aStoreProperties_doc[0] = new PropertyValue(); aStoreProperties_doc[1] = new PropertyValue(); aStoreProperties_doc[0].Name = "Override"; aStoreProperties_doc[0].Value = true; aStoreProperties_doc[1].Name = "FilterName"; aStoreProperties_doc[1].Value = "MS Word 97"; xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); app.closeDocument(xTextDocument); //reopen the document and assert row height setting XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.NONE,xCursorProps_assert_odt.getPropertyValue("CharCaseMap")); //reopen the document and assert row height setting XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); //verify set property assertEquals("assert character casemap",com.sun.star.style.CaseMap.NONE,xCursorProps_assert_doc.getPropertyValue("CharCaseMap")); } }