1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.awt;
29 
30 import com.sun.star.awt.AsyncCallback;
31 import com.sun.star.awt.Rectangle;
32 import com.sun.star.awt.XCallback;
33 import com.sun.star.awt.XMessageBox;
34 import com.sun.star.awt.XMessageBoxFactory;
35 import com.sun.star.awt.XRequestCallback;
36 import com.sun.star.awt.XWindow;
37 import com.sun.star.awt.XWindowPeer;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.uno.Any;
40 import com.sun.star.uno.UnoRuntime;
41 import lib.MultiMethodTest;
42 import util.UITools;
43 
44 /**
45  * Testing <code>com.sun.star.awt.XMessageBoxFactory</code>
46  * interface methods :
47  * <ul>
48  *  <li><code> </code>createMessageBox()</li>
49  * </ul> <p>
50  * Test is <b> NOT </b> multithread compilant. <p>
51  * @see com.sun.star.awt.XMessageBoxFactory
52  */
53 public class _XMessageBoxFactory extends MultiMethodTest {
54     public XMessageBoxFactory oObj = null;
55 
56     public void _createMessageBox() {
57         final XMessageBox mb = oObj.createMessageBox(
58             (XWindowPeer) tEnv.getObjRelation("WINPEER"),
59             new Rectangle(0, 0, 100, 100), "errorbox", 1, "The Title",
60             "The Message");
61         final UITools tools = new UITools(
62             (XMultiServiceFactory) tParam.getMSF(),
63             UnoRuntime.queryInterface(XWindow.class, mb));
64         final boolean[] done = new boolean[] { false };
65         final boolean[] good = new boolean[] { false };
66         XRequestCallback async = AsyncCallback.create(
67             tParam.getComponentContext());
68         async.addCallback(
69             new XCallback() {
70                 public void notify(Object aData) {
71                     mb.execute();
72                     synchronized (done) {
73                         done[0] = true;
74                         done.notifyAll();
75                     }
76                 }
77             },
78             Any.VOID);
79         async.addCallback(
80             new XCallback() {
81                 public void notify(Object aData) {
82                     try {
83                         tools.clickButton("OK");
84                     } catch (RuntimeException e) {
85                         throw e;
86                     } catch (Exception e) {
87                         throw new RuntimeException(e);
88                     }
89                     synchronized (good) {
90                         good[0] = true;
91                     }
92                 }
93             },
94             Any.VOID);
95         synchronized (done) {
96             while (!done[0]) {
97                 try {
98                     done.wait();
99                 } catch (InterruptedException e) {
100                     throw new RuntimeException(e);
101                 }
102             }
103         }
104         boolean ok;
105         synchronized (good) {
106             ok = good[0];
107         }
108         tRes.tested("createMessageBox()", ok);
109     }
110 }
111