1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.awt;
25 
26 import com.sun.star.awt.AsyncCallback;
27 import com.sun.star.awt.Rectangle;
28 import com.sun.star.awt.XCallback;
29 import com.sun.star.awt.XMessageBox;
30 import com.sun.star.awt.XMessageBoxFactory;
31 import com.sun.star.awt.XRequestCallback;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.awt.XWindowPeer;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.uno.Any;
36 import com.sun.star.uno.UnoRuntime;
37 import lib.MultiMethodTest;
38 import util.UITools;
39 
40 /**
41  * Testing <code>com.sun.star.awt.XMessageBoxFactory</code>
42  * interface methods :
43  * <ul>
44  *  <li><code> </code>createMessageBox()</li>
45  * </ul> <p>
46  * Test is <b> NOT </b> multithread compilant. <p>
47  * @see com.sun.star.awt.XMessageBoxFactory
48  */
49 public class _XMessageBoxFactory extends MultiMethodTest {
50     public XMessageBoxFactory oObj = null;
51 
_createMessageBox()52     public void _createMessageBox() {
53         final XMessageBox mb = oObj.createMessageBox(
54             (XWindowPeer) tEnv.getObjRelation("WINPEER"),
55             com.sun.star.awt.MessageBoxType.ERRORBOX, 1, "The Title",
56             "The Message");
57         final UITools tools = new UITools(
58             (XMultiServiceFactory) tParam.getMSF(),
59             UnoRuntime.queryInterface(XWindow.class, mb));
60         final boolean[] done = new boolean[] { false };
61         final boolean[] good = new boolean[] { false };
62         XRequestCallback async = AsyncCallback.create(
63             tParam.getComponentContext());
64         async.addCallback(
65             new XCallback() {
66                 public void notify(Object aData) {
67                     mb.execute();
68                     synchronized (done) {
69                         done[0] = true;
70                         done.notifyAll();
71                     }
72                 }
73             },
74             Any.VOID);
75         async.addCallback(
76             new XCallback() {
77                 public void notify(Object aData) {
78                     try {
79                         tools.clickButton("OK");
80                     } catch (RuntimeException e) {
81                         throw e;
82                     } catch (Exception e) {
83                         throw new RuntimeException(e);
84                     }
85                     synchronized (good) {
86                         good[0] = true;
87                     }
88                 }
89             },
90             Any.VOID);
91         synchronized (done) {
92             while (!done[0]) {
93                 try {
94                     done.wait();
95                 } catch (InterruptedException e) {
96                     throw new RuntimeException(e);
97                 }
98             }
99         }
100         boolean ok;
101         synchronized (good) {
102             ok = good[0];
103         }
104         tRes.tested("createMessageBox()", ok);
105     }
106 }
107