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