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 lib.MultiMethodTest;
27 
28 import com.sun.star.awt.XDialog;
29 
30 /**
31 * Testing <code>com.sun.star.awt.XDialog</code>
32 * interface methods :
33 * <ul>
34 *  <li><code> setTitle()</code></li>
35 *  <li><code> getTitle()</code></li>
36 *  <li><code> execute()</code></li>
37 *  <li><code> endExecute()</code></li>
38 * </ul> <p>
39 * Test is <b> NOT </b> multithread compilant. <p>
40 * After test completion object environment has to be recreated.
41 * @see com.sun.star.awt.XDialog
42 */
43 public class _XDialog extends MultiMethodTest {
44 
45     public XDialog oObj = null;
46 
47     /**
48     * As <code>execute()</code> method is a blocking call,
49     * then it must be executed in a separate thread. This
50     * thread class just call <code>execute</code> method
51     * of tested object.
52     */
53     protected  Thread execThread = new Thread(
54         new Runnable() {
55             public void run() {
56                 oObj.execute() ;
57             }
58         }) ;
59 
60     /**
61     * Sets the title to some string. <p>
62     * Has <b>OK</b> status if no runtime exceptions occurs.
63     */
_setTitle()64     public void _setTitle() {
65 
66         oObj.setTitle("XDialog test") ;
67 
68         tRes.tested("setTitle()", true) ;
69     }
70 
71     /**
72     * Gets the title and compares it to the value set in
73     * <code>setTitle</code> method test. <p>
74     * Has <b>OK</b> status is set/get values are equal.
75     * The following method tests are to be completed successfully before :
76     * <ul>
77     *  <li> <code> setTitle </code>  </li>
78     * </ul>
79     */
_getTitle()80     public void _getTitle() {
81         requiredMethod("setTitle()") ;
82 
83         tRes.tested("getTitle()",
84             "XDialog test".equals(oObj.getTitle())) ;
85     }
86 
87     /**
88     * Starts the execution of dialog in a separate thread.
89     * As this call is blocking then the thread execution
90     * must not be finished. <p>
91     * Has <b>OK</b> status if thread wasn't finished and
92     * no exceptions occured.
93     */
_execute()94     public void _execute() {
95         boolean result = true ;
96 
97         log.println("Starting execute() thread ...") ;
98         execThread.start() ;
99 
100         try {
101             execThread.join(200) ;
102         } catch (InterruptedException e) {
103             log.println("execute() thread was interrupted") ;
104             result = false ;
105         }
106         result &= execThread.isAlive() ;
107 
108         tRes.tested("execute()", result) ;
109     }
110 
111     /**
112     * Calls the method and checks if the execution thread
113     * where <code>execute()</code> method is running was
114     * finished. If <code>execute</code> method didn't return
115     * and still running then thread interrupted. <p>
116     * Has <b>OK</b> status if <code>execute</code> method
117     * call successfully retured.
118     * The following method tests are to be completed successfully before :
119     * <ul>
120     *  <li> <code> execute </code> </li>
121     * </ul>
122     */
_endExecute()123     public void _endExecute() {
124         requiredMethod("execute()") ;
125 
126         boolean result = true ;
127 
128         oObj.endExecute() ;
129 
130         try {
131             execThread.join(200) ;
132         } catch (InterruptedException e) {
133             log.println("execute() thread was interrupted") ;
134             result = false ;
135         }
136 
137         if (execThread.isAlive()) {
138             execThread.interrupt() ;
139         }
140 
141         result &= !execThread.isAlive() ;
142 
143         tRes.tested("endExecute()", result) ;
144     }
145 
146     /**
147     * Disposes object environment.
148     */
after()149     public void after() {
150         disposeEnvironment() ;
151     }
152 }
153 
154 
155