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