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