cid#1607171 Data race condition
[LibreOffice.git] / qadevOOo / tests / java / ifc / configuration / backend / _XBackend.java
blobeb8a09cc65a3282d2abb557d945b23e935f2811e
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.XBackend;
21 import com.sun.star.configuration.backend.XLayer;
22 import com.sun.star.configuration.backend.XUpdateHandler;
23 import com.sun.star.lang.XMultiServiceFactory;
24 import com.sun.star.uno.UnoRuntime;
25 import com.sun.star.util.XStringSubstitution;
27 import lib.MultiMethodTest;
29 import util.XLayerHandlerImpl;
32 public class _XBackend extends MultiMethodTest {
33 public XBackend oObj;
35 public void _getOwnUpdateHandler() {
36 boolean res = true;
38 String noUpdate = (String) tEnv.getObjRelation("noUpdate");
40 if (noUpdate != null) {
41 log.println(noUpdate);
42 tRes.tested("getOwnUpdateHandler()", res);
44 return;
47 try {
48 XUpdateHandler aHandler = oObj.getOwnUpdateHandler(
49 "org.openoffice.Office.Linguistic");
50 res &= (aHandler != null);
52 if (aHandler == null) {
53 log.println("\treturned Layer is NULL -- FAILED");
55 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
56 log.println("unexpected Exception " + e + " -- FAILED");
57 res = false;
58 } catch (com.sun.star.lang.IllegalArgumentException e) {
59 log.println("unexpected Exception " + e + " -- FAILED");
60 res = false;
61 } catch (com.sun.star.lang.NoSupportException e) {
62 log.println("unexpected Exception " + e + " -- FAILED");
63 res = false;
66 tRes.tested("getOwnUpdateHandler()", res);
69 public void _getUpdateHandler() {
70 boolean res = true;
72 String noUpdate = (String) tEnv.getObjRelation("noUpdate");
74 if (noUpdate != null) {
75 log.println(noUpdate);
76 tRes.tested("getUpdateHandler()", res);
78 return;
81 try {
82 oObj.getUpdateHandler(
83 "org.openoffice.Office.TypeDetection",
84 "illegal");
85 log.println("Exception expected -- FAILED");
86 res = false;
87 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
88 log.println("expected Exception -- OK");
89 } catch (com.sun.star.lang.IllegalArgumentException e) {
90 log.println("unexpected Exception -- FAILED");
91 res = false;
92 } catch (com.sun.star.lang.NoSupportException e) {
93 log.println("unexpected Exception " + e + " -- FAILED");
94 res = false;
97 try {
98 XStringSubstitution sts = createStringSubstitution(
99 tParam.getMSF());
100 String ent = sts.getSubstituteVariableValue("$(inst)") +
101 "/share/registry";
102 XUpdateHandler aHandler = oObj.getUpdateHandler(
103 "org.openoffice.Office.Jobs",
104 ent);
106 if (aHandler == null) {
107 log.println("\treturned Layer is NULL -- FAILED");
109 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
110 log.println("unexpected Exception -- FAILED");
111 res = false;
112 } catch (com.sun.star.lang.IllegalArgumentException e) {
113 log.println("unexpected Exception -- FAILED");
114 res = false;
115 } catch (com.sun.star.lang.NoSupportException e) {
116 log.println("unexpected Exception " + e + " -- FAILED");
117 res = false;
118 } catch (com.sun.star.container.NoSuchElementException e) {
119 log.println("unexpected Exception " + e + " -- FAILED");
120 res = false;
121 } catch (com.sun.star.uno.Exception e) {
122 log.println("unexpected Exception " + e + " -- FAILED");
123 res = false;
126 tRes.tested("getUpdateHandler()", res);
129 public void _listLayers() {
130 boolean res = true;
132 try {
133 XStringSubstitution sts = createStringSubstitution(tParam.getMSF());
134 String ent = sts.getSubstituteVariableValue("$(inst)") +
135 "/share/registry";
136 XLayer[] Layers = oObj.listLayers(
137 "org.openoffice.Office.Linguistic", ent);
139 for (int i = 0; i < Layers.length; i++) {
140 log.println("Checking Layer " + i);
141 res &= checkLayer(Layers[i]);
143 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
144 log.println("unexpected Exception " + e + " -- FAILED");
145 res = false;
146 } catch (com.sun.star.lang.IllegalArgumentException e) {
147 log.println("unexpected Exception " + e + " -- FAILED");
148 res = false;
149 } catch (com.sun.star.container.NoSuchElementException e) {
150 log.println("unexpected Exception " + e + " -- FAILED");
151 res = false;
152 } catch (com.sun.star.uno.Exception e) {
153 log.println("unexpected Exception " + e + " -- FAILED");
154 res = false;
157 tRes.tested("listLayers()", res);
160 public void _listOwnLayers() {
161 boolean res = true;
163 try {
164 XLayer[] Layers = oObj.listOwnLayers(
165 "org.openoffice.Office.Common");
167 for (int i = 0; i < Layers.length; i++) {
168 log.println("Checking Layer " + i);
169 res &= checkLayer(Layers[i]);
171 if (Layers.length==0) {
172 System.out.println("No Layers found -- FAILED");
173 res &= false;
175 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
176 log.println("unexpected Exception " + e + " -- FAILED");
177 res = false;
178 } catch (com.sun.star.lang.IllegalArgumentException e) {
179 log.println("unexpected Exception " + e + " -- FAILED");
180 res = false;
183 tRes.tested("listOwnLayers()", res);
186 protected boolean checkLayer(XLayer aLayer) {
187 boolean res = false;
189 log.println("Checking for Exception in case of null argument");
191 try {
192 aLayer.readData(null);
193 } catch (com.sun.star.lang.NullPointerException e) {
194 log.println("Expected Exception -- OK");
195 res = true;
196 } catch (com.sun.star.lang.WrappedTargetException e) {
197 log.println("Unexpected Exception (" + e + ") -- FAILED");
198 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
199 log.println("Unexpected Exception (" + e + ") -- FAILED");
202 log.println("checking read data with own XLayerHandler implementation");
204 try {
205 XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
206 aLayer.readData(xLayerHandler);
208 String implCalled = xLayerHandler.getCalls();
209 log.println(implCalled);
211 int sl = implCalled.indexOf("startLayer");
213 if (sl < 0) {
214 log.println("startLayer wasn't called -- FAILED");
215 res &= false;
216 } else {
217 log.println("startLayer was called -- OK");
218 res &= true;
221 int el = implCalled.indexOf("endLayer");
223 if (el < 0) {
224 log.println("endLayer wasn't called -- FAILED");
225 res &= false;
226 } else {
227 log.println("endLayer was called -- OK");
228 res &= true;
230 } catch (com.sun.star.lang.NullPointerException e) {
231 log.println("Unexpected Exception (" + e + ") -- FAILED");
232 res &= false;
233 } catch (com.sun.star.lang.WrappedTargetException e) {
234 log.println("Unexpected Exception (" + e + ") -- FAILED");
235 res &= false;
236 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
237 log.println("Unexpected Exception (" + e + ") -- FAILED");
238 res &= false;
241 return res;
244 public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) throws com.sun.star.uno.Exception
246 Object xPathSubst = xMSF.createInstance(
247 "com.sun.star.util.PathSubstitution");
248 return UnoRuntime.queryInterface(XStringSubstitution.class, xPathSubst);