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.XControl;
29 import com.sun.star.awt.XControlModel;
30 import com.sun.star.awt.XToolkit;
31 import com.sun.star.awt.XView;
32 import com.sun.star.awt.XWindowPeer;
33 import com.sun.star.uno.XInterface;
34 
35 /**
36 * Testing <code>com.sun.star.awt.XControl</code>
37 * interface methods:
38 * <ul>
39 *  <li><code> setContext() </code></li>
40 *  <li><code> getContext() </code></li>
41 *  <li><code> createPeer() </code></li>
42 *  <li><code> getPeer() </code></li>
43 *  <li><code> setModel() </code></li>
44 *  <li><code> getModel() </code></li>
45 *  <li><code> setDesignMode() </code></li>
46 *  <li><code> isDesignMode() </code></li>
47 *  <li><code> isTransparent() </code></li>
48 *  <li><code> getView() </code></li>
49 * </ul><p>
50 * This test needs the following object relations :
51 * <ul>
52 *  <li> <code>'CONTEXT'</code> (of type <code>XInterface</code>):
53 *  used as a parameter to setContext() and for testing getContext().</li>
54 *  <li> <code>'WINPEER'</code> (of type <code>XWindowPeer</code>):
55 *  used as a parameter to createPeer() and for testing getPeer()</li>
56 *  <li> <code>'TOOLKIT'</code> (of type <code>XToolkit</code>):
57 *  used as a parameter to createPeer()</li>
58 *  <li> <code>'MODEL'</code> (of type <code>XControlModel</code>):
59 *  used as a parameter to setModel() and for testing getModel()</li>
60 * <ul> <p>
61 * Test is <b> NOT </b> multithread compilant. <p>
62 * @see com.sun.star.awt.XControl
63 */
64 public class _XControl extends MultiMethodTest {
65     public XControl oObj = null;
66     public XControlModel aModel = null;
67     public boolean desMode;
68 
69     /**
70     * After test calls the method, the Context is set to a corresponding
71     * object relation.<p>
72     * Has <b> OK </b> status if the method successfully returns
73     * and no exceptions were thrown. <p>
74     */
_setContext()75     public void _setContext() {
76         XInterface cont = (XInterface) tEnv.getObjRelation("CONTEXT");
77         oObj.setContext(cont);
78         tRes.tested("setContext()",true);
79     }
80 
81     /**
82     * After test calls the method, the Context is gotten and compared
83     * with object relation 'CONTEXT'.<p>
84     * Has <b> OK </b> status if get value is equals to value set before.<p>
85     * The following method tests are to be completed successfully before:
86     * <ul>
87     *  <li> <code> setContext() </code> : set Context to a corresponding
88     * object relation</li>
89     * </ul>
90     */
_getContext()91     public void _getContext() {
92         requiredMethod("setContext()");
93         XInterface cont = (XInterface) tEnv.getObjRelation("CONTEXT");
94         Object get = oObj.getContext();
95         boolean res = get.equals(cont);
96         if (!res) {
97             log.println("!!! Error: getting: "+get.toString());
98             log.println("!!! expected: "+cont.toString());
99         }
100         tRes.tested("getContext()",res);
101     }
102 
103 
104     /**
105     * The objects needed to create peer are obtained
106     * from corresponding object relations, then the peer is created.
107     * <p>
108     * Has <b> OK </b> status if the method successfully returns
109     * and no exceptions were thrown.
110     */
_createPeer()111     public void _createPeer() {
112         XWindowPeer the_win = (XWindowPeer) tEnv.getObjRelation("WINPEER");
113         XToolkit the_kit = (XToolkit) tEnv.getObjRelation("TOOLKIT");
114         oObj.createPeer(the_kit,the_win);
115         tRes.tested("createPeer()",true);
116     }
117 
118     /**
119     * Test calls the method. Then the the object ralation 'WINPEER' is
120     * obtained, and compared with the peer, gotten from (XControl) oObj
121     * variable.<p>
122     * Has <b> OK </b> status if peer gotten isn't null
123     * The following method tests are to be completed successfully before :
124     */
_getPeer()125     public void _getPeer() {
126         requiredMethod("createPeer()");
127         boolean res = false;
128         XWindowPeer get = oObj.getPeer();
129         if (get == null) {
130             log.println("The method 'getPeer' returns NULL");
131         } else {
132            res = true;
133         }
134         tRes.tested("getPeer()",res);
135     }
136 
137 
138     /**
139     * At first current model is obtained and saved to variable aModel.
140     * Then object relation 'MODEL' is gotten and test calls the method. <p>
141     * Has <b> OK </b> status if the method successfully returns
142     * and no exceptions were thrown.
143     */
_setModel()144     public void _setModel() {
145         aModel = oObj.getModel();
146         XControlModel the_model = (XControlModel) tEnv.getObjRelation("MODEL");
147         oObj.setModel(the_model);
148         tRes.tested("setModel()",true);
149     }
150 
151     /**
152     * Test calls the method, then object relation 'MODEL' is gotten and
153     * compared with object returned by the method. Then previously saved
154     * value of model (aModel) restored to (XControl) oObj<p>
155     * Has <b> OK </b> status if models set and get are equal. <p>
156     * The following method tests are to be completed successfully before :
157     * <ul>
158     *  <li> <code> setModel() </code> : setting model from corresponding
159     *  object relation </li>
160     * </ul>
161     */
_getModel()162     public void _getModel() {
163         requiredMethod("setModel()");
164         XControlModel the_model = (XControlModel) tEnv.getObjRelation("MODEL");
165         XControlModel get = oObj.getModel();
166         boolean res = (get.equals(the_model));
167         if (!res) {
168             log.println("getting: "+get.toString());
169             log.println("expected: "+the_model.toString());
170         }
171         if (aModel != null) {
172         oObj.setModel(aModel);
173     }
174         tRes.tested("getModel()",res);
175     }
176 
177     /**
178     * Test calls the method. Then mode is checked using isDesignMode().<p>
179     * Has <b> OK </b> status if mode is swithed.
180     */
_setDesignMode()181     public void _setDesignMode() {
182     desMode = oObj.isDesignMode();
183         oObj.setDesignMode(!desMode);
184         tRes.tested("setDesignMode()",oObj.isDesignMode() == !desMode);
185     }
186 
187     /**
188     * The mode is changed and result is checked.<p>
189     * Has <b> OK </b> status if the mode changed successfully.
190     */
_isDesignMode()191     public void _isDesignMode() {
192     requiredMethod("setDesignMode()");
193         oObj.setDesignMode(desMode);
194         tRes.tested("isDesignMode()", oObj.isDesignMode() == desMode);
195     }
196 
197     /**
198     * Test calls the method.<p>
199     * Has <b> OK </b> status if the method successfully returns
200     * and no exceptions were thrown. <p>
201     */
_isTransparent()202     public void _isTransparent() {
203         boolean isT = oObj.isTransparent();
204         tRes.tested("isTransparent()",true );
205     }
206 
207     /**
208     * Test calls the method.<p>
209     * Has <b> OK </b> status if the method returns not null. <p>
210     */
_getView()211     public void _getView() {
212         XView the_view = oObj.getView();
213         tRes.tested("getView()", the_view != null);
214     }
215 
216 }
217 
218 
219