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