diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java | 2 | ||||
-rw-r--r-- | test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java | 4 | ||||
-rw-r--r-- | test/testuno/source/testcase/uno/sw/field/PageNumberField.java | 196 | ||||
-rw-r--r-- | test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.doc | bin | 0 -> 26624 bytes | |||
-rw-r--r-- | test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.odt | bin | 0 -> 8074 bytes | |||
-rw-r--r-- | test/testuno/source/testlib/uno/SDUtil.java | 21 | ||||
-rw-r--r-- | test/testuno/source/testlib/uno/SWUtil.java | 72 |
7 files changed, 278 insertions, 17 deletions
diff --git a/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java b/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java index 09ae20001362..0b672a68670b 100644 --- a/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java +++ b/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java @@ -22,7 +22,7 @@ package testcase.uno.sw.bookmark; import static org.junit.Assert.assertArrayEquals; -import static testlib.uno.SWUtil.insertBookmark; +import static testlib.uno.SWUtil.*; import org.junit.After; import org.junit.AfterClass; diff --git a/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java b/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java index ffb468507432..5f21c30669b1 100644 --- a/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java +++ b/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java @@ -53,12 +53,12 @@ import com.sun.star.util.DateTime; public class CheckDateTimeField { - private static final UnoApp app = new UnoApp(); - private XTextDocument document = null; private String tempPath = "testcase/uno/sw/temp/" ; private String tempFileName = String.valueOf(System.currentTimeMillis()); + private static final UnoApp app = new UnoApp(); + private XTextDocument document = null; @Before public void setUpDocument() throws Exception { document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); diff --git a/test/testuno/source/testcase/uno/sw/field/PageNumberField.java b/test/testuno/source/testcase/uno/sw/field/PageNumberField.java new file mode 100644 index 000000000000..a80d83f9b542 --- /dev/null +++ b/test/testuno/source/testcase/uno/sw/field/PageNumberField.java @@ -0,0 +1,196 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ +package testcase.uno.sw.field; +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.openoffice.test.common.Testspace; +import org.openoffice.test.uno.UnoApp; + +import testlib.uno.SWUtil; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XEnumeration; +import com.sun.star.container.XEnumerationAccess; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.text.XTextDocument; +import com.sun.star.text.XTextField; +import com.sun.star.text.XTextFieldsSupplier; +import com.sun.star.uno.UnoRuntime; + + +public class PageNumberField { + + private static final UnoApp app = new UnoApp(); + private static XTextDocument odtDocument = null; + private static XTextDocument docDocument = null; + private static String odtSample = "testcase/uno/sw/field/PageNumberFieldTest.odt"; + private static String odtSampleWorking = ""; + private static String docSample = "testcase/uno/sw/field/PageNumberFieldTest.doc"; + private static String docSampleWorking = ""; + + private static String odtSaveAsDocSample = "testcase/uno/sw/field/PageNumberFieldTest_1.doc"; + private static String docSaveAsODTSample = "testcase/uno/sw/field/PageNumberFieldTest_1.odt"; + + @Before + public void setUpDocument() throws Exception { + app.start(); + } + + @After + public void tearDownDocument() { + + + } + + @BeforeClass + public static void setUpConnection() throws Exception { + + } + + + @AfterClass + public static void tearDownConnection() throws InterruptedException, + Exception { + app.close(); + } + + /** + * There is a bug : Bug 120625 + * Test Page Number Field Can created and Saved in odt file + * 1.launch a odt document + * 2.Create a page number field at end of this page + * 3.Save and Reopen this document + * @throws Throwable + */ + @Test + @Ignore("Bug 120625") + public void testPageNumberFieldODT() throws Throwable { + odtSampleWorking = Testspace.prepareData(odtSample); + odtDocument = SWUtil.openDocument(odtSampleWorking, app); + createPageNumberFiled(odtDocument, 3, "odt"); + app.closeDocument(odtDocument); + } + + /** + * Bug 120625 + * Test Page Number Field Can created and Saved in Doc file + * 1.launch a doc document + * 2.Create a page number field at end of this page + * 3.Save and Reopen this document, check page number field + * @throws Throwable + */ + @Test + @Ignore("Bug 120625") + public void testPageNumberFieldDOC() throws Throwable { + docSampleWorking = Testspace.prepareData(docSample); + docDocument = SWUtil.openDocument(docSampleWorking, app); + createPageNumberFiled(docDocument, 2, "odt"); + app.closeDocument(docDocument); + } + + /** + * Test Page Number Field in odt file save to doc format works well + * 1.Launch the new saved file + * 2.Check page number filed. + * @throws Throwable + */ + @Test + public void testSavedDoc2ODTPageNumberField() throws Throwable { + odtDocument = SWUtil.openDocumentFromURL(Testspace.getUrl(docSaveAsODTSample), app); + getPageNumberField(odtDocument, 2); + app.closeDocument(odtDocument); + } + + /** + * Test Page Number Field in doc file save to odt format works well + * 1.Launch the new saved file + * 2.Check page number filed. + * @throws Throwable + */ + @Test + public void testSavedODT2DOCPageNumberField() throws Throwable { + docDocument = SWUtil.openDocumentFromURL(Testspace.getUrl(odtSaveAsDocSample), app); + getPageNumberField(docDocument, 2); + app.closeDocument(docDocument); + } + + private void createPageNumberFiled(XTextDocument document, int expectNumber, String saveAsFormat) throws Exception { + XMultiServiceFactory sevriceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document); + XTextField pageNumberFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.PageNumber")); + + XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, pageNumberFiled); + props.setPropertyValue("NumberingType", 4);//Set page number display as Arabic + + + SWUtil.moveCuror2End(document); + document.getText().insertTextContent(document.getText().getEnd(), pageNumberFiled, true); + + String documentString = document.getText().getString().trim(); + int length = documentString.length(); + String strNum = String.valueOf(documentString.charAt(length -1)); + int number = Integer.valueOf(strNum); + assertEquals("Test Page Number field can insert correctly", expectNumber, number); + SWUtil.save(document); + if("odt".equals(saveAsFormat)) { + SWUtil.saveAsDoc(document, Testspace.getUrl(odtSaveAsDocSample)); + + + } else if ("doc".equals(saveAsFormat)) { + SWUtil.saveAsDoc(document, Testspace.getUrl(docSaveAsODTSample)); + + } + app.closeDocument(document); + + //Verify after save. + document = SWUtil.openDocument(odtSampleWorking, app); + + getPageNumberField(document, expectNumber); + + + } + + private void getPageNumberField(XTextDocument document, int expectNumber) throws Exception { + XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); + XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields(); + XEnumeration enumeration = xEnumeratedFields.createEnumeration(); + while (enumeration.hasMoreElements()) { + Object field = enumeration.nextElement(); + XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); + short numberType = (Short) props.getPropertyValue("NumberingType"); + assertEquals("Verify page number field type is Arabic", 4, numberType); + + } + + String documentString = document.getText().getString().trim(); + int length = documentString.length(); + String strNum = String.valueOf(documentString.charAt(length -1)); + int number = Integer.valueOf(strNum); + assertEquals("Test Page Number field can insert and saved correctly", expectNumber, number); + + + } +} diff --git a/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.doc b/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.doc Binary files differnew file mode 100644 index 000000000000..ba0a5288a49c --- /dev/null +++ b/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.doc diff --git a/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.odt b/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.odt Binary files differnew file mode 100644 index 000000000000..a8feebdf808a --- /dev/null +++ b/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.odt diff --git a/test/testuno/source/testlib/uno/SDUtil.java b/test/testuno/source/testlib/uno/SDUtil.java index be6adab66d19..24fb7d41684b 100644 --- a/test/testuno/source/testlib/uno/SDUtil.java +++ b/test/testuno/source/testlib/uno/SDUtil.java @@ -1,6 +1,23 @@ -/** +/************************************************************** * - */ + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ package testlib.uno; import com.sun.star.container.XIndexAccess; diff --git a/test/testuno/source/testlib/uno/SWUtil.java b/test/testuno/source/testlib/uno/SWUtil.java index 73b293804bc3..8e4f1ff90e33 100644 --- a/test/testuno/source/testlib/uno/SWUtil.java +++ b/test/testuno/source/testlib/uno/SWUtil.java @@ -1,13 +1,33 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ package testlib.uno; import org.openoffice.test.uno.UnoApp; import com.sun.star.beans.PropertyValue; -import com.sun.star.container.XNameAccess; import com.sun.star.container.XNamed; import com.sun.star.frame.XStorable; +import com.sun.star.io.IOException; import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.text.XBookmarksSupplier; +import com.sun.star.text.XText; import com.sun.star.text.XTextContent; import com.sun.star.text.XTextCursor; import com.sun.star.text.XTextDocument; @@ -15,17 +35,23 @@ import com.sun.star.uno.UnoRuntime; public class SWUtil { - private static final UnoApp app = new UnoApp(); - public static void saveAsDoc(XTextDocument document, String url) throws Exception { + + public static void saveAsDoc(XTextDocument document, String url) throws IOException { saveAs(document, "MS Word 97", url); } - public static void saveAsODT(XTextDocument document, String url) throws Exception { + public static void saveAsODT(XTextDocument document, String url) throws IOException { saveAs(document, "writer8", url); } - public static void saveAs(XTextDocument document, String filterValue, String url) throws Exception { + public static void save(XTextDocument document) throws IOException { + XStorable store = UnoRuntime.queryInterface(XStorable.class, document); + store.store(); + + } + + public static void saveAs(XTextDocument document, String filterValue, String url) throws IOException { XStorable store = UnoRuntime.queryInterface(XStorable.class, document); PropertyValue[] propsValue = new PropertyValue[1]; @@ -36,11 +62,34 @@ public class SWUtil { } - public static XTextDocument newDocument() throws Exception { - return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); + public static XTextDocument newDocument(UnoApp app) throws Exception { + return UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); } + public static XTextDocument openDocumentFromURL(String url, UnoApp app) throws Exception { + return UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url)); + + } + + public static XTextDocument openDocument(String filePath, UnoApp app) throws Exception { + + return UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(filePath)); + + } + public static void moveCuror2End(XTextDocument document) { + XText xText = document.getText(); + XTextCursor xTextCursor = xText.createTextCursor(); + xTextCursor.gotoEnd(false); + } + + public static void moveCuror2Start(XTextDocument document) { + XText xText = document.getText(); + XTextCursor xTextCursor = xText.createTextCursor(); + xTextCursor.gotoStart(false); + } + + /** * Insert a bookmark into text document * @param document text document @@ -49,12 +98,11 @@ public class SWUtil { * @throws Exception */ public static void insertBookmark(XTextDocument document, XTextCursor textCursor, String bookmarkName) throws Exception { - XMultiServiceFactory xDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document); + XMultiServiceFactory xDocFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, document); Object xBookmark = xDocFactory.createInstance("com.sun.star.text.Bookmark"); - XTextContent xBookmarkAsTextContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xBookmark); - XNamed xBookmarkAsNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, xBookmark); + XTextContent xBookmarkAsTextContent = UnoRuntime.queryInterface(XTextContent.class, xBookmark); + XNamed xBookmarkAsNamed = UnoRuntime.queryInterface(XNamed.class, xBookmark); xBookmarkAsNamed.setName(bookmarkName); document.getText().insertTextContent(textCursor, xBookmarkAsTextContent, true); } - } |