Return-Path: X-Original-To: apmail-incubator-ooo-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-ooo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 011E1DA65 for ; Fri, 17 Aug 2012 07:31:11 +0000 (UTC) Received: (qmail 74566 invoked by uid 500); 17 Aug 2012 07:31:10 -0000 Delivered-To: apmail-incubator-ooo-commits-archive@incubator.apache.org Received: (qmail 74393 invoked by uid 500); 17 Aug 2012 07:31:06 -0000 Mailing-List: contact ooo-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ooo-dev@incubator.apache.org Delivered-To: mailing list ooo-commits@incubator.apache.org Received: (qmail 74317 invoked by uid 99); 17 Aug 2012 07:31:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Aug 2012 07:31:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Aug 2012 07:31:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8FA00238890D; Fri, 17 Aug 2012 07:30:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1374165 - in /incubator/ooo/trunk/main/test/testuno/source: testcase/uno/sw/field/CheckDateTimeField.java testlib/uno/sw/SWUtil.java Date: Fri, 17 Aug 2012 07:30:17 -0000 To: ooo-commits@incubator.apache.org From: liuzhe@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120817073017.8FA00238890D@eris.apache.org> Author: liuzhe Date: Fri Aug 17 07:30:17 2012 New Revision: 1374165 URL: http://svn.apache.org/viewvc?rev=1374165&view=rev Log: #120603# - [testuno]Test Create and Load Date and Time Field in Writer by UNO Patch by: Zong Dong Jun Review by: Liu Zhe Modified: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/field/CheckDateTimeField.java incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java 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=1374165&r1=1374164&r2=1374165&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 Fri Aug 17 07:30:17 2012 @@ -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,51 +121,37 @@ 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")); - - - 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(); + 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); + 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 @@ 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,56 +179,44 @@ 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")); - - - 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(); + 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); + 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); } } Modified: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java?rev=1374165&r1=1374164&r2=1374165&view=diff ============================================================================== --- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java (original) +++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java Fri Aug 17 07:30:17 2012 @@ -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(); - } + 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")); + } }