1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.awt;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.awt.XControl;
33 import com.sun.star.awt.XControlContainer;
34 
35 /**
36 * Testing <code>com.sun.star.awt.XControlContainer</code>
37 * interface methods:
38 * <ul>
39 *   <li><code> setStatusText() </code></li>
40 *   <li><code> addControl() </code></li>
41 *   <li><code> removeControl() </code></li>
42 *   <li><code> getControl() </code></li>
43 *   <li><code> getControls() </code></li>
44 * </ul><p>
45 * This test needs the following object relations :
46 * <ul>
47 *  <li> <code>'CONTROL1'</code> (of type <code>XControl</code>):
48 *  used as a parameter to addControl(), getControl() and removeControl()</li>
49 *  <li> <code>'CONTROL2'</code> (of type <code>XControl</code>):
50 *  used as a parameter to addControl(), getControl() and removeControl()</li>
51 * <ul> <p>
52 * Test is <b> NOT </b> multithread compilant. <p>
53 * @see com.sun.star.awt.XControlContainer
54 */
55 public class _XControlContainer extends MultiMethodTest {
56     public XControlContainer oObj = null;
57 
58     /**
59     * Test calls the method. <p>
60     * Has <b> OK </b> status if the method successfully returns
61     * and no exceptions were thrown.
62     */
63     public void _setStatusText() {
64         oObj.setStatusText("testing XControlContainer::setStatusText(String)");
65         tRes.tested("setStatusText()",true);
66     }
67 
68     /**
69     * Test calls the method twice - two controls gotten from object relations
70     * 'CONTROL1' and 'CONTROL2' added to container.<p>
71     * Has <b> OK </b> status if the method successfully returns
72     * and no exceptions were thrown.
73     */
74     public void _addControl() {
75         oObj.addControl("CONTROL1", (XControl)tEnv.getObjRelation("CONTROL1"));
76         oObj.addControl("CONTROL2", (XControl)tEnv.getObjRelation("CONTROL2"));
77         tRes.tested("addControl()",true);
78     }
79 
80     /**
81     * Test calls the method with object relation 'CONTROL1' as a
82     * parameter. Then control gotten from container is checked, and if returned
83     * value is null then another control 'CONTROL2' is removed from container,
84     * otherwise returned value of method test is 'false'.<p>
85     * Has <b> OK </b> status if control is removed successfully.<p>
86     * The following method tests are to be completed successfully before :
87     * <ul>
88     *  <li> <code> addControl() </code> : adds control to a container </li>
89     *  <li> <code> getControl() </code> : gets control from container </li>
90     *  <li> <code> getControls() </code> : gets controls from container</li>
91     * </ul>
92     */
93     public void _removeControl() {
94         boolean result = true;
95 
96         requiredMethod("addControl()");
97         requiredMethod("getControl()");
98         requiredMethod("getControls()");
99         oObj.removeControl( (XControl) tEnv.getObjRelation("CONTROL1") );
100         XControl ctrl = oObj.getControl("CONTROL1");
101         if (ctrl != null) {
102             result = false;
103             log.println("'removeControl()' fails; Control still exists");
104         } else {
105             oObj.removeControl( (XControl) tEnv.getObjRelation("CONTROL2") );
106         }
107         tRes.tested("removeControl()", result);
108     }
109 
110     /**
111     * Test calls the method with 'CONTROL1' as a parameter, then we just
112     * compare returned object and object relation 'CONTROL1'.<p>
113     * Has <b> OK </b> status if value returned by the method is equal to
114     * a corresponding object relation.<p>
115     * The following method tests are to be completed successfully before :
116     * <ul>
117     *  <li> <code> addControl() </code> : adds control to a container </li>
118     * </ul>
119     */
120     public void _getControl() {
121         requiredMethod("addControl()");
122         XControl xCtrlComp = oObj.getControl("CONTROL1");
123         XControl xCl = (XControl) tEnv.getObjRelation("CONTROL1");
124         tRes.tested("getControl()", xCtrlComp.equals(xCl));
125     }
126 
127     /**
128     * Test calls the method, then returned value is checked.<p>
129     * Has <b> OK </b> status if returned array consists of at least two
130     * elements.<p>
131     * The following method tests are to be completed successfully before :
132     * <ul>
133     *  <li> <code> addControl() </code> : adds control to a container </li>
134     * </ul>
135     */
136     public void _getControls() {
137         requiredMethod("addControl()");
138         XControl[] xCtrls = oObj.getControls();
139         tRes.tested("getControls()",xCtrls.length >= 2);
140     }
141 }
142 
143