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