Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XModuleManager.java
blobd870589c3c564b73fa95a9aab3c1d196199adafe
1 /*
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 .
19 package ifc.frame;
21 import com.sun.star.beans.PropertyValue;
23 import com.sun.star.frame.XModuleManager;
24 import lib.MultiMethodTest;
25 import lib.Status;
26 import lib.StatusException;
28 import com.sun.star.lang.IllegalArgumentException;
29 import com.sun.star.frame.UnknownModuleException;
32 /**
33 * Testing <code>com.sun.star.frame.XModuleManager</code>
34 * interface methods:
35 * <ul>
36 * <li><code> identify() </code></li>
37 * </ul><p>
38 * This test needs the following object relations :
39 * <ul>
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>identify()</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>identify()</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>identify()</code></li>
49 * </ul> <p>
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 object relations <CODE>XModuleManager.XFrame</CODE>,
56 * <CODE>XModuleManager.XController</CODE> and <CODE>XModuleManager.XModel</CODE>
57 * are sequences 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 * corresponding value.<p>
62 * As enhancement the method <CODE>identify()</CODE> was called with invalid
63 * parameter. In this case the thrown exceptions were caught.
65 public XModuleManager oObj = null;
66 /**
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:
71 * <ul>
72 * <li> <code> attachFrame() </code> : attaches frame obtained object
73 * relation 'Frame' </li>
74 * </ul>
77 private PropertyValue[] xFrameSeq = null;
78 private PropertyValue[] xControllerSeq = null;
79 private PropertyValue[] xModelSeq = null;
80 /** Retrieves object relations. */
82 @Override
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 used for every entry in sequence of
104 * object relations.
106 public void _identify() {
107 boolean ok = true;
108 log.println("testing frame sequence...");
109 ok &= testSequence(xFrameSeq);
110 log.println("testing controller sequence...");
111 ok &= testSequence(xControllerSeq);
112 log.println("testing model sequence...");
113 ok &= testSequence(xModelSeq);
114 tRes.tested("identify()", ok);
116 log.println("testing invalid objects...");
117 try{
118 oObj.identify(oObj);
119 } catch (IllegalArgumentException e){
120 log.println("expected exception.");
121 } catch (UnknownModuleException e){
122 log.println("expected exception.");
126 private boolean testSequence(PropertyValue[] sequence){
127 boolean ok = true;
128 for (int i = 0 ; i < sequence.length; i++){
129 try{
130 log.println("testing '" + sequence[i].Name + "'");
131 if (!oObj.identify(sequence[i].Value).equals(
132 sequence[i].Name)) {
133 log.println("failure: returned value: '" +
134 oObj.identify(sequence[i].Value) +
135 "' ,expected value: '" + sequence[i].Name + "'");
136 ok = false;
138 } catch (IllegalArgumentException e){
139 log.println("Could not get value of sequence '" +
140 sequence[i].Name + "'");
141 return false;
143 } catch (UnknownModuleException e){
144 log.println("Could not indetify value of sequence '" +
145 sequence[i].Name + "'");
146 return false;
149 return ok;