1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.awt;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.awt.XDialog;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /**
31cdf0e10cSrcweir * Testing <code>com.sun.star.awt.XDialog</code>
32cdf0e10cSrcweir * interface methods :
33cdf0e10cSrcweir * <ul>
34cdf0e10cSrcweir *  <li><code> setTitle()</code></li>
35cdf0e10cSrcweir *  <li><code> getTitle()</code></li>
36cdf0e10cSrcweir *  <li><code> execute()</code></li>
37cdf0e10cSrcweir *  <li><code> endExecute()</code></li>
38cdf0e10cSrcweir * </ul> <p>
39cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
40cdf0e10cSrcweir * After test completion object environment has to be recreated.
41cdf0e10cSrcweir * @see com.sun.star.awt.XDialog
42cdf0e10cSrcweir */
43cdf0e10cSrcweir public class _XDialog extends MultiMethodTest {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     public XDialog oObj = null;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     /**
48cdf0e10cSrcweir     * As <code>execute()</code> method is a blocking call,
49cdf0e10cSrcweir     * then it must be executed in a separate thread. This
50cdf0e10cSrcweir     * thread class just call <code>execute</code> method
51cdf0e10cSrcweir     * of tested object.
52cdf0e10cSrcweir     */
53cdf0e10cSrcweir     protected  Thread execThread = new Thread(
54cdf0e10cSrcweir         new Runnable() {
55cdf0e10cSrcweir             public void run() {
56cdf0e10cSrcweir                 oObj.execute() ;
57cdf0e10cSrcweir             }
58cdf0e10cSrcweir         }) ;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     /**
61cdf0e10cSrcweir     * Sets the title to some string. <p>
62cdf0e10cSrcweir     * Has <b>OK</b> status if no runtime exceptions occurs.
63cdf0e10cSrcweir     */
64cdf0e10cSrcweir     public void _setTitle() {
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         oObj.setTitle("XDialog test") ;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         tRes.tested("setTitle()", true) ;
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     /**
72cdf0e10cSrcweir     * Gets the title and compares it to the value set in
73cdf0e10cSrcweir     * <code>setTitle</code> method test. <p>
74cdf0e10cSrcweir     * Has <b>OK</b> status is set/get values are equal.
75cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
76cdf0e10cSrcweir     * <ul>
77cdf0e10cSrcweir     *  <li> <code> setTitle </code>  </li>
78cdf0e10cSrcweir     * </ul>
79cdf0e10cSrcweir     */
80cdf0e10cSrcweir     public void _getTitle() {
81cdf0e10cSrcweir         requiredMethod("setTitle()") ;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         tRes.tested("getTitle()",
84cdf0e10cSrcweir             "XDialog test".equals(oObj.getTitle())) ;
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     /**
88cdf0e10cSrcweir     * Starts the execution of dialog in a separate thread.
89cdf0e10cSrcweir     * As this call is blocking then the thread execution
90cdf0e10cSrcweir     * must not be finished. <p>
91cdf0e10cSrcweir     * Has <b>OK</b> status if thread wasn't finished and
92cdf0e10cSrcweir     * no exceptions occured.
93cdf0e10cSrcweir     */
94cdf0e10cSrcweir     public void _execute() {
95cdf0e10cSrcweir         boolean result = true ;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         log.println("Starting execute() thread ...") ;
98cdf0e10cSrcweir         execThread.start() ;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         try {
101cdf0e10cSrcweir             execThread.join(200) ;
102cdf0e10cSrcweir         } catch (InterruptedException e) {
103cdf0e10cSrcweir             log.println("execute() thread was interrupted") ;
104cdf0e10cSrcweir             result = false ;
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir         result &= execThread.isAlive() ;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         tRes.tested("execute()", result) ;
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     /**
112cdf0e10cSrcweir     * Calls the method and checks if the execution thread
113cdf0e10cSrcweir     * where <code>execute()</code> method is running was
114cdf0e10cSrcweir     * finished. If <code>execute</code> method didn't return
115cdf0e10cSrcweir     * and still running then thread interrupted. <p>
116cdf0e10cSrcweir     * Has <b>OK</b> status if <code>execute</code> method
117cdf0e10cSrcweir     * call successfully retured.
118cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
119cdf0e10cSrcweir     * <ul>
120cdf0e10cSrcweir     *  <li> <code> execute </code> </li>
121cdf0e10cSrcweir     * </ul>
122cdf0e10cSrcweir     */
123cdf0e10cSrcweir     public void _endExecute() {
124cdf0e10cSrcweir         requiredMethod("execute()") ;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         boolean result = true ;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         oObj.endExecute() ;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         try {
131cdf0e10cSrcweir             execThread.join(200) ;
132cdf0e10cSrcweir         } catch (InterruptedException e) {
133cdf0e10cSrcweir             log.println("execute() thread was interrupted") ;
134cdf0e10cSrcweir             result = false ;
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         if (execThread.isAlive()) {
138cdf0e10cSrcweir             execThread.interrupt() ;
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         result &= !execThread.isAlive() ;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         tRes.tested("endExecute()", result) ;
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     /**
147cdf0e10cSrcweir     * Disposes object environment.
148cdf0e10cSrcweir     */
149cdf0e10cSrcweir     public void after() {
150cdf0e10cSrcweir         disposeEnvironment() ;
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 
155