Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XController.java
blob48ecad772f073e1787fb29ded630ee9e71cefe3a
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 lib.MultiMethodTest;
23 import com.sun.star.frame.XController;
24 import com.sun.star.frame.XFrame;
25 import com.sun.star.frame.XModel;
26 import com.sun.star.util.XModifiable;
29 /**
30 * Testing <code>com.sun.star.frame.XController</code>
31 * interface methods:
32 * <ul>
33 * <li><code> getFrame() </code></li>
34 * <li><code> attachFrame() </code></li>
35 * <li><code> getModel() </code></li>
36 * <li><code> attachModel() </code></li>
37 * <li><code> getViewData() </code></li>
38 * <li><code> restoreViewData() </code></li>
39 * <li><code> suspend() </code></li>
40 * </ul><p>
41 * This test needs the following object relations :
42 * <ul>
43 * <li> <code>'Frame'</code> (of type <code>XFrame</code>):
44 * any other frame, used for tests</li>
45 * <li> <code>'FirstModel'</code> (of type <code>XModel</code>):
46 * model of a controller tested</li>
47 * <li> <code>'SecondModel'</code> (of type <code>XModel</code>):
48 * other model, used for tests </li>
49 * <li> <code>'HasViewData'</code> (of type <code>Boolean</code>):
50 * (optional relation) if it exists, so controller has no view data</li>
51 * <li> <code>'SecondController'</code> (of type <code>XController</code>):
52 * other controller, used for tests </li>
53 * </ul> <p>
54 * Test is <b> NOT </b> multithread compliant. <p>
55 * @see com.sun.star.frame.XController
57 public class _XController extends MultiMethodTest {
58 public XController oObj = null;
59 public XModel firstModel = null;
60 public XModel secondModel = null;
61 public XFrame frame = null;
62 public Object ViewData = null;
64 /**
65 * Test calls the method. <p>
66 * Has <b> OK </b> status if the method returns object, that's equal to
67 * previously obtained object relation 'Frame'.
68 * The following method tests are to be completed successfully before:
69 * <ul>
70 * <li> <code> attachFrame() </code> : attaches frame obtained object
71 * relation 'Frame' </li>
72 * </ul>
74 public void _getFrame() {
75 requiredMethod("attachFrame()");
76 XFrame getting = oObj.getFrame();
77 boolean eq = getting.equals(frame);
78 if ( !eq ) {
79 log.println("Getting: " + getting.toString());
80 log.println("Expected: " + frame.toString());
82 tRes.tested("getFrame()", eq);
85 /**
86 * After obtaining a corresponding object relation test calls the method.
87 * Has <b> OK </b> status if no exceptions were thrown. <p>
89 public void _attachFrame() {
90 frame = (XFrame) tEnv.getObjRelation("Frame");
91 oObj.attachFrame(frame);
92 tRes.tested("attachFrame()", true);
95 /**
96 * At first object relation 'FirstModel' is gotten. Then test calls the
97 * method. <p>
98 * Has <b> OK </b> status if string representation of an object, returned by
99 * the method is equal to string representation of corresponding object
100 * relation.
102 public void _getModel() {
103 firstModel = (XModel) tEnv.getObjRelation("FirstModel");
104 XModel getting = oObj.getModel();
105 String out1 = "";
106 String out2 = "";
107 if ( (firstModel == null) ) out1="none";
108 else out1 = firstModel.toString();
109 if ( (getting == null) ) out2="none"; else out2 = getting.toString();
110 boolean eq = out1.equals(out2);
111 if ( !eq ) {
112 log.println("Getting: " + out2);
113 log.println("Expected: " + out1);
115 tRes.tested("getModel()", eq);
119 * At first, we obtain an object relation 'SecondModel'. Then test calls
120 * the method and check result. <p>
121 * Has <b> OK </b> status if method returns true and attached model is
122 * equal to a model 'SecondModel' obtained before.
123 * <p>
124 * The following method tests are to be completed successfully before :
125 * <ul>
126 * <li> <code> getModel() </code> : returns model (XModel) of the
127 * XController object</li>
128 * </ul>
130 public void _attachModel() {
131 boolean result = false;
133 requiredMethod("getModel()");
134 secondModel = (XModel) tEnv.getObjRelation("SecondModel");
135 XModel gotBefore = oObj.getModel();
136 boolean attached = oObj.attachModel(secondModel);
137 XModel gotAfter = oObj.getModel();
138 if ( attached ) {
139 if ( ! gotBefore.equals(gotAfter) ) {
140 if ( gotAfter.equals(secondModel) ) {
141 result = true;
142 } else {
143 log.println("Attached and gotten models are not equal");
144 log.println("Getting: " + gotAfter.toString());
145 log.println("Expected: " + secondModel.toString());
147 } else {
148 log.println("method did not change model");
150 } else {
151 result=true;
152 log.println("attachModel() returns false");
153 log.println("as expected, see #82938");
155 tRes.tested("attachModel()", result);
156 boolean bResult = oObj.attachModel(firstModel);
157 log.println("attachModel() --> " + bResult);
161 * At first gotten object relation 'HasViewData' is checked. Then if
162 * 'HasViewData' is null, test calls the method. <p>
163 * Has <b> OK </b> status if obtained object relation is not null, or if
164 * the method does not return null.
166 public void _getViewData() {
167 if (tEnv.getObjRelation("HasViewData") != null) {
168 log.println("This Object has no View Data");
169 tRes.tested("getViewData()", true);
170 return;
172 ViewData = oObj.getViewData();
173 tRes.tested( "getViewData()", ViewData != null );
177 * If obtained object relation 'HasViewData' is null, test calls the method.
178 * <p>Has <b> OK </b> status if obtained object relation is not null, or
179 * if no exceptions were thrown while method call.<p>
180 * The following method tests are to be completed successfully before :
181 * <ul>
182 * <li> <code> getViewData() </code> : gets view data of an object. </li>
183 * </ul>
185 public void _restoreViewData() {
186 requiredMethod("getViewData()");
187 if (tEnv.getObjRelation("HasViewData") != null) {
188 log.println("This Object has no View Data");
189 tRes.tested("restoreViewData()", true);
190 return;
192 oObj.restoreViewData(ViewData);
193 tRes.tested( "restoreViewData()", true );
197 * Has <b> OK </b> status if the method returns true.<p>
198 * The following method tests are to be completed successfully before :
199 * <ul>
200 * <li> <code> restoreViewData() </code> : restores view status of an
201 * object </li>
202 * </ul>
204 public void _suspend() {
205 requiredMethod("restoreViewData()");
206 XModifiable modify = (XModifiable) tEnv.getObjRelation("Modifiable");
207 if (modify != null) {
208 try {
209 modify.setModified(false);
210 } catch (com.sun.star.beans.PropertyVetoException pve) {
211 log.println("PropertyVetoException, couldn't change Modify flag");
214 tRes.tested( "suspend()", oObj.suspend(true) );