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.frame;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.frame.XModuleManager;
29cdf0e10cSrcweir import lib.MultiMethodTest;
30cdf0e10cSrcweir import lib.Status;
31cdf0e10cSrcweir import lib.StatusException;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException;
34cdf0e10cSrcweir import com.sun.star.frame.UnknownModuleException;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /**
38cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XModuleManager</code>
39cdf0e10cSrcweir * interface methods:
40cdf0e10cSrcweir * <ul>
41cdf0e10cSrcweir *  <li><code> identify() </code></li>
42cdf0e10cSrcweir * </ul><p>
43cdf0e10cSrcweir * This test needs the following object relations :
44cdf0e10cSrcweir * <ul>
45cdf0e10cSrcweir *  <li> <code>'XModuleManager.XFrame'</code> (of type <code>PropertyValue[]</code>):
46cdf0e10cSrcweir *  PropertyValue[n].Value : a XFrame
47cdf0e10cSrcweir *  PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
48cdf0e10cSrcweir *  <li> <code>'XModuleManager.XController'</code> (of type <code>PropertyValue[]</code>):
49cdf0e10cSrcweir *  PropertyValue[n].Value : a XController
50cdf0e10cSrcweir *  PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
51cdf0e10cSrcweir *  <li> <code>'XModuleManager.XModel'</code> (of type <code>PropertyValue[]</code>):
52cdf0e10cSrcweir *  PropertyValue[n].Value : a XFrame
53cdf0e10cSrcweir *  PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
54cdf0e10cSrcweir * </ul> <p>
55cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
56cdf0e10cSrcweir * @see com.sun.star.frame.XModuleManager
57cdf0e10cSrcweir */
58cdf0e10cSrcweir public class _XModuleManager extends MultiMethodTest {
59cdf0e10cSrcweir     /** Test calls the method. <p>
60cdf0e10cSrcweir      * The onject relations <CODE>XModuleManager.XFrame</CODE>,
61cdf0e10cSrcweir      * <CODE>XModuleManager.XController</CODE> and <CODE>XModuleManager.XModel</CODE>
62cdf0e10cSrcweir      * are sequenzes of <CODE>PropertyValue</CODE>. The value of a PropertyValue
63cdf0e10cSrcweir      * containes a <CODE>XFrame</CODE>, <CODE>XController</CODE> or a
64cdf0e10cSrcweir      * <CODE>XModel</CODE>. The name of the PropertyValue contains the expected return
65cdf0e10cSrcweir      * value of method <CODE>indetify()</CODE> if the method was called with
66cdf0e10cSrcweir      * coresponding value.<p>
67cdf0e10cSrcweir      * As enhancement the method <CODE>identify()</CODE> was called with incvalid
68cdf0e10cSrcweir      * parameter. In this case the thrown exceptions was catched.
69cdf0e10cSrcweir      */
70cdf0e10cSrcweir     public XModuleManager oObj = null;
71cdf0e10cSrcweir     /**
72cdf0e10cSrcweir     * Test calls the method. <p>
73cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns expected values, that's equal to
74cdf0e10cSrcweir     * previously obtained object relation 'Frame'.
75cdf0e10cSrcweir     * The following method tests are to be completed successfully before:
76cdf0e10cSrcweir     * <ul>
77cdf0e10cSrcweir     *  <li> <code> attachFrame() </code> : attachs frame obtained object
78cdf0e10cSrcweir     * relation 'Frame' </li>
79cdf0e10cSrcweir     * </ul>
80cdf0e10cSrcweir     */
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     private PropertyValue[] xFrameSeq = null;
83cdf0e10cSrcweir     private PropertyValue[] xControllerSeq = null;
84cdf0e10cSrcweir     private PropertyValue[] xModelSeq = null;
85cdf0e10cSrcweir     /** Retrieves object relations. */
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     public void before() {
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         xFrameSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XFrame") ;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         if (xFrameSeq == null) throw new StatusException
92cdf0e10cSrcweir             (Status.failed("Relation 'xFrameSeq' not found.")) ;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         xControllerSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XController") ;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         if (xControllerSeq == null) throw new StatusException
98cdf0e10cSrcweir             (Status.failed("Relation 'xControllerSeq' not found.")) ;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         xModelSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XModel") ;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         if (xModelSeq == null) throw new StatusException
104cdf0e10cSrcweir             (Status.failed("Relation 'xModelSeq' not found.")) ;
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     /** The method <CODE>identify()</CODE> was tesed for every entry in sequeze of
108cdf0e10cSrcweir      * object relations.
109cdf0e10cSrcweir      */
110cdf0e10cSrcweir     public void _identify() {
111cdf0e10cSrcweir         boolean ok = true;
112cdf0e10cSrcweir         log.println("testing frame sequenze...");
113cdf0e10cSrcweir         ok &= testSequenze(xFrameSeq);
114cdf0e10cSrcweir         log.println("testing controller sequenze...");
115cdf0e10cSrcweir         ok &= testSequenze(xControllerSeq);
116cdf0e10cSrcweir         log.println("testing model sequenze...");
117cdf0e10cSrcweir         ok &= testSequenze(xModelSeq);
118cdf0e10cSrcweir         tRes.tested("identify()", ok);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         log.println("testing invalid objects...");
121cdf0e10cSrcweir         try{
122cdf0e10cSrcweir             oObj.identify(oObj);
123cdf0e10cSrcweir         } catch (IllegalArgumentException e){
124cdf0e10cSrcweir             log.println("expected exception.");
125cdf0e10cSrcweir         } catch (UnknownModuleException e){
126cdf0e10cSrcweir             log.println("expected exception.");
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     private boolean testSequenze(PropertyValue[] sequenze){
131cdf0e10cSrcweir         boolean ok = true;
132cdf0e10cSrcweir         for (int i = 0 ; i < sequenze.length; i++){
133cdf0e10cSrcweir             try{
134cdf0e10cSrcweir                 log.println("testing '" + sequenze[i].Name + "'");
135cdf0e10cSrcweir                 if (oObj.identify(sequenze[i].Value).equals(
136cdf0e10cSrcweir                                                         sequenze[i].Name)){
137cdf0e10cSrcweir                      ok &= ok;
138cdf0e10cSrcweir                 }else{
139cdf0e10cSrcweir                      log.println("failure: returned value: '" +
140cdf0e10cSrcweir                                  oObj.identify(sequenze[i].Value) +
141cdf0e10cSrcweir                                  "' ,expected value: '" + sequenze[i].Name + "'");
142cdf0e10cSrcweir                      ok = false;
143cdf0e10cSrcweir                 }
144cdf0e10cSrcweir             } catch (IllegalArgumentException e){
145cdf0e10cSrcweir                 log.println("Could not get value of sequenze '" +
146cdf0e10cSrcweir                             sequenze[i].Name + "'");
147cdf0e10cSrcweir                 return false;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir             } catch (UnknownModuleException e){
150cdf0e10cSrcweir                 log.println("Could not indetify value of sequenze '" +
151cdf0e10cSrcweir                             sequenze[i].Name + "'");
152cdf0e10cSrcweir                 return false;
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir         return ok;
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160