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