1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.frame;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import com.sun.star.frame.XModuleManager;
33*cdf0e10cSrcweir import lib.MultiMethodTest;
34*cdf0e10cSrcweir import lib.Status;
35*cdf0e10cSrcweir import lib.StatusException;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException;
38*cdf0e10cSrcweir import com.sun.star.frame.UnknownModuleException;
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir /**
42*cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XModuleManager</code>
43*cdf0e10cSrcweir * interface methods:
44*cdf0e10cSrcweir * <ul>
45*cdf0e10cSrcweir *  <li><code> identify() </code></li>
46*cdf0e10cSrcweir * </ul><p>
47*cdf0e10cSrcweir * This test needs the following object relations :
48*cdf0e10cSrcweir * <ul>
49*cdf0e10cSrcweir *  <li> <code>'XModuleManager.XFrame'</code> (of type <code>PropertyValue[]</code>):
50*cdf0e10cSrcweir *  PropertyValue[n].Value : a XFrame
51*cdf0e10cSrcweir *  PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
52*cdf0e10cSrcweir *  <li> <code>'XModuleManager.XController'</code> (of type <code>PropertyValue[]</code>):
53*cdf0e10cSrcweir *  PropertyValue[n].Value : a XController
54*cdf0e10cSrcweir *  PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
55*cdf0e10cSrcweir *  <li> <code>'XModuleManager.XModel'</code> (of type <code>PropertyValue[]</code>):
56*cdf0e10cSrcweir *  PropertyValue[n].Value : a XFrame
57*cdf0e10cSrcweir *  PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
58*cdf0e10cSrcweir * </ul> <p>
59*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
60*cdf0e10cSrcweir * @see com.sun.star.frame.XModuleManager
61*cdf0e10cSrcweir */
62*cdf0e10cSrcweir public class _XModuleManager extends MultiMethodTest {
63*cdf0e10cSrcweir     /** Test calls the method. <p>
64*cdf0e10cSrcweir      * The onject relations <CODE>XModuleManager.XFrame</CODE>,
65*cdf0e10cSrcweir      * <CODE>XModuleManager.XController</CODE> and <CODE>XModuleManager.XModel</CODE>
66*cdf0e10cSrcweir      * are sequenzes of <CODE>PropertyValue</CODE>. The value of a PropertyValue
67*cdf0e10cSrcweir      * containes a <CODE>XFrame</CODE>, <CODE>XController</CODE> or a
68*cdf0e10cSrcweir      * <CODE>XModel</CODE>. The name of the PropertyValue contains the expected return
69*cdf0e10cSrcweir      * value of method <CODE>indetify()</CODE> if the method was called with
70*cdf0e10cSrcweir      * coresponding value.<p>
71*cdf0e10cSrcweir      * As enhancement the method <CODE>identify()</CODE> was called with incvalid
72*cdf0e10cSrcweir      * parameter. In this case the thrown exceptions was catched.
73*cdf0e10cSrcweir      */
74*cdf0e10cSrcweir     public XModuleManager oObj = null;
75*cdf0e10cSrcweir     /**
76*cdf0e10cSrcweir     * Test calls the method. <p>
77*cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns expected values, that's equal to
78*cdf0e10cSrcweir     * previously obtained object relation 'Frame'.
79*cdf0e10cSrcweir     * The following method tests are to be completed successfully before:
80*cdf0e10cSrcweir     * <ul>
81*cdf0e10cSrcweir     *  <li> <code> attachFrame() </code> : attachs frame obtained object
82*cdf0e10cSrcweir     * relation 'Frame' </li>
83*cdf0e10cSrcweir     * </ul>
84*cdf0e10cSrcweir     */
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     private PropertyValue[] xFrameSeq = null;
87*cdf0e10cSrcweir     private PropertyValue[] xControllerSeq = null;
88*cdf0e10cSrcweir     private PropertyValue[] xModelSeq = null;
89*cdf0e10cSrcweir     /** Retrieves object relations. */
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     public void before() {
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir         xFrameSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XFrame") ;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         if (xFrameSeq == null) throw new StatusException
96*cdf0e10cSrcweir             (Status.failed("Relation 'xFrameSeq' not found.")) ;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir         xControllerSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XController") ;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir         if (xControllerSeq == null) throw new StatusException
102*cdf0e10cSrcweir             (Status.failed("Relation 'xControllerSeq' not found.")) ;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         xModelSeq = (PropertyValue[]) tEnv.getObjRelation("XModuleManager.XModel") ;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         if (xModelSeq == null) throw new StatusException
108*cdf0e10cSrcweir             (Status.failed("Relation 'xModelSeq' not found.")) ;
109*cdf0e10cSrcweir     }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     /** The method <CODE>identify()</CODE> was tesed for every entry in sequeze of
112*cdf0e10cSrcweir      * object relations.
113*cdf0e10cSrcweir      */
114*cdf0e10cSrcweir     public void _identify() {
115*cdf0e10cSrcweir         boolean ok = true;
116*cdf0e10cSrcweir         log.println("testing frame sequenze...");
117*cdf0e10cSrcweir         ok &= testSequenze(xFrameSeq);
118*cdf0e10cSrcweir         log.println("testing controller sequenze...");
119*cdf0e10cSrcweir         ok &= testSequenze(xControllerSeq);
120*cdf0e10cSrcweir         log.println("testing model sequenze...");
121*cdf0e10cSrcweir         ok &= testSequenze(xModelSeq);
122*cdf0e10cSrcweir         tRes.tested("identify()", ok);
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         log.println("testing invalid objects...");
125*cdf0e10cSrcweir         try{
126*cdf0e10cSrcweir             oObj.identify(oObj);
127*cdf0e10cSrcweir         } catch (IllegalArgumentException e){
128*cdf0e10cSrcweir             log.println("expected exception.");
129*cdf0e10cSrcweir         } catch (UnknownModuleException e){
130*cdf0e10cSrcweir             log.println("expected exception.");
131*cdf0e10cSrcweir         }
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     private boolean testSequenze(PropertyValue[] sequenze){
135*cdf0e10cSrcweir         boolean ok = true;
136*cdf0e10cSrcweir         for (int i = 0 ; i < sequenze.length; i++){
137*cdf0e10cSrcweir             try{
138*cdf0e10cSrcweir                 log.println("testing '" + sequenze[i].Name + "'");
139*cdf0e10cSrcweir                 if (oObj.identify(sequenze[i].Value).equals(
140*cdf0e10cSrcweir                                                         sequenze[i].Name)){
141*cdf0e10cSrcweir                      ok &= ok;
142*cdf0e10cSrcweir                 }else{
143*cdf0e10cSrcweir                      log.println("failure: returned value: '" +
144*cdf0e10cSrcweir                                  oObj.identify(sequenze[i].Value) +
145*cdf0e10cSrcweir                                  "' ,expected value: '" + sequenze[i].Name + "'");
146*cdf0e10cSrcweir                      ok = false;
147*cdf0e10cSrcweir                 }
148*cdf0e10cSrcweir             } catch (IllegalArgumentException e){
149*cdf0e10cSrcweir                 log.println("Could not get value of sequenze '" +
150*cdf0e10cSrcweir                             sequenze[i].Name + "'");
151*cdf0e10cSrcweir                 return false;
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir             } catch (UnknownModuleException e){
154*cdf0e10cSrcweir                 log.println("Could not indetify value of sequenze '" +
155*cdf0e10cSrcweir                             sequenze[i].Name + "'");
156*cdf0e10cSrcweir                 return false;
157*cdf0e10cSrcweir             }
158*cdf0e10cSrcweir         }
159*cdf0e10cSrcweir         return ok;
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164