Kaydet (Commit) cc9e9db3 authored tarafından Liu Zhe's avatar Liu Zhe

#120603# - [testuno]Test Create and Load Date and Time Field in Writer by UNO

Patch by: Zong Dong Jun <zongdj001@gmail.com>
Review by: Liu Zhe <aliuzhe@gmail.com>
üst 6ca0d400
......@@ -30,6 +30,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openoffice.test.common.FileUtil;
import org.openoffice.test.common.Testspace;
import org.openoffice.test.uno.UnoApp;
......@@ -66,7 +67,7 @@ public class CheckDateTimeField {
@After
public void tearDownDocument() {
app.closeDocument(document);
// FileUtil.deleteFile(Testspace.getFile(tempPath));
FileUtil.deleteFile(Testspace.getFile(tempPath));
}
......@@ -89,10 +90,11 @@ public class CheckDateTimeField {
* 2.Verify the Time is created by check the date hour in the new document
* 3.Save and close the new document to doc format
* 4.Reload the new save doc file, check the time field
* @throws Exception
*/
@Test
public void testCreateTimeFieldSaveDoc() {
public void testCreateTimeFieldSaveDoc() throws Exception {
String url = Testspace.getUrl(tempPath + tempFileName + ".doc");
PropertyValue[] propsValue = new PropertyValue[1];
......@@ -108,9 +110,10 @@ public class CheckDateTimeField {
* 2.Verify the Time Field is created by check the date hour in the new document
* 3.Save and close the new document to doc format
* 4.Reload the new save odt file, check the Time Field
* @throws Exception
*/
@Test
public void testCreateTimeFieldSaveODT() {
public void testCreateTimeFieldSaveODT() throws Exception {
String url = Testspace.getUrl(tempPath + tempFileName + ".odt");
PropertyValue[] propsValue = new PropertyValue[0];
......@@ -118,9 +121,8 @@ public class CheckDateTimeField {
}
private void createTimeFiled(XTextDocument document, String url, PropertyValue[] propsValue) {
private void createTimeFiled(XTextDocument document, String url, PropertyValue[] propsValue) throws Exception {
XMultiServiceFactory sevriceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
try {
XTextField dateFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.DateTime"));
......@@ -138,8 +140,6 @@ public class CheckDateTimeField {
XStorable store = UnoRuntime.queryInterface(XStorable.class, document);
store.storeAsURL(url, propsValue);
app.closeDocument(document);
try {
document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url));
XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document);
XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields();
......@@ -152,17 +152,6 @@ public class CheckDateTimeField {
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (com.sun.star.uno.Exception e) {
e.printStackTrace();
}
}
/**
* Test Date Field can be created correctly.
......@@ -170,10 +159,11 @@ public class CheckDateTimeField {
* 2.Verify the Date is created by check the date hour in the new document
* 3.Save and close the new document to doc format
* 4.Reload the new save doc file, check the Date field
* @throws Exception
*/
@Test
public void testCreateDateFieldSaveDoc() {
public void testCreateDateFieldSaveDoc() throws Exception {
String url = Testspace.getUrl(tempPath + tempFileName + ".doc");
PropertyValue[] propsValue = new PropertyValue[1];
......@@ -189,18 +179,18 @@ public class CheckDateTimeField {
* 2.Verify the dateField is created by check the date hour in the new document
* 3.Save and close the new document to doc format
* 4.Reload the new save odt file, check the date field
* @throws Exception
*/
@Test
public void testCreateDateFieldSaveODT() {
public void testCreateDateFieldSaveODT() throws Exception {
String url = Testspace.getUrl(tempPath + tempFileName + ".odt");
PropertyValue[] propsValue = new PropertyValue[0];
createDateFiled(document, url, propsValue);
}
private void createDateFiled(XTextDocument document, String url, PropertyValue[] propsValue) {
private void createDateFiled(XTextDocument document, String url, PropertyValue[] propsValue) throws Exception {
XMultiServiceFactory sevriceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
try {
XTextField dateFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.DateTime"));
......@@ -218,8 +208,6 @@ public class CheckDateTimeField {
XStorable store = UnoRuntime.queryInterface(XStorable.class, document);
store.storeAsURL(url, propsValue);
app.closeDocument(document);
try {
document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url));
XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document);
XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields();
......@@ -231,16 +219,6 @@ public class CheckDateTimeField {
assertEquals("Verify date field is creatd correct by save and reload.", expectDay, dateField2.Day);
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (com.sun.star.uno.Exception e) {
e.printStackTrace();
}
}
......
......@@ -4,42 +4,34 @@ import org.openoffice.test.uno.UnoApp;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XStorable;
import com.sun.star.io.IOException;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
public class SWUtil {
private static final UnoApp app = new UnoApp();
public static void saveAsDoc(XTextDocument document, String url) {
public static void saveAsDoc(XTextDocument document, String url) throws Exception {
saveAs(document, "MS Word 97", url);
}
public static void saveAsODT(XTextDocument document, String url) {
public static void saveAsODT(XTextDocument document, String url) throws Exception {
saveAs(document, "writer8", url);
}
public static void saveAs(XTextDocument document, String filterValue, String url) {
public static void saveAs(XTextDocument document, String filterValue, String url) throws Exception {
XStorable store = UnoRuntime.queryInterface(XStorable.class, document);
PropertyValue[] propsValue = new PropertyValue[1];
propsValue[0] = new PropertyValue();
propsValue[0].Name = "FilterName";
propsValue[0].Value = filterValue;
try {
store.storeAsURL(url, propsValue);
} catch (IOException e) {
e.printStackTrace();
}
}
public static XTextDocument newDocument() {
try {
public static XTextDocument newDocument() throws Exception {
return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment