diff options
author | Kurt Zenker <kz@openoffice.org> | 2003-12-11 10:49:03 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2003-12-11 10:49:03 +0000 |
commit | fd4432ed7e3dc3cd196ad5366c53c3e861fdefbb (patch) | |
tree | 0691544cca098cfb17f79cc4060b5f4b8393db83 | |
parent | ee305f0012c1fc22173ce77e4be8768e78671837 (diff) |
INTEGRATION: CWS qadev14 (1.2.12); FILE MERGED
2003/12/04 19:07:07 sg 1.2.12.1: #114056#CHG: adapted test
-rw-r--r-- | qadevOOo/tests/java/ifc/util/_XChangesBatch.java | 138 | ||||
-rw-r--r-- | qadevOOo/tests/java/ifc/util/_XChangesNotifier.java | 187 |
2 files changed, 316 insertions, 9 deletions
diff --git a/qadevOOo/tests/java/ifc/util/_XChangesBatch.java b/qadevOOo/tests/java/ifc/util/_XChangesBatch.java index 80efbfb3ced1..91e53ad1d2d4 100644 --- a/qadevOOo/tests/java/ifc/util/_XChangesBatch.java +++ b/qadevOOo/tests/java/ifc/util/_XChangesBatch.java @@ -2,9 +2,9 @@ * * $RCSfile: _XChangesBatch.java,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change:$Date: 2003-09-08 11:29:18 $ + * last change:$Date: 2003-12-11 11:48:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,21 +61,155 @@ package ifc.util; +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XProperty; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XHierarchicalName; +import com.sun.star.container.XHierarchicalNameAccess; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameReplace; +import com.sun.star.document.XTypeDetection; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.ElementChange; import lib.MultiMethodTest; import com.sun.star.util.XChangesBatch; +import java.io.PrintWriter; +import lib.Status; +import lib.StatusException; public class _XChangesBatch extends MultiMethodTest { public XChangesBatch oObj; + private Object changeElement = null; + private Object originalElement = null; + private String elementName = null; + private XPropertySet xProp = null; + private XNameReplace xNameReplace = null; + + /** + * add a change that can be committed + */ + protected void before() { + changeElement = tEnv.getObjRelation("XChangesBatch.ChangeElement"); + originalElement = tEnv.getObjRelation("XChangesBatch.OriginalElement"); + elementName = (String)tEnv.getObjRelation("XChangesBatch.PropertyName"); + + // to do a change, get an XPropertySet + xProp = (XPropertySet)tEnv.getObjRelation("XChangesBatch.PropertySet"); + try { + if (originalElement == null && xProp != null) + originalElement = xProp.getPropertyValue(elementName); + } + catch(com.sun.star.uno.Exception e) { + throw new StatusException("Could not get property '" + elementName + "'.", e); + } + + // or get an XNameReplace + xNameReplace = (XNameReplace)tEnv.getObjRelation("XChangesBatch.NameReplace"); + try { + if (originalElement == null && xNameReplace != null) + originalElement = xNameReplace.getByName(elementName); + } + catch(com.sun.star.uno.Exception e) { + throw new StatusException("Could not get element by name '" + elementName + "'.", e); + } + + if (changeElement == null || originalElement == null || elementName == null || (xProp == null && xNameReplace == null)) { + log.println( + changeElement == null?"Missing property 'XChangesBatch.ChangeElement'\n":"" + + originalElement == null?"Missing property 'XChangesBatch.OriginalElement'\n":"" + + elementName == null?"Missing property 'XChangesBatch.PropertyName'\n":"" + + xProp == null?"Missing property 'XChangesBatch.PropertySet'":"" + + xNameReplace == null?"Missing property 'XChangesBatch.NameReplace'":"" + ); + throw new StatusException("Some needed object relations are missing.", new Exception()); + } + } public void _commitChanges() { + requiredMethod("getPendingChanges()"); + try { + log.println("Committing changes."); + oObj.commitChanges(); + } + catch(com.sun.star.lang.WrappedTargetException e) { + tRes.tested("commitChanges()", Status.exception(e)); + return; + } + try { + executeChange(originalElement); + } + catch(StatusException e) { + tRes.tested("hasPendingChanges()", Status.exception(e)); + return; + } + + try { + log.println("Commit changes back."); + oObj.commitChanges(); + } + catch(com.sun.star.lang.WrappedTargetException e) { + tRes.tested("commitChanges()", Status.exception(e)); + return; + } + tRes.tested("commitChanges()", true); } public void _getPendingChanges() { + requiredMethod("hasPendingChanges()"); + ElementChange[]changes = oObj.getPendingChanges(); + if (changes == null) { + log.println("Returned changes was 'null'"); + log.println("It should have been 1 change."); + tRes.tested("getPendingChanges()", false); + } else if (changes.length != 1) { + int amount = changes.length; + log.println("Found not the right number of changes: " + amount); + log.println("It should have been 1 change."); + for (int i=0; i<amount; i++) { + System.out.println("Detailed Change " + i + " -> new Element: '" + + changes[i].Element.toString() + "' ReplacedElement: '" + + changes[i].ReplacedElement.toString() + "'"); + } + tRes.tested("getPendingChanges()", false); + } + else { + boolean result = changes[0].ReplacedElement.equals(originalElement); + result &= changes[0].Element.equals(changeElement); + tRes.tested("getPendingChanges()", result); + } } public void _hasPendingChanges() { + try { + executeChange(changeElement); + } + catch(StatusException e) { + tRes.tested("hasPendingChanges()", Status.exception(e)); + return; + } + boolean hasPendingChanges = oObj.hasPendingChanges(); + tRes.tested("hasPendingChanges()", hasPendingChanges); } + private void executeChange(Object element) throws StatusException { + if (xProp != null) { + try { + xProp.setPropertyValue(elementName, element); + } + catch(com.sun.star.uno.Exception e) { + throw new StatusException("Could not set property '" + elementName + "'.", e); + } + } + else if (xNameReplace != null) { + try { + xNameReplace.replaceByName(elementName, element); + } + catch(com.sun.star.uno.Exception e) { + throw new StatusException("Could not replace '" + elementName + "' by name.", e); + } + } + } } diff --git a/qadevOOo/tests/java/ifc/util/_XChangesNotifier.java b/qadevOOo/tests/java/ifc/util/_XChangesNotifier.java index 66686ac6ca94..af1ed91a5c57 100644 --- a/qadevOOo/tests/java/ifc/util/_XChangesNotifier.java +++ b/qadevOOo/tests/java/ifc/util/_XChangesNotifier.java @@ -2,9 +2,9 @@ * * $RCSfile: _XChangesNotifier.java,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change:$Date: 2003-09-08 11:29:27 $ + * last change:$Date: 2003-12-11 11:49:03 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,23 +61,196 @@ package ifc.util; -import lib.MultiMethodTest; - +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameReplace; +import com.sun.star.util.XChangesBatch; +import com.sun.star.util.XChangesListener; import com.sun.star.util.XChangesNotifier; +import java.io.PrintWriter; +import lib.StatusException; +import lib.MultiMethodTest; /** - * - * @author sw93809 + * Test the XChangesNotifier interface. To produce some changes, + * XChangesBatch is used. + * @see com.sun.star.util.XChangesNotifier + * @see com.sun.star.util.XChangesBatch */ public class _XChangesNotifier extends MultiMethodTest { - public XChangesNotifier oObj; + public XChangesNotifier oObj = null; + private XChangesBatch xBatch = null; + private Object changeElement = null; + private Object originalElement = null; + private String elementName = null; + private XPropertySet xProp = null; + private XNameReplace xNameReplace = null; + private _XChangesNotifier.MyChangesListener xListener = null; + + /** + * Own implementation of the XChangesListener interface + * @see com.sun.star.util.XChangesListener + */ + private static class MyChangesListener implements XChangesListener { + /** Just lo a call of the listener **/ + boolean bChangesOccured = false; + + /** A change did occur + * @param changesEvent The event. + **/ + public void changesOccurred(com.sun.star.util.ChangesEvent changesEvent) { + bChangesOccured = true; + } + + /** Disposing of the listener + * @param eventObject The event. + **/ + public void disposing(com.sun.star.lang.EventObject eventObject) { + bChangesOccured = true; + } + + /** + * Reset the listener + */ + public void reset() { + bChangesOccured = false; + } + + /** + * Has the listener been called? + * @return True, if the listener has been called. + */ + public boolean didChangesOccur() { + return bChangesOccured; + } + } + + /** + * Before the test: get the 'XChangesNotifier.ChangesBatch' object relation + * and create the listener. + */ + protected void before() { + xBatch = (XChangesBatch)tEnv.getObjRelation("XChangesNotifier.ChangesBatch"); + changeElement = tEnv.getObjRelation("XChangesNotifier.ChangeElement"); + originalElement = tEnv.getObjRelation("XChangesNotifier.OriginalElement"); + elementName = (String)tEnv.getObjRelation("XChangesNotifier.PropertyName"); + xProp = (XPropertySet)tEnv.getObjRelation("XChangesNotifier.PropertySet"); + try { + if (originalElement == null && xProp != null) + originalElement = xProp.getPropertyValue(elementName); + } + catch(com.sun.star.uno.Exception e) { + throw new StatusException("Could not get property '" + elementName + "'.", e); + } + // or get an XNameReplace + xNameReplace = (XNameReplace)tEnv.getObjRelation("XChangesNotifier.NameReplace"); + try { + if (originalElement == null && xNameReplace != null) + originalElement = xNameReplace.getByName(elementName); + } + catch(com.sun.star.uno.Exception e) { + throw new StatusException("Could not get element by name '" + elementName + "'.", e); + } + + if (changeElement == null || originalElement == null || elementName == null || (xProp == null && xNameReplace == null) || xBatch == null) { + log.println( + changeElement == null?"Missing property 'XChangesNotifier.ChangeElement'\n":"" + + originalElement == null?"Missing property 'XChangesNotifier.OriginalElement'\n":"" + + elementName == null?"Missing property 'XChangesNotifier.PropertyName'\n":"" + + xProp == null?"Missing property 'XChangesNotifier.PropertySet'":"" + + xNameReplace == null?"Missing property 'XChangesNotifier.NameReplace'":"" + + xBatch == null?"Missing property 'XChangesNotifier.ChangesBatch'":"" + ); + throw new StatusException("Some needed object relations are missing.", new Exception()); + } + + xListener = new _XChangesNotifier.MyChangesListener(); + } + + /** test addChangesListener **/ public void _addChangesListener() { + oObj.addChangesListener(xListener); + tRes.tested("addChangesListener()", true); } + /** test removeChangesListener **/ public void _removeChangesListener() { + requiredMethod("addChangesListener()"); + boolean result = true; + result &= commitChanges(); + result &= xListener.didChangesOccur(); + if (!result) + log.println("Listener has not been called."); + oObj.removeChangesListener(xListener); + xListener.reset(); + result &= redoChanges(); + boolean result2 = xListener.didChangesOccur(); + if (result2) + log.println("Removed listener has been called."); + + tRes.tested("removeChangesListener()", result && !result2); + } + + /** + * Commit a change, using an implementation of the XChangesBatch interface. + * @return true, if changing worked. + */ + private boolean commitChanges() { + if (!executeChange(changeElement)) return false; + if (!xBatch.hasPendingChanges()) return false; + try { + xBatch.commitChanges(); + } + catch(com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace((PrintWriter)log); + return false; + } + return true; + } + + /** + * Redo the change, using an implementation of the XChangesBatch interface. + * @return true, if changing worked. + */ + private boolean redoChanges() { + if (!executeChange(originalElement)) return false; + if (!xBatch.hasPendingChanges()) return false; + try { + xBatch.commitChanges(); + } + catch(com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace((PrintWriter)log); + return false; + } + return true; + } + + /** + * Execute the change, use XPropertySet or XNameReplace + * @return False, if changing did throw an exception. + */ + private boolean executeChange(Object element) throws StatusException { + if (xProp != null) { + try { + xProp.setPropertyValue(elementName, element); + } + catch(com.sun.star.uno.Exception e) { + e.printStackTrace((PrintWriter)log); + return false; + } + } + else if (xNameReplace != null) { + try { + xNameReplace.replaceByName(elementName, element); + } + catch(com.sun.star.uno.Exception e) { + e.printStackTrace((PrintWriter)log); + return false; + } + } + return true; } } |