cid#1607171 Data race condition
[LibreOffice.git] / qadevOOo / tests / java / ifc / configuration / backend / _XSchema.java
blob597d245efbd1519a4f3a65115843197a7a6e6c32
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.configuration.backend;
21 import com.sun.star.configuration.backend.XSchema;
22 import com.sun.star.io.XActiveDataSink;
23 import com.sun.star.io.XInputStream;
24 import com.sun.star.ucb.XSimpleFileAccess;
25 import com.sun.star.uno.UnoRuntime;
27 import lib.MultiMethodTest;
29 import util.XSchemaHandlerImpl;
31 public class _XSchema extends MultiMethodTest {
32 public XSchema oObj;
33 XSchemaHandlerImpl xSchemaHandlerImpl = new XSchemaHandlerImpl();
34 String filename = null;
36 @Override
37 protected void before() {
38 filename = (String)tEnv.getObjRelation("ParsedFileName");
41 public void _readComponent() {
42 requiredMethod("readTemplates()");
43 boolean res = false;
45 log.println("Checking for Exception in case of null argument");
47 try {
48 oObj.readComponent(null);
49 } catch (com.sun.star.lang.NullPointerException e) {
50 log.println("Expected Exception -- OK");
51 res = true;
52 } catch (com.sun.star.lang.WrappedTargetException e) {
53 log.println("Unexpected Exception (" + e + ") -- FAILED");
54 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
55 log.println("Unexpected Exception (" + e + ") -- FAILED");
58 log.println(
59 "checking readComponent with own XSchemeHandler implementation");
61 try {
62 xSchemaHandlerImpl.cleanCalls();
63 oObj.readComponent(xSchemaHandlerImpl);
65 String implCalled = xSchemaHandlerImpl.getCalls();
67 System.out.println(implCalled);
69 int sc = implCalled.indexOf("startComponent");
71 if (sc < 0) {
72 log.println("startComponent wasn't called -- FAILED");
73 res &= false;
74 } else {
75 log.println("startComponent was called -- OK");
76 res &= true;
79 int ec = implCalled.indexOf("endComponent");
81 if (ec < 0) {
82 log.println("endComponent wasn't called -- FAILED");
83 res &= false;
84 } else {
85 log.println("endComponent was called -- OK");
86 res &= true;
88 } catch (com.sun.star.lang.NullPointerException e) {
89 log.println("Unexpected Exception (" + e + ") -- FAILED");
90 res &= false;
91 } catch (com.sun.star.lang.WrappedTargetException e) {
92 log.println("Unexpected Exception (" + e + ") -- FAILED");
93 res &= false;
94 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
95 log.println("Unexpected Exception (" + e + ") -- FAILED");
96 res &= false;
99 tRes.tested("readComponent()", res);
100 reopenFile();
103 public void _readSchema() {
104 requiredMethod("readComponent()");
105 boolean res = false;
107 log.println("Checking for Exception in case of null argument");
109 try {
110 xSchemaHandlerImpl.cleanCalls();
111 oObj.readSchema(null);
112 } catch (com.sun.star.lang.NullPointerException e) {
113 log.println("Expected Exception -- OK");
114 res = true;
115 } catch (com.sun.star.lang.WrappedTargetException e) {
116 log.println("Unexpected Exception (" + e + ") -- FAILED");
117 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
118 log.println("Unexpected Exception (" + e + ") -- FAILED");
121 log.println(
122 "checking read data with own XSchemeHandler implementation");
124 try {
125 xSchemaHandlerImpl.cleanCalls();
126 oObj.readSchema(xSchemaHandlerImpl);
128 String implCalled = xSchemaHandlerImpl.getCalls();
130 int sc = implCalled.indexOf("startSchema");
132 if (sc < 0) {
133 log.println("startSchema wasn't called -- FAILED");
134 res &= false;
135 } else {
136 log.println("startSchema was called -- OK");
137 res &= true;
140 int ec = implCalled.indexOf("endSchema");
142 if (ec < 0) {
143 log.println("endSchema wasn't called -- FAILED");
144 res &= false;
145 } else {
146 log.println("endSchema was called -- OK");
147 res &= true;
149 } catch (com.sun.star.lang.NullPointerException e) {
150 log.println("Unexpected Exception (" + e + ") -- FAILED");
151 res &= false;
152 } catch (com.sun.star.lang.WrappedTargetException e) {
153 log.println("Unexpected Exception (" + e + ") -- FAILED");
154 res &= false;
155 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
156 log.println("Unexpected Exception (" + e + ") -- FAILED");
157 res &= false;
160 // check for the wrapped target exception
161 try {
162 xSchemaHandlerImpl.cleanCalls();
163 oObj.readSchema(xSchemaHandlerImpl);
164 } catch (com.sun.star.lang.NullPointerException e) {
165 log.println("Unexpected Exception (" + e + ") -- FAILED");
166 } catch (com.sun.star.lang.WrappedTargetException e) {
167 log.println("Expected Exception -- OK");
168 res = true;
169 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
170 log.println("Unexpected Exception (" + e + ") -- FAILED");
173 tRes.tested("readSchema()", res);
174 reopenFile();
177 public void _readTemplates() {
178 boolean res = false;
180 log.println("Checking for Exception in case of null argument");
182 try {
183 oObj.readTemplates(null);
184 } catch (com.sun.star.lang.NullPointerException e) {
185 log.println("Expected Exception -- OK");
186 res = true;
187 } catch (com.sun.star.lang.WrappedTargetException e) {
188 log.println("Unexpected Exception (" + e + ") -- FAILED");
189 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
190 log.println("Unexpected Exception (" + e + ") -- FAILED");
193 log.println(
194 "checking readComponent with own XSchemeHandler implementation");
196 try {
197 xSchemaHandlerImpl.cleanCalls();
198 oObj.readComponent(xSchemaHandlerImpl);
200 String implCalled = xSchemaHandlerImpl.getCalls();
202 int sc = implCalled.indexOf("startGroup");
204 if (sc < 0) {
205 log.println("startGroup wasn't called -- FAILED");
206 res &= false;
207 } else {
208 log.println("startGroup was called -- OK");
209 res &= true;
212 int ec = implCalled.indexOf("endNode");
214 if (ec < 0) {
215 log.println("endNode wasn't called -- FAILED");
216 res &= false;
217 } else {
218 log.println("endNode was called -- OK");
219 res &= true;
221 } catch (com.sun.star.lang.NullPointerException e) {
222 log.println("Unexpected Exception (" + e + ") -- FAILED");
223 res &= false;
224 } catch (com.sun.star.lang.WrappedTargetException e) {
225 log.println("Unexpected Exception (" + e + ") -- FAILED");
226 res &= false;
227 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
228 log.println("Unexpected Exception (" + e + ") -- FAILED");
229 res &= false;
232 tRes.tested("readTemplates()", res);
233 reopenFile();
237 * reopen the parsed file again, to avoid the wrapped target exception.
239 private void reopenFile() {
240 XSimpleFileAccess simpleAccess = null;
241 XInputStream xStream = null;
242 try {
243 Object fileacc = tParam.getMSF().createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
244 simpleAccess = UnoRuntime.queryInterface(XSimpleFileAccess.class,fileacc);
245 log.println("Going to parse: "+filename);
246 xStream = simpleAccess.openFileRead(filename);
247 } catch (com.sun.star.uno.Exception e) {
250 XActiveDataSink xSink = UnoRuntime.queryInterface(XActiveDataSink.class, oObj);
251 xSink.setInputStream(xStream);