Author: liuzhe
Date: Tue Aug 21 08:42:34 2012
New Revision: 1375430
URL: http://svn.apache.org/viewvc?rev=1375430&view=rev
Log:
#120630# - [testuno]Test PageNumber field create and load in wirter
Patch by: Zong Dong Jun <[email protected]>
Review by: Liu Zhe <[email protected]>
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberField.java
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.doc
(with props)
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.odt
(with props)
Modified:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java
incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java
incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java
Modified:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java?rev=1375430&r1=1375429&r2=1375430&view=diff
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java
(original)
+++
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/bookmark/CheckBookmarks.java
Tue Aug 21 08:42:34 2012
@@ -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;
Modified:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java?rev=1375430&r1=1375429&r2=1375430&view=diff
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java
(original)
+++
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java
Tue Aug 21 08:42:34 2012
@@ -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"));
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberField.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberField.java?rev=1375430&view=auto
==============================================================================
---
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberField.java
(added)
+++
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberField.java
Tue Aug 21 08:42:34 2012
@@ -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);
+
+
+ }
+}
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.doc
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.doc?rev=1375430&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.doc
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.odt
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.odt?rev=1375430&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/PageNumberFieldTest.odt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java?rev=1375430&r1=1375429&r2=1375430&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java
(original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SDUtil.java Tue
Aug 21 08:42:34 2012
@@ -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;
Modified: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java
URL:
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java?rev=1375430&r1=1375429&r2=1375430&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java
(original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SWUtil.java Tue
Aug 21 08:42:34 2012
@@ -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);
}
-
}