Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / configuration / backend / _XMultiLayerStratum.java
blob20d87d50577f98232e44a1e95eb7dfb592b9dd54
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XMultiLayerStratum.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc.configuration.backend;
32 import com.sun.star.configuration.backend.XLayer;
33 import com.sun.star.configuration.backend.XMultiLayerStratum;
34 import com.sun.star.configuration.backend.XUpdatableLayer;
35 import com.sun.star.lang.XMultiServiceFactory;
37 import lib.MultiMethodTest;
39 import util.XLayerHandlerImpl;
42 public class _XMultiLayerStratum extends MultiMethodTest {
43 public XMultiLayerStratum oObj;
44 protected String aLayerID;
46 public void _getLayer() {
47 boolean res = true;
49 try {
50 XLayer aLayer = oObj.getLayer("", "");
51 log.println("Exception expected -- FAILED");
52 res = false;
53 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
54 log.println("unexpected Exception " + e + " -- FAILED");
55 res = false;
56 } catch (com.sun.star.lang.IllegalArgumentException e) {
57 log.println("expected Exception -- OK");
60 try {
61 XLayer aLayer = oObj.getLayer(aLayerID, "");
62 res &= (aLayer != null);
64 if (aLayer == null) {
65 log.println("\treturned Layer is NULL -- FAILED");
68 res &= checkLayer(aLayer);
69 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
70 log.println("unexpected Exception -- FAILED");
71 res = false;
72 } catch (com.sun.star.lang.IllegalArgumentException e) {
73 log.println("unexpected Exception -- FAILED");
74 res = false;
77 tRes.tested("getLayer()", res);
80 public void _getLayers() {
81 boolean res = true;
83 try {
84 String[] LayerIds = new String[2];
85 LayerIds[0] = "1 /org/openoffice/Office/Jobs.xcu";
86 LayerIds[1] = "2 /org/openoffice/Office/Linguistic.xcu";
88 XLayer[] Layers = oObj.getLayers(LayerIds, "");
89 res = Layers.length == 2;
90 log.println("Getting two XLayers -- OK");
91 log.println("Checking first on "+LayerIds[0]);
92 res &= checkLayer(Layers[0]);
93 log.println("Checking second on "+LayerIds[1]);
94 res &= checkLayer(Layers[1]);
95 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
96 log.println("unexpected Exception -- FAILED");
97 res = false;
98 } catch (com.sun.star.lang.IllegalArgumentException e) {
99 log.println("unexpected Exception -- FAILED");
100 res = false;
103 tRes.tested("getLayers()", res);
106 public void _getMultipleLayers() {
107 boolean res = true;
109 try {
110 String[] LayerIds = new String[2];
111 LayerIds[0] = "1 /org/openoffice/Office/Jobs.xcu";
112 LayerIds[1] = "2 /org/openoffice/Office/Linguistic.xcu";
113 String[] Times = new String[2];
114 Times[0] = "";
115 Times[1] = "";
117 XLayer[] Layers = oObj.getMultipleLayers(LayerIds, Times);
118 res = Layers.length == 2;
119 log.println("Getting two XLayers -- OK");
120 log.println("Checking first on "+LayerIds[0]);
121 res &= checkLayer(Layers[0]);
122 log.println("Checking second on "+LayerIds[1]);
123 res &= checkLayer(Layers[1]);
124 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
125 log.println("unexpected Exception -- FAILED");
126 res = false;
127 } catch (com.sun.star.lang.IllegalArgumentException e) {
128 log.println("unexpected Exception -- FAILED");
129 res = false;
132 tRes.tested("getMultipleLayers()", res);
135 public void _getUpdatableLayer() {
136 boolean res = true;
138 try {
139 XUpdatableLayer aLayer = oObj.getUpdatableLayer("");
140 log.println("Exception expected -- FAILED");
141 res = false;
142 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
143 log.println("unexpected Exception " + e + " -- FAILED");
144 res = false;
145 } catch (com.sun.star.lang.IllegalArgumentException e) {
146 log.println("expected Exception -- OK");
147 } catch (com.sun.star.lang.NoSupportException e) {
148 log.println("unexpected Exception -- FAILED");
149 res = false;
152 try {
153 XUpdatableLayer aLayer = oObj.getUpdatableLayer(aLayerID);
154 res &= (aLayer != null);
156 if (aLayer == null) {
157 log.println("\treturned Layer is NULL -- FAILED");
160 res &= checkLayer(aLayer);
161 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
162 log.println("unexpected Exception -- FAILED");
163 res = false;
164 } catch (com.sun.star.lang.IllegalArgumentException e) {
165 log.println("unexpected Exception -- FAILED");
166 res = false;
167 } catch (com.sun.star.lang.NoSupportException e) {
168 log.println("unexpected Exception -- FAILED");
169 res = false;
172 tRes.tested("getUpdatableLayer()", res);
175 public void _getUpdateLayerId() {
176 boolean res = true;
178 try {
179 String UpdateLayerID = oObj.getUpdateLayerId(
180 "org.openoffice.Office.TypeDetection",
181 "illegal");
182 log.println("Exception expected -- FAILED");
183 res = false;
184 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
185 log.println("expected Exception -- OK");
186 } catch (com.sun.star.lang.IllegalArgumentException e) {
187 log.println("unexpected Exception -- FAILED");
188 res = false;
189 } catch (com.sun.star.lang.NoSupportException e) {
190 log.println("unexpected Exception -- FAILED");
191 res = false;
194 try {
195 String ent = util.utils.getOfficeURL(
196 (XMultiServiceFactory) tParam.getMSF()) +
197 "/../share/registry";
198 String UpdateLayerID = oObj.getUpdateLayerId(
199 "org.openoffice.Office.Linguistic", ent);
200 res &= UpdateLayerID.endsWith("Linguistic.xcu");
202 if (!UpdateLayerID.endsWith("Linguistic.xcu")) {
203 log.println("\tExpected the id to end with Linguistic.xcu");
204 log.println("\tBut got " + UpdateLayerID);
205 log.println("\t=> FAILED");
207 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
208 log.println("unexpected Exception -- FAILED");
209 res = false;
210 } catch (com.sun.star.lang.IllegalArgumentException e) {
211 log.println("unexpected Exception "+e+" -- FAILED");
212 res = false;
213 } catch (com.sun.star.lang.NoSupportException e) {
214 log.println("unexpected Exception -- FAILED");
215 res = false;
218 tRes.tested("getUpdateLayerId()", res);
221 public void _listLayerIds() {
222 boolean res = true;
224 try {
225 String[] LayerIDs = oObj.listLayerIds(
226 "org.openoffice.Office.TypeDetection",
227 "illegal");
228 log.println("Exception expected -- FAILED");
229 res = false;
230 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
231 log.println("expected Exception -- OK");
232 } catch (com.sun.star.lang.IllegalArgumentException e) {
233 log.println("unexpected Exception -- FAILED");
234 res = false;
237 try {
238 String ent = util.utils.getOfficeURL(
239 (XMultiServiceFactory) tParam.getMSF()) +
240 "/../share/registry";
241 String[] LayerIDs = oObj.listLayerIds("org.openoffice.Office.Jobs",
242 ent);
243 res &= LayerIDs[0].endsWith("Jobs.xcu");
244 aLayerID = LayerIDs[0];
246 if (!LayerIDs[0].endsWith("Jobs.xcu")) {
247 log.println("\tExpected the id to end with Jobs.xcu");
248 log.println("\tBut got " + LayerIDs[0]);
249 log.println("\t=> FAILED");
251 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
252 log.println("unexpected Exception -- FAILED");
253 res = false;
254 } catch (com.sun.star.lang.IllegalArgumentException e) {
255 log.println("unexpected Exception -- FAILED");
256 res = false;
259 tRes.tested("listLayerIds()", res);
262 protected boolean checkLayer(XLayer aLayer) {
263 boolean res = false;
265 log.println("Checking for Exception in case of null argument");
267 try {
268 aLayer.readData(null);
269 } catch (com.sun.star.lang.NullPointerException e) {
270 log.println("Expected Exception -- OK");
271 res = true;
272 } catch (com.sun.star.lang.WrappedTargetException e) {
273 log.println("Unexpected Exception (" + e + ") -- FAILED");
274 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
275 log.println("Unexpected Exception (" + e + ") -- FAILED");
278 log.println("checking read data with own XLayerHandler implementation");
280 try {
281 XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
282 aLayer.readData(xLayerHandler);
284 String implCalled = xLayerHandler.getCalls();
285 log.println(implCalled);
287 int sl = implCalled.indexOf("startLayer");
289 if (sl < 0) {
290 log.println("startLayer wasn't called -- FAILED");
291 res &= false;
292 } else {
293 log.println("startLayer was called -- OK");
294 res &= true;
297 int el = implCalled.indexOf("endLayer");
299 if (el < 0) {
300 log.println("endLayer wasn't called -- FAILED");
301 res &= false;
302 } else {
303 log.println("endLayer was called -- OK");
304 res &= true;
306 } catch (com.sun.star.lang.NullPointerException e) {
307 log.println("Unexpected Exception (" + e + ") -- FAILED");
308 res &= false;
309 } catch (com.sun.star.lang.WrappedTargetException e) {
310 log.println("Unexpected Exception (" + e + ") -- FAILED");
311 res &= false;
312 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
313 log.println("Unexpected Exception (" + e + ") -- FAILED");
314 res &= false;
317 return res;