1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski package ifc.awt;
25*b1cdbd2cSJim Jagielski 
26*b1cdbd2cSJim Jagielski import lib.MultiMethodTest;
27*b1cdbd2cSJim Jagielski 
28*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControl;
29*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControlModel;
30*b1cdbd2cSJim Jagielski import com.sun.star.awt.XToolkit;
31*b1cdbd2cSJim Jagielski import com.sun.star.awt.XView;
32*b1cdbd2cSJim Jagielski import com.sun.star.awt.XWindowPeer;
33*b1cdbd2cSJim Jagielski import com.sun.star.uno.XInterface;
34*b1cdbd2cSJim Jagielski 
35*b1cdbd2cSJim Jagielski /**
36*b1cdbd2cSJim Jagielski * Testing <code>com.sun.star.awt.XControl</code>
37*b1cdbd2cSJim Jagielski * interface methods:
38*b1cdbd2cSJim Jagielski * <ul>
39*b1cdbd2cSJim Jagielski *  <li><code> setContext() </code></li>
40*b1cdbd2cSJim Jagielski *  <li><code> getContext() </code></li>
41*b1cdbd2cSJim Jagielski *  <li><code> createPeer() </code></li>
42*b1cdbd2cSJim Jagielski *  <li><code> getPeer() </code></li>
43*b1cdbd2cSJim Jagielski *  <li><code> setModel() </code></li>
44*b1cdbd2cSJim Jagielski *  <li><code> getModel() </code></li>
45*b1cdbd2cSJim Jagielski *  <li><code> setDesignMode() </code></li>
46*b1cdbd2cSJim Jagielski *  <li><code> isDesignMode() </code></li>
47*b1cdbd2cSJim Jagielski *  <li><code> isTransparent() </code></li>
48*b1cdbd2cSJim Jagielski *  <li><code> getView() </code></li>
49*b1cdbd2cSJim Jagielski * </ul><p>
50*b1cdbd2cSJim Jagielski * This test needs the following object relations :
51*b1cdbd2cSJim Jagielski * <ul>
52*b1cdbd2cSJim Jagielski *  <li> <code>'CONTEXT'</code> (of type <code>XInterface</code>):
53*b1cdbd2cSJim Jagielski *  used as a parameter to setContext() and for testing getContext().</li>
54*b1cdbd2cSJim Jagielski *  <li> <code>'WINPEER'</code> (of type <code>XWindowPeer</code>):
55*b1cdbd2cSJim Jagielski *  used as a parameter to createPeer() and for testing getPeer()</li>
56*b1cdbd2cSJim Jagielski *  <li> <code>'TOOLKIT'</code> (of type <code>XToolkit</code>):
57*b1cdbd2cSJim Jagielski *  used as a parameter to createPeer()</li>
58*b1cdbd2cSJim Jagielski *  <li> <code>'MODEL'</code> (of type <code>XControlModel</code>):
59*b1cdbd2cSJim Jagielski *  used as a parameter to setModel() and for testing getModel()</li>
60*b1cdbd2cSJim Jagielski * <ul> <p>
61*b1cdbd2cSJim Jagielski * Test is <b> NOT </b> multithread compilant. <p>
62*b1cdbd2cSJim Jagielski * @see com.sun.star.awt.XControl
63*b1cdbd2cSJim Jagielski */
64*b1cdbd2cSJim Jagielski public class _XControl extends MultiMethodTest {
65*b1cdbd2cSJim Jagielski     public XControl oObj = null;
66*b1cdbd2cSJim Jagielski     public XControlModel aModel = null;
67*b1cdbd2cSJim Jagielski     public boolean desMode;
68*b1cdbd2cSJim Jagielski 
69*b1cdbd2cSJim Jagielski     /**
70*b1cdbd2cSJim Jagielski     * After test calls the method, the Context is set to a corresponding
71*b1cdbd2cSJim Jagielski     * object relation.<p>
72*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if the method successfully returns
73*b1cdbd2cSJim Jagielski     * and no exceptions were thrown. <p>
74*b1cdbd2cSJim Jagielski     */
_setContext()75*b1cdbd2cSJim Jagielski     public void _setContext() {
76*b1cdbd2cSJim Jagielski         XInterface cont = (XInterface) tEnv.getObjRelation("CONTEXT");
77*b1cdbd2cSJim Jagielski         oObj.setContext(cont);
78*b1cdbd2cSJim Jagielski         tRes.tested("setContext()",true);
79*b1cdbd2cSJim Jagielski     }
80*b1cdbd2cSJim Jagielski 
81*b1cdbd2cSJim Jagielski     /**
82*b1cdbd2cSJim Jagielski     * After test calls the method, the Context is gotten and compared
83*b1cdbd2cSJim Jagielski     * with object relation 'CONTEXT'.<p>
84*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if get value is equals to value set before.<p>
85*b1cdbd2cSJim Jagielski     * The following method tests are to be completed successfully before:
86*b1cdbd2cSJim Jagielski     * <ul>
87*b1cdbd2cSJim Jagielski     *  <li> <code> setContext() </code> : set Context to a corresponding
88*b1cdbd2cSJim Jagielski     * object relation</li>
89*b1cdbd2cSJim Jagielski     * </ul>
90*b1cdbd2cSJim Jagielski     */
_getContext()91*b1cdbd2cSJim Jagielski     public void _getContext() {
92*b1cdbd2cSJim Jagielski         requiredMethod("setContext()");
93*b1cdbd2cSJim Jagielski         XInterface cont = (XInterface) tEnv.getObjRelation("CONTEXT");
94*b1cdbd2cSJim Jagielski         Object get = oObj.getContext();
95*b1cdbd2cSJim Jagielski         boolean res = get.equals(cont);
96*b1cdbd2cSJim Jagielski         if (!res) {
97*b1cdbd2cSJim Jagielski             log.println("!!! Error: getting: "+get.toString());
98*b1cdbd2cSJim Jagielski             log.println("!!! expected: "+cont.toString());
99*b1cdbd2cSJim Jagielski         }
100*b1cdbd2cSJim Jagielski         tRes.tested("getContext()",res);
101*b1cdbd2cSJim Jagielski     }
102*b1cdbd2cSJim Jagielski 
103*b1cdbd2cSJim Jagielski 
104*b1cdbd2cSJim Jagielski     /**
105*b1cdbd2cSJim Jagielski     * The objects needed to create peer are obtained
106*b1cdbd2cSJim Jagielski     * from corresponding object relations, then the peer is created.
107*b1cdbd2cSJim Jagielski     * <p>
108*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if the method successfully returns
109*b1cdbd2cSJim Jagielski     * and no exceptions were thrown.
110*b1cdbd2cSJim Jagielski     */
_createPeer()111*b1cdbd2cSJim Jagielski     public void _createPeer() {
112*b1cdbd2cSJim Jagielski         XWindowPeer the_win = (XWindowPeer) tEnv.getObjRelation("WINPEER");
113*b1cdbd2cSJim Jagielski         XToolkit the_kit = (XToolkit) tEnv.getObjRelation("TOOLKIT");
114*b1cdbd2cSJim Jagielski         oObj.createPeer(the_kit,the_win);
115*b1cdbd2cSJim Jagielski         tRes.tested("createPeer()",true);
116*b1cdbd2cSJim Jagielski     }
117*b1cdbd2cSJim Jagielski 
118*b1cdbd2cSJim Jagielski     /**
119*b1cdbd2cSJim Jagielski     * Test calls the method. Then the the object ralation 'WINPEER' is
120*b1cdbd2cSJim Jagielski     * obtained, and compared with the peer, gotten from (XControl) oObj
121*b1cdbd2cSJim Jagielski     * variable.<p>
122*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if peer gotten isn't null
123*b1cdbd2cSJim Jagielski     * The following method tests are to be completed successfully before :
124*b1cdbd2cSJim Jagielski     */
_getPeer()125*b1cdbd2cSJim Jagielski     public void _getPeer() {
126*b1cdbd2cSJim Jagielski         requiredMethod("createPeer()");
127*b1cdbd2cSJim Jagielski         boolean res = false;
128*b1cdbd2cSJim Jagielski         XWindowPeer get = oObj.getPeer();
129*b1cdbd2cSJim Jagielski         if (get == null) {
130*b1cdbd2cSJim Jagielski             log.println("The method 'getPeer' returns NULL");
131*b1cdbd2cSJim Jagielski         } else {
132*b1cdbd2cSJim Jagielski            res = true;
133*b1cdbd2cSJim Jagielski         }
134*b1cdbd2cSJim Jagielski         tRes.tested("getPeer()",res);
135*b1cdbd2cSJim Jagielski     }
136*b1cdbd2cSJim Jagielski 
137*b1cdbd2cSJim Jagielski 
138*b1cdbd2cSJim Jagielski     /**
139*b1cdbd2cSJim Jagielski     * At first current model is obtained and saved to variable aModel.
140*b1cdbd2cSJim Jagielski     * Then object relation 'MODEL' is gotten and test calls the method. <p>
141*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if the method successfully returns
142*b1cdbd2cSJim Jagielski     * and no exceptions were thrown.
143*b1cdbd2cSJim Jagielski     */
_setModel()144*b1cdbd2cSJim Jagielski     public void _setModel() {
145*b1cdbd2cSJim Jagielski         aModel = oObj.getModel();
146*b1cdbd2cSJim Jagielski         XControlModel the_model = (XControlModel) tEnv.getObjRelation("MODEL");
147*b1cdbd2cSJim Jagielski         oObj.setModel(the_model);
148*b1cdbd2cSJim Jagielski         tRes.tested("setModel()",true);
149*b1cdbd2cSJim Jagielski     }
150*b1cdbd2cSJim Jagielski 
151*b1cdbd2cSJim Jagielski     /**
152*b1cdbd2cSJim Jagielski     * Test calls the method, then object relation 'MODEL' is gotten and
153*b1cdbd2cSJim Jagielski     * compared with object returned by the method. Then previously saved
154*b1cdbd2cSJim Jagielski     * value of model (aModel) restored to (XControl) oObj<p>
155*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if models set and get are equal. <p>
156*b1cdbd2cSJim Jagielski     * The following method tests are to be completed successfully before :
157*b1cdbd2cSJim Jagielski     * <ul>
158*b1cdbd2cSJim Jagielski     *  <li> <code> setModel() </code> : setting model from corresponding
159*b1cdbd2cSJim Jagielski     *  object relation </li>
160*b1cdbd2cSJim Jagielski     * </ul>
161*b1cdbd2cSJim Jagielski     */
_getModel()162*b1cdbd2cSJim Jagielski     public void _getModel() {
163*b1cdbd2cSJim Jagielski         requiredMethod("setModel()");
164*b1cdbd2cSJim Jagielski         XControlModel the_model = (XControlModel) tEnv.getObjRelation("MODEL");
165*b1cdbd2cSJim Jagielski         XControlModel get = oObj.getModel();
166*b1cdbd2cSJim Jagielski         boolean res = (get.equals(the_model));
167*b1cdbd2cSJim Jagielski         if (!res) {
168*b1cdbd2cSJim Jagielski             log.println("getting: "+get.toString());
169*b1cdbd2cSJim Jagielski             log.println("expected: "+the_model.toString());
170*b1cdbd2cSJim Jagielski         }
171*b1cdbd2cSJim Jagielski         if (aModel != null) {
172*b1cdbd2cSJim Jagielski         oObj.setModel(aModel);
173*b1cdbd2cSJim Jagielski     }
174*b1cdbd2cSJim Jagielski         tRes.tested("getModel()",res);
175*b1cdbd2cSJim Jagielski     }
176*b1cdbd2cSJim Jagielski 
177*b1cdbd2cSJim Jagielski     /**
178*b1cdbd2cSJim Jagielski     * Test calls the method. Then mode is checked using isDesignMode().<p>
179*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if mode is swithed.
180*b1cdbd2cSJim Jagielski     */
_setDesignMode()181*b1cdbd2cSJim Jagielski     public void _setDesignMode() {
182*b1cdbd2cSJim Jagielski     desMode = oObj.isDesignMode();
183*b1cdbd2cSJim Jagielski         oObj.setDesignMode(!desMode);
184*b1cdbd2cSJim Jagielski         tRes.tested("setDesignMode()",oObj.isDesignMode() == !desMode);
185*b1cdbd2cSJim Jagielski     }
186*b1cdbd2cSJim Jagielski 
187*b1cdbd2cSJim Jagielski     /**
188*b1cdbd2cSJim Jagielski     * The mode is changed and result is checked.<p>
189*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if the mode changed successfully.
190*b1cdbd2cSJim Jagielski     */
_isDesignMode()191*b1cdbd2cSJim Jagielski     public void _isDesignMode() {
192*b1cdbd2cSJim Jagielski     requiredMethod("setDesignMode()");
193*b1cdbd2cSJim Jagielski         oObj.setDesignMode(desMode);
194*b1cdbd2cSJim Jagielski         tRes.tested("isDesignMode()", oObj.isDesignMode() == desMode);
195*b1cdbd2cSJim Jagielski     }
196*b1cdbd2cSJim Jagielski 
197*b1cdbd2cSJim Jagielski     /**
198*b1cdbd2cSJim Jagielski     * Test calls the method.<p>
199*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if the method successfully returns
200*b1cdbd2cSJim Jagielski     * and no exceptions were thrown. <p>
201*b1cdbd2cSJim Jagielski     */
_isTransparent()202*b1cdbd2cSJim Jagielski     public void _isTransparent() {
203*b1cdbd2cSJim Jagielski         boolean isT = oObj.isTransparent();
204*b1cdbd2cSJim Jagielski         tRes.tested("isTransparent()",true );
205*b1cdbd2cSJim Jagielski     }
206*b1cdbd2cSJim Jagielski 
207*b1cdbd2cSJim Jagielski     /**
208*b1cdbd2cSJim Jagielski     * Test calls the method.<p>
209*b1cdbd2cSJim Jagielski     * Has <b> OK </b> status if the method returns not null. <p>
210*b1cdbd2cSJim Jagielski     */
_getView()211*b1cdbd2cSJim Jagielski     public void _getView() {
212*b1cdbd2cSJim Jagielski         XView the_view = oObj.getView();
213*b1cdbd2cSJim Jagielski         tRes.tested("getView()", the_view != null);
214*b1cdbd2cSJim Jagielski     }
215*b1cdbd2cSJim Jagielski 
216*b1cdbd2cSJim Jagielski }
217*b1cdbd2cSJim Jagielski 
218*b1cdbd2cSJim Jagielski 
219