summaryrefslogtreecommitdiff
path: root/qadevOOo/tests
diff options
context:
space:
mode:
authorsb <sb@openoffice.org>2010-02-25 10:25:07 +0100
committersb <sb@openoffice.org>2010-02-25 10:25:07 +0100
commit8c8f794ad853f5a5d36be67f58496b1e9c2b3f09 (patch)
treec43be990524f29980d311a31b3420573672cbe94 /qadevOOo/tests
parent5fe7ed663401b3e05c3e6ab5594d117899aed263 (diff)
sb118: #i80788# further improved XMessageBoxFactory test to avoid random sleeps
Diffstat (limited to 'qadevOOo/tests')
-rw-r--r--qadevOOo/tests/java/ifc/awt/_XMessageBoxFactory.java136
1 files changed, 50 insertions, 86 deletions
diff --git a/qadevOOo/tests/java/ifc/awt/_XMessageBoxFactory.java b/qadevOOo/tests/java/ifc/awt/_XMessageBoxFactory.java
index bc2a2ed228b9..d7347e3d2acd 100644
--- a/qadevOOo/tests/java/ifc/awt/_XMessageBoxFactory.java
+++ b/qadevOOo/tests/java/ifc/awt/_XMessageBoxFactory.java
@@ -30,18 +30,18 @@
package ifc.awt;
+import com.sun.star.awt.AsyncCallback;
import com.sun.star.awt.Rectangle;
+import com.sun.star.awt.XCallback;
+import com.sun.star.awt.XMessageBox;
+import com.sun.star.awt.XMessageBoxFactory;
+import com.sun.star.awt.XRequestCallback;
+import com.sun.star.awt.XWindow;
import com.sun.star.awt.XWindowPeer;
import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.Any;
import com.sun.star.uno.UnoRuntime;
import lib.MultiMethodTest;
-
-import com.sun.star.awt.XMessageBox;
-import com.sun.star.awt.XMessageBoxFactory;
-import com.sun.star.awt.XWindow;
-import java.io.PrintWriter;
-import lib.Status;
-import lib.StatusException;
import util.UITools;
/**
@@ -54,94 +54,58 @@ import util.UITools;
* @see com.sun.star.awt.XMessageBoxFactory
*/
public class _XMessageBoxFactory extends MultiMethodTest {
-
public XMessageBoxFactory oObj = null;
- private XWindowPeer the_win = null;
-
- /**
- * Retrieves object relation.
- * @throws StatusException If the relation not found.
- */
- public void before() {
- the_win = (XWindowPeer) tEnv.getObjRelation("WINPEER");
- if (the_win == null)
- throw new StatusException(Status.failed("Relation 'WINPEER' not found")) ;
- }
-
-
- /**
- * As <code>execute()</code> method is a blocking call,
- * then it must be executed in a separate thread. This
- * thread class just call <code>execute</code> method
- * of tested object.
- */
- protected Thread execThread = new Thread(
- new Runnable() {
- public void run() {
- Rectangle rect = new Rectangle(0,0,100,100);
- XMessageBox mb = oObj.createMessageBox(the_win, rect, "errorbox", 1, "The Title", "The Message") ;
- synchronized (this) {
- messageBox = mb;
- notifyAll();
- }
- mb.execute();
- }
- }) ;
- private XMessageBox messageBox = null;
-
- /**
- * Starts the execution of MessageBox in a separate thread.
- * As this call is blocking then the thread execution
- * must not be finished. <p>
- * Has <b>OK</b> status if thread wasn't finished and
- * no exceptions occured.
- */
public void _createMessageBox() {
- boolean result = true ;
-
- log.println("Starting createMessageBox() thread ...") ;
- execThread.start() ;
-
- try {
- execThread.join(200) ;
- } catch (InterruptedException e) {
- log.println("createMessageBox() thread was interrupted") ;
- result = false ;
- }
- result &= execThread.isAlive() ;
-
- synchronized (execThread) {
- while (messageBox == null) {
+ final XMessageBox mb = oObj.createMessageBox(
+ (XWindowPeer) tEnv.getObjRelation("WINPEER"),
+ new Rectangle(0, 0, 100, 100), "errorbox", 1, "The Title",
+ "The Message");
+ final UITools tools = new UITools(
+ (XMultiServiceFactory) tParam.getMSF(),
+ UnoRuntime.queryInterface(XWindow.class, mb));
+ final State[] state = new State[] { State.NONE };
+ XRequestCallback async = AsyncCallback.create(
+ tParam.getComponentContext());
+ async.addCallback(
+ new XCallback() {
+ public void notify(Object aData) {
+ mb.execute();
+ }
+ },
+ Any.VOID);
+ async.addCallback(
+ new XCallback() {
+ public void notify(Object aData) {
+ boolean ok = true;
+ try {
+ tools.clickButton("OK");
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ ok = false;
+ }
+ synchronized (state) {
+ state[0] = ok ? State.GOOD : State.BAD;
+ state.notifyAll();
+ }
+ }
+ },
+ Any.VOID);
+ boolean ok;
+ synchronized (state) {
+ while (state[0] == State.NONE) {
try {
- execThread.wait();
+ state.wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
+ ok = state[0] == State.GOOD;
}
- try {
- Thread.currentThread().sleep(500);
- } catch(InterruptedException e) {
- throw new RuntimeException(e);
- }
- UITools oUITools = new UITools(
- (XMultiServiceFactory) tParam.getMSF(),
- UnoRuntime.queryInterface(XWindow.class, messageBox));
- try{
- oUITools.printAccessibleTree(log, tParam.getBool("DebugIsActive"));
-
- oUITools.clickButton("OK");
-
- } catch (java.lang.Exception e) {
- e.printStackTrace((PrintWriter) log);
- log.println("Could not cklick 'OK' on messagebox: " + e.toString());
- result = false;
- }
-
- tRes.tested("createMessageBox()", result) ;
+ tRes.tested("createMessageBox()", ok);
}
+ private enum State { NONE, GOOD, BAD };
}
-
-