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.XControlContainer;
30 
31 /**
32 * Testing <code>com.sun.star.awt.XControlContainer</code>
33 * interface methods:
34 * <ul>
35 *   <li><code> setStatusText() </code></li>
36 *   <li><code> addControl() </code></li>
37 *   <li><code> removeControl() </code></li>
38 *   <li><code> getControl() </code></li>
39 *   <li><code> getControls() </code></li>
40 * </ul><p>
41 * This test needs the following object relations :
42 * <ul>
43 *  <li> <code>'CONTROL1'</code> (of type <code>XControl</code>):
44 *  used as a parameter to addControl(), getControl() and removeControl()</li>
45 *  <li> <code>'CONTROL2'</code> (of type <code>XControl</code>):
46 *  used as a parameter to addControl(), getControl() and removeControl()</li>
47 * <ul> <p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.awt.XControlContainer
50 */
51 public class _XControlContainer extends MultiMethodTest {
52     public XControlContainer oObj = null;
53 
54     /**
55     * Test calls the method. <p>
56     * Has <b> OK </b> status if the method successfully returns
57     * and no exceptions were thrown.
58     */
_setStatusText()59     public void _setStatusText() {
60         oObj.setStatusText("testing XControlContainer::setStatusText(String)");
61         tRes.tested("setStatusText()",true);
62     }
63 
64     /**
65     * Test calls the method twice - two controls gotten from object relations
66     * 'CONTROL1' and 'CONTROL2' added to container.<p>
67     * Has <b> OK </b> status if the method successfully returns
68     * and no exceptions were thrown.
69     */
_addControl()70     public void _addControl() {
71         oObj.addControl("CONTROL1", (XControl)tEnv.getObjRelation("CONTROL1"));
72         oObj.addControl("CONTROL2", (XControl)tEnv.getObjRelation("CONTROL2"));
73         tRes.tested("addControl()",true);
74     }
75 
76     /**
77     * Test calls the method with object relation 'CONTROL1' as a
78     * parameter. Then control gotten from container is checked, and if returned
79     * value is null then another control 'CONTROL2' is removed from container,
80     * otherwise returned value of method test is 'false'.<p>
81     * Has <b> OK </b> status if control is removed successfully.<p>
82     * The following method tests are to be completed successfully before :
83     * <ul>
84     *  <li> <code> addControl() </code> : adds control to a container </li>
85     *  <li> <code> getControl() </code> : gets control from container </li>
86     *  <li> <code> getControls() </code> : gets controls from container</li>
87     * </ul>
88     */
_removeControl()89     public void _removeControl() {
90         boolean result = true;
91 
92         requiredMethod("addControl()");
93         requiredMethod("getControl()");
94         requiredMethod("getControls()");
95         oObj.removeControl( (XControl) tEnv.getObjRelation("CONTROL1") );
96         XControl ctrl = oObj.getControl("CONTROL1");
97         if (ctrl != null) {
98             result = false;
99             log.println("'removeControl()' fails; Control still exists");
100         } else {
101             oObj.removeControl( (XControl) tEnv.getObjRelation("CONTROL2") );
102         }
103         tRes.tested("removeControl()", result);
104     }
105 
106     /**
107     * Test calls the method with 'CONTROL1' as a parameter, then we just
108     * compare returned object and object relation 'CONTROL1'.<p>
109     * Has <b> OK </b> status if value returned by the method is equal to
110     * a corresponding object relation.<p>
111     * The following method tests are to be completed successfully before :
112     * <ul>
113     *  <li> <code> addControl() </code> : adds control to a container </li>
114     * </ul>
115     */
_getControl()116     public void _getControl() {
117         requiredMethod("addControl()");
118         XControl xCtrlComp = oObj.getControl("CONTROL1");
119         XControl xCl = (XControl) tEnv.getObjRelation("CONTROL1");
120         tRes.tested("getControl()", xCtrlComp.equals(xCl));
121     }
122 
123     /**
124     * Test calls the method, then returned value is checked.<p>
125     * Has <b> OK </b> status if returned array consists of at least two
126     * elements.<p>
127     * The following method tests are to be completed successfully before :
128     * <ul>
129     *  <li> <code> addControl() </code> : adds control to a container </li>
130     * </ul>
131     */
_getControls()132     public void _getControls() {
133         requiredMethod("addControl()");
134         XControl[] xCtrls = oObj.getControls();
135         tRes.tested("getControls()",xCtrls.length >= 2);
136     }
137 }
138 
139