cid#1607171 Data race condition
[LibreOffice.git] / qadevOOo / tests / java / ifc / configuration / backend / _XMultiLayerStratum.java
blobc0b7c438c455a7e05547a528dbf01f2c5ea4fb38
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 .
18 package ifc.configuration.backend;
20 import com.sun.star.configuration.backend.XLayer;
21 import com.sun.star.configuration.backend.XMultiLayerStratum;
22 import com.sun.star.configuration.backend.XUpdatableLayer;
23 import lib.MultiMethodTest;
25 import util.XLayerHandlerImpl;
28 public class _XMultiLayerStratum extends MultiMethodTest {
29 public XMultiLayerStratum oObj;
30 protected String aLayerID;
32 public void _getLayer() {
33 boolean res = true;
35 try {
36 oObj.getLayer("", "");
37 log.println("Exception expected -- FAILED");
38 res = false;
39 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
40 log.println("unexpected Exception " + e + " -- FAILED");
41 res = false;
42 } catch (com.sun.star.lang.IllegalArgumentException e) {
43 log.println("expected Exception -- OK");
46 try {
47 XLayer aLayer = oObj.getLayer(aLayerID, "");
48 res &= (aLayer != null);
50 if (aLayer == null) {
51 log.println("\treturned Layer is NULL -- FAILED");
52 } else {
53 res &= checkLayer(aLayer);
55 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
56 log.println("unexpected Exception -- FAILED");
57 res = false;
58 } catch (com.sun.star.lang.IllegalArgumentException e) {
59 log.println("unexpected Exception -- FAILED");
60 res = false;
63 tRes.tested("getLayer()", res);
66 public void _getLayers() {
67 boolean res = true;
69 try {
70 String[] LayerIds = new String[] {
71 "1 /org/openoffice/Office/Jobs.xcu",
72 "2 /org/openoffice/Office/Linguistic.xcu" };
74 XLayer[] Layers = oObj.getLayers(LayerIds, "");
75 res = Layers.length == 2;
76 log.println("Getting two XLayers -- OK");
77 log.println("Checking first on "+LayerIds[0]);
78 res &= checkLayer(Layers[0]);
79 log.println("Checking second on "+LayerIds[1]);
80 res &= checkLayer(Layers[1]);
81 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
82 log.println("unexpected Exception -- FAILED");
83 res = false;
84 } catch (com.sun.star.lang.IllegalArgumentException e) {
85 log.println("unexpected Exception -- FAILED");
86 res = false;
89 tRes.tested("getLayers()", res);
92 public void _getMultipleLayers() {
93 boolean res = true;
95 try {
96 String[] LayerIds = new String[] {
97 "1 /org/openoffice/Office/Jobs.xcu",
98 "2 /org/openoffice/Office/Linguistic.xcu" };
99 String[] Times = new String[] { "", "" };
101 XLayer[] Layers = oObj.getMultipleLayers(LayerIds, Times);
102 res = Layers.length == 2;
103 log.println("Getting two XLayers -- OK");
104 log.println("Checking first on "+LayerIds[0]);
105 res &= checkLayer(Layers[0]);
106 log.println("Checking second on "+LayerIds[1]);
107 res &= checkLayer(Layers[1]);
108 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
109 log.println("unexpected Exception -- FAILED");
110 res = false;
111 } catch (com.sun.star.lang.IllegalArgumentException e) {
112 log.println("unexpected Exception -- FAILED");
113 res = false;
116 tRes.tested("getMultipleLayers()", res);
119 public void _getUpdatableLayer() {
120 boolean res = true;
122 try {
123 oObj.getUpdatableLayer("");
124 log.println("Exception expected -- FAILED");
125 res = false;
126 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
127 log.println("unexpected Exception " + e + " -- FAILED");
128 res = false;
129 } catch (com.sun.star.lang.IllegalArgumentException e) {
130 log.println("expected Exception -- OK");
131 } catch (com.sun.star.lang.NoSupportException e) {
132 log.println("unexpected Exception -- FAILED");
133 res = false;
136 try {
137 XUpdatableLayer aLayer = oObj.getUpdatableLayer(aLayerID);
138 res &= (aLayer != null);
140 if (aLayer == null) {
141 log.println("\treturned Layer is NULL -- FAILED");
142 } else {
143 res &= checkLayer(aLayer);
145 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
146 log.println("unexpected Exception -- FAILED");
147 res = false;
148 } catch (com.sun.star.lang.IllegalArgumentException e) {
149 log.println("unexpected Exception -- FAILED");
150 res = false;
151 } catch (com.sun.star.lang.NoSupportException e) {
152 log.println("unexpected Exception -- FAILED");
153 res = false;
156 tRes.tested("getUpdatableLayer()", res);
159 public void _getUpdateLayerId() throws com.sun.star.uno.Exception {
160 boolean res = true;
162 try {
163 oObj.getUpdateLayerId(
164 "org.openoffice.Office.TypeDetection",
165 "illegal");
166 log.println("Exception expected -- FAILED");
167 res = false;
168 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
169 log.println("expected Exception -- OK");
170 } catch (com.sun.star.lang.IllegalArgumentException e) {
171 log.println("unexpected Exception -- FAILED");
172 res = false;
173 } catch (com.sun.star.lang.NoSupportException e) {
174 log.println("unexpected Exception -- FAILED");
175 res = false;
178 try {
179 String ent = util.utils.getOfficeURL(
180 tParam.getMSF()) +
181 "/../share/registry";
182 String UpdateLayerID = oObj.getUpdateLayerId(
183 "org.openoffice.Office.Linguistic", ent);
184 res &= UpdateLayerID.endsWith("Linguistic.xcu");
186 if (!UpdateLayerID.endsWith("Linguistic.xcu")) {
187 log.println("\tExpected the id to end with Linguistic.xcu");
188 log.println("\tBut got " + UpdateLayerID);
189 log.println("\t=> FAILED");
191 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
192 log.println("unexpected Exception -- FAILED");
193 res = false;
194 } catch (com.sun.star.lang.IllegalArgumentException e) {
195 log.println("unexpected Exception "+e+" -- FAILED");
196 res = false;
197 } catch (com.sun.star.lang.NoSupportException e) {
198 log.println("unexpected Exception -- FAILED");
199 res = false;
202 tRes.tested("getUpdateLayerId()", res);
205 public void _listLayerIds() throws com.sun.star.uno.Exception {
206 boolean res = true;
208 try {
209 oObj.listLayerIds(
210 "org.openoffice.Office.TypeDetection",
211 "illegal");
212 log.println("Exception expected -- FAILED");
213 res = false;
214 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
215 log.println("expected Exception -- OK");
216 } catch (com.sun.star.lang.IllegalArgumentException e) {
217 log.println("unexpected Exception -- FAILED");
218 res = false;
221 try {
222 String ent = util.utils.getOfficeURL(
223 tParam.getMSF()) +
224 "/../share/registry";
225 String[] LayerIDs = oObj.listLayerIds("org.openoffice.Office.Jobs",
226 ent);
227 res &= LayerIDs[0].endsWith("Jobs.xcu");
228 aLayerID = LayerIDs[0];
230 if (!LayerIDs[0].endsWith("Jobs.xcu")) {
231 log.println("\tExpected the id to end with Jobs.xcu");
232 log.println("\tBut got " + LayerIDs[0]);
233 log.println("\t=> FAILED");
235 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
236 log.println("unexpected Exception -- FAILED");
237 res = false;
238 } catch (com.sun.star.lang.IllegalArgumentException e) {
239 log.println("unexpected Exception -- FAILED");
240 res = false;
243 tRes.tested("listLayerIds()", res);
246 protected boolean checkLayer(XLayer aLayer) {
247 boolean res = false;
249 log.println("Checking for Exception in case of null argument");
251 try {
252 aLayer.readData(null);
253 } catch (com.sun.star.lang.NullPointerException e) {
254 log.println("Expected Exception -- OK");
255 res = true;
256 } catch (com.sun.star.lang.WrappedTargetException e) {
257 log.println("Unexpected Exception (" + e + ") -- FAILED");
258 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
259 log.println("Unexpected Exception (" + e + ") -- FAILED");
262 log.println("checking read data with own XLayerHandler implementation");
264 try {
265 XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
266 aLayer.readData(xLayerHandler);
268 String implCalled = xLayerHandler.getCalls();
269 log.println(implCalled);
271 int sl = implCalled.indexOf("startLayer");
273 if (sl < 0) {
274 log.println("startLayer wasn't called -- FAILED");
275 res &= false;
276 } else {
277 log.println("startLayer was called -- OK");
278 res &= true;
281 int el = implCalled.indexOf("endLayer");
283 if (el < 0) {
284 log.println("endLayer wasn't called -- FAILED");
285 res &= false;
286 } else {
287 log.println("endLayer was called -- OK");
288 res &= true;
290 } catch (com.sun.star.lang.NullPointerException e) {
291 log.println("Unexpected Exception (" + e + ") -- FAILED");
292 res &= false;
293 } catch (com.sun.star.lang.WrappedTargetException e) {
294 log.println("Unexpected Exception (" + e + ") -- FAILED");
295 res &= false;
296 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
297 log.println("Unexpected Exception (" + e + ") -- FAILED");
298 res &= false;
301 return res;