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.inspection;
25 
26 import com.sun.star.inspection.XObjectInspector;
27 import com.sun.star.inspection.XObjectInspectorModel;
28 import com.sun.star.inspection.XObjectInspectorUI;
29 import lib.MultiMethodTest;
30 import lib.Status;
31 import lib.StatusException;
32 
33 
34 /**
35  * Testing <code>com.sun.star.inspection.XObjectInspector</code>
36  * interface methods :
37  * <ul>
38  *  <li><code> inspect()</code></li>
39  *  <li><code> InspectorModel()</code></li>
40  * </ul> <p>
41  * Test is <b> NOT </b> multithread compilant. <p>
42  *
43  * This test needs the following object relations :
44  * <ul>
45  *  <li> <code>'XObjectInspector.toInspect'</code>
46  *  (of type <code>Object []</code>):
47  *   acceptable collection of one or more objects which can be inspected by <code>inspect()</code> </li>
48  * <ul> <p>
49  *
50  */
51 
52 public class _XObjectInspector extends MultiMethodTest {
53 
54     /**
55      * the test object
56      */
57     public XObjectInspector oObj = null;
58     /**
59      * This variable was filled with the object relation
60      * <CODE>XObjectInspector.toInspect</CODE> and was used to
61      * test the method <CODE>inspect()</CODE>
62      */
63     public Object[] oInspect = null;
64     /**
65      * This variable was filled with the object relation
66      * <CODE>XObjectInspector.InspectorModelToSet</CODE> and was used to
67      * test the method <CODE>setInspectorModel()</CODE>
68      */
69     public XObjectInspectorModel xSetModel = null;
70 
71     /**
72      * get object relations
73      * <ul>
74      *   <li>XObjectInspector.toInspect</li>
75      * </ul>
76      */
before()77     public void before() {
78 
79         oInspect = (Object[]) tEnv.getObjRelation("XObjectInspector.toInspect");
80 
81         if (oInspect == null) throw new StatusException
82                 (Status.failed("Relation 'XObjectInspector.toInspect' not found.")) ;
83 
84         xSetModel = (XObjectInspectorModel) tEnv.getObjRelation("XObjectInspector.InspectorModelToSet");
85 
86         if (xSetModel == null) throw new StatusException
87                 (Status.failed("Relation 'XObjectInspector.InspectorModelToSet' not found.")) ;
88     }
89 
90     /**
91      * Inspects a new collection of one or more objects given by object realtion
92      * <CODE>XObjectInspector.toInspect</CODE><br>
93      * Has <b>OK</b> status if no runtime exceptions occured.
94      */
_inspect()95     public void _inspect() {
96 
97         boolean result = true;
98 
99         try {
100             oObj.inspect(oInspect);
101 
102         } catch (com.sun.star.util.VetoException e){
103             log.println("ERROR:" + e.toString());
104             result = false;
105         }
106 
107         tRes.tested("inspect()", result) ;
108     }
109 
110     /**
111      * First call the method <CODE>getInspectorModel()</CODE> and save the value<br>
112      * Second call the method <CODE>setInspectorModel()</CODE> with the module variable
113      * <CODE>xSetModel</CODE> as parameter.<br> Then <CODE>getInspectorModel()</CODE>
114      * was called and the returned valued was compared to the saved variable
115      * <CODE>xSetModel</CODE><br>
116      * Has <CODE>OK</CODE> status if the returned value is equal to
117      * <CODE>xSetModel</CODE>.and the saved value is not null.
118      */
_InspectorModel()119     public void _InspectorModel() {
120 
121         log.println("testing 'getInspectorModel()'...");
122         XObjectInspectorModel xGetModel = oObj.getInspectorModel() ;
123 
124         boolean result = xGetModel != null;
125 
126         log.println(result? "got a not null object -> OK" : "got a NULL object -> FAILED");
127 
128         log.println("testing 'setInspectorModel()'...");
129         oObj.setInspectorModel(xSetModel);
130 
131         XObjectInspectorModel xNewModel = oObj.getInspectorModel();
132 
133         if (result) oObj.setInspectorModel(xGetModel);
134 
135         result &= xSetModel.equals(xNewModel);
136 
137         tRes.tested("InspectorModel()", result) ;
138     }
139 
140     /**
141      * Calls the method <CODE>getInspectorUI()</CODE>
142      * Has <b>OK</b> returned value is not null
143      */
_InspectorUI()144     public void _InspectorUI() {
145 
146         XObjectInspectorUI oUI = oObj.getInspectorUI();
147 
148         tRes.tested("InspectorUI()", oUI != null) ;
149 
150     }
151 }
152 
153 
154