Index: testuno/.externalToolBuilders/Classpath Builder.launch =================================================================== --- testuno/.externalToolBuilders/Classpath Builder.launch (revision 1374160) +++ testuno/.externalToolBuilders/Classpath Builder.launch (working copy) @@ -1,16 +1,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + Index: testuno/source/testcase/uno/sw/field/CheckDateTimeField.java =================================================================== --- testuno/source/testcase/uno/sw/field/CheckDateTimeField.java (revision 1374160) +++ testuno/source/testcase/uno/sw/field/CheckDateTimeField.java (working copy) @@ -30,6 +30,7 @@ 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 @@ @After public void tearDownDocument() { app.closeDocument(document); - // FileUtil.deleteFile(Testspace.getFile(tempPath)); + FileUtil.deleteFile(Testspace.getFile(tempPath)); } @@ -89,10 +90,11 @@ * 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 @@ * 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,51 +121,37 @@ } - 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")); - + XTextField dateFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.DateTime")); - XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, dateFiled); - props.setPropertyValue("IsDate", false); - - document.getText().insertTextContent(document.getText().getEnd(), dateFiled, false); - DateTime dateField = (DateTime) props.getPropertyValue("DateTimeValue"); - String dateString = document.getText().getString(); - assertTrue("Verify time field is creatd, by verify it's hour", dateString.indexOf(String.valueOf(dateField.Hours).trim()) != -1); - assertTrue("Verify time field is creatd, by verify it's minutes", dateString.indexOf(String.valueOf(dateField.Minutes).trim()) != -1); - int expectHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); - assertEquals("Verify time field is creatd, value is right, by compare Hour", expectHour, dateField.Hours); - 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(); - XEnumeration enumeration = xEnumeratedFields.createEnumeration(); - while (enumeration.hasMoreElements()) { - Object field = enumeration.nextElement(); - XPropertySet props2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); - DateTime dateField2 = (DateTime) props2.getPropertyValue("DateTimeValue"); - assertEquals("Verify time field is creatd correct by save and reload.", expectHour, dateField2.Hours); - } - - - } catch (Exception e) { - e.printStackTrace(); - } - - - - - } catch (com.sun.star.uno.Exception e) { - e.printStackTrace(); + XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, dateFiled); + props.setPropertyValue("IsDate", false); + + document.getText().insertTextContent(document.getText().getEnd(), dateFiled, false); + DateTime dateField = (DateTime) props.getPropertyValue("DateTimeValue"); + + String dateString = document.getText().getString(); + assertTrue("Verify time field is creatd, by verify it's hour", dateString.indexOf(String.valueOf(dateField.Hours).trim()) != -1); + assertTrue("Verify time field is creatd, by verify it's minutes", dateString.indexOf(String.valueOf(dateField.Minutes).trim()) != -1); + int expectHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); + assertEquals("Verify time field is creatd, value is right, by compare Hour", expectHour, dateField.Hours); + XStorable store = UnoRuntime.queryInterface(XStorable.class, document); + store.storeAsURL(url, propsValue); + app.closeDocument(document); + document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url)); + XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); + XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields(); + XEnumeration enumeration = xEnumeratedFields.createEnumeration(); + while (enumeration.hasMoreElements()) { + Object field = enumeration.nextElement(); + XPropertySet props2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); + DateTime dateField2 = (DateTime) props2.getPropertyValue("DateTimeValue"); + assertEquals("Verify time field is creatd correct by save and reload.", expectHour, dateField2.Hours); } + } /** * Test Date Field can be created correctly. @@ -170,10 +159,11 @@ * 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,56 +179,44 @@ * 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")); - + XTextField dateFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.DateTime")); - XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, dateFiled); - props.setPropertyValue("IsDate", true); - - document.getText().insertTextContent(document.getText().getEnd(), dateFiled, false); - DateTime dateField = (DateTime) props.getPropertyValue("DateTimeValue"); - String dateString = document.getText().getString(); - assertTrue("Verify date field is creatd, by verify it's Month", dateString.indexOf(String.valueOf(dateField.Month).trim()) != -1); - assertTrue("Verify date field is creatd, by verify it's Day", dateString.indexOf(String.valueOf(dateField.Day).trim()) != -1); - int expectDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); - assertEquals("Verify date field is creatd, value is right, by compare Day", expectDay, dateField.Day); - 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(); - XEnumeration enumeration = xEnumeratedFields.createEnumeration(); - while (enumeration.hasMoreElements()) { - Object field = enumeration.nextElement(); - XPropertySet props2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); - DateTime dateField2 = (DateTime) props2.getPropertyValue("DateTimeValue"); - 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(); + XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, dateFiled); + props.setPropertyValue("IsDate", true); + + document.getText().insertTextContent(document.getText().getEnd(), dateFiled, false); + DateTime dateField = (DateTime) props.getPropertyValue("DateTimeValue"); + + String dateString = document.getText().getString(); + assertTrue("Verify date field is creatd, by verify it's Month", dateString.indexOf(String.valueOf(dateField.Month).trim()) != -1); + assertTrue("Verify date field is creatd, by verify it's Day", dateString.indexOf(String.valueOf(dateField.Day).trim()) != -1); + int expectDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); + assertEquals("Verify date field is creatd, value is right, by compare Day", expectDay, dateField.Day); + XStorable store = UnoRuntime.queryInterface(XStorable.class, document); + store.storeAsURL(url, propsValue); + app.closeDocument(document); + document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url)); + XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); + XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields(); + XEnumeration enumeration = xEnumeratedFields.createEnumeration(); + while (enumeration.hasMoreElements()) { + Object field = enumeration.nextElement(); + XPropertySet props2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); + DateTime dateField2 = (DateTime) props2.getPropertyValue("DateTimeValue"); + assertEquals("Verify date field is creatd correct by save and reload.", expectDay, dateField2.Day); } } Index: testuno/source/testlib/uno/sw/SWUtil.java =================================================================== --- testuno/source/testlib/uno/sw/SWUtil.java (revision 1374160) +++ testuno/source/testlib/uno/sw/SWUtil.java (working copy) @@ -11,35 +11,28 @@ 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 IOException { saveAs(document, "MS Word 97", url); } - public static void saveAsODT(XTextDocument document, String url) { + public static void saveAsODT(XTextDocument document, String url) throws IOException { 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 IOException { 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(); - } + store.storeAsURL(url, propsValue); + } - public static XTextDocument newDocument() { - try { - return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); - } catch (Exception e) { - e.printStackTrace(); - } - return null; + public static XTextDocument newDocument() throws Exception { + return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); + } }