From 8c8f794ad853f5a5d36be67f58496b1e9c2b3f09 Mon Sep 17 00:00:00 2001 From: sb Date: Thu, 25 Feb 2010 10:25:07 +0100 Subject: sb118: #i80788# further improved XMessageBoxFactory test to avoid random sleeps --- .../tests/java/ifc/awt/_XMessageBoxFactory.java | 136 ++++++++------------- 1 file changed, 50 insertions(+), 86 deletions(-) (limited to 'qadevOOo/tests') 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 execute() method is a blocking call, - * then it must be executed in a separate thread. This - * thread class just call execute 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.

- * Has OK 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 }; } - - -- cgit v1.2.3