2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.beans
.PropertyValue
;
23 import com
.sun
.star
.frame
.XModuleManager
;
24 import lib
.MultiMethodTest
;
26 import lib
.StatusException
;
28 import com
.sun
.star
.lang
.IllegalArgumentException
;
29 import com
.sun
.star
.frame
.UnknownModuleException
;
33 * Testing <code>com.sun.star.frame.XModuleManager</code>
36 * <li><code> identify() </code></li>
38 * This test needs the following object relations :
40 * <li> <code>'XModuleManager.XFrame'</code> (of type <code>PropertyValue[]</code>):
41 * PropertyValue[n].Value : a XFrame
42 * PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
43 * <li> <code>'XModuleManager.XController'</code> (of type <code>PropertyValue[]</code>):
44 * PropertyValue[n].Value : a XController
45 * PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
46 * <li> <code>'XModuleManager.XModel'</code> (of type <code>PropertyValue[]</code>):
47 * PropertyValue[n].Value : a XFrame
48 * PropertyValue[n].Name : the expected return value of <code>idendify()</code></li>
50 * Test is <b> NOT </b> multithread compliant. <p>
51 * @see com.sun.star.frame.XModuleManager
53 public class _XModuleManager
extends MultiMethodTest
{
54 /** Test calls the method. <p>
55 * The onject relations <CODE>XModuleManager.XFrame</CODE>,
56 * <CODE>XModuleManager.XController</CODE> and <CODE>XModuleManager.XModel</CODE>
57 * are sequenzes of <CODE>PropertyValue</CODE>. The value of a PropertyValue
58 * contains a <CODE>XFrame</CODE>, <CODE>XController</CODE> or a
59 * <CODE>XModel</CODE>. The name of the PropertyValue contains the expected return
60 * value of method <CODE>indetify()</CODE> if the method was called with
61 * coresponding value.<p>
62 * As enhancement the method <CODE>identify()</CODE> was called with incvalid
63 * parameter. In this case the thrown exceptions was catched.
65 public XModuleManager oObj
= null;
67 * Test calls the method. <p>
68 * Has <b> OK </b> status if the method returns expected values, that's equal to
69 * previously obtained object relation 'Frame'.
70 * The following method tests are to be completed successfully before:
72 * <li> <code> attachFrame() </code> : attachs frame obtained object
73 * relation 'Frame' </li>
77 private PropertyValue
[] xFrameSeq
= null;
78 private PropertyValue
[] xControllerSeq
= null;
79 private PropertyValue
[] xModelSeq
= null;
80 /** Retrieves object relations. */
83 public void before() {
85 xFrameSeq
= (PropertyValue
[]) tEnv
.getObjRelation("XModuleManager.XFrame") ;
87 if (xFrameSeq
== null) throw new StatusException
88 (Status
.failed("Relation 'xFrameSeq' not found.")) ;
91 xControllerSeq
= (PropertyValue
[]) tEnv
.getObjRelation("XModuleManager.XController") ;
93 if (xControllerSeq
== null) throw new StatusException
94 (Status
.failed("Relation 'xControllerSeq' not found.")) ;
97 xModelSeq
= (PropertyValue
[]) tEnv
.getObjRelation("XModuleManager.XModel") ;
99 if (xModelSeq
== null) throw new StatusException
100 (Status
.failed("Relation 'xModelSeq' not found.")) ;
103 /** The method <CODE>identify()</CODE> was tesed for every entry in sequeze of
106 public void _identify() {
108 log
.println("testing frame sequenze...");
109 ok
&= testSequenze(xFrameSeq
);
110 log
.println("testing controller sequenze...");
111 ok
&= testSequenze(xControllerSeq
);
112 log
.println("testing model sequenze...");
113 ok
&= testSequenze(xModelSeq
);
114 tRes
.tested("identify()", ok
);
116 log
.println("testing invalid objects...");
119 } catch (IllegalArgumentException e
){
120 log
.println("expected exception.");
121 } catch (UnknownModuleException e
){
122 log
.println("expected exception.");
126 private boolean testSequenze(PropertyValue
[] sequenze
){
128 for (int i
= 0 ; i
< sequenze
.length
; i
++){
130 log
.println("testing '" + sequenze
[i
].Name
+ "'");
131 if (!oObj
.identify(sequenze
[i
].Value
).equals(
133 log
.println("failure: returned value: '" +
134 oObj
.identify(sequenze
[i
].Value
) +
135 "' ,expected value: '" + sequenze
[i
].Name
+ "'");
138 } catch (IllegalArgumentException e
){
139 log
.println("Could not get value of sequenze '" +
140 sequenze
[i
].Name
+ "'");
143 } catch (UnknownModuleException e
){
144 log
.println("Could not indetify value of sequenze '" +
145 sequenze
[i
].Name
+ "'");