Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / configuration / backend / _XSchema.java
blob41e8d238341f82126c543ff7ac0fac97eb165632
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: _XSchema.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.configuration.backend;
33 import com.sun.star.configuration.backend.XSchema;
34 import com.sun.star.io.XActiveDataSink;
35 import com.sun.star.io.XInputStream;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.ucb.XSimpleFileAccess;
38 import com.sun.star.uno.UnoRuntime;
40 import lib.MultiMethodTest;
42 import util.XSchemaHandlerImpl;
44 public class _XSchema extends MultiMethodTest {
45 public XSchema oObj;
46 XSchemaHandlerImpl xSchemaHandlerImpl = new XSchemaHandlerImpl();
47 String filename = null;
49 protected void before() {
50 filename = (String)tEnv.getObjRelation("ParsedFileName");
53 public void _readComponent() {
54 requiredMethod("readTemplates()");
55 boolean res = false;
57 log.println("Checking for Exception in case of null argument");
59 try {
60 oObj.readComponent(null);
61 } catch (com.sun.star.lang.NullPointerException e) {
62 log.println("Expected Exception -- OK");
63 res = true;
64 } catch (com.sun.star.lang.WrappedTargetException e) {
65 log.println("Unexpected Exception (" + e + ") -- FAILED");
66 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
67 log.println("Unexpected Exception (" + e + ") -- FAILED");
70 log.println(
71 "checking readComponent with own XSchemeHandler implementation");
73 try {
74 xSchemaHandlerImpl.cleanCalls();
75 oObj.readComponent(xSchemaHandlerImpl);
77 String implCalled = xSchemaHandlerImpl.getCalls();
79 System.out.println(implCalled);
81 int sc = implCalled.indexOf("startComponent");
83 if (sc < 0) {
84 log.println("startComponent wasn't called -- FAILED");
85 res &= false;
86 } else {
87 log.println("startComponent was called -- OK");
88 res &= true;
91 int ec = implCalled.indexOf("endComponent");
93 if (ec < 0) {
94 log.println("endComponent wasn't called -- FAILED");
95 res &= false;
96 } else {
97 log.println("endComponent was called -- OK");
98 res &= true;
100 } catch (com.sun.star.lang.NullPointerException e) {
101 log.println("Unexpected Exception (" + e + ") -- FAILED");
102 res &= false;
103 } catch (com.sun.star.lang.WrappedTargetException e) {
104 log.println("Unexpected Exception (" + e + ") -- FAILED");
105 res &= false;
106 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
107 log.println("Unexpected Exception (" + e + ") -- FAILED");
108 res &= false;
111 tRes.tested("readComponent()", res);
112 reopenFile();
115 public void _readSchema() {
116 requiredMethod("readComponent()");
117 boolean res = false;
119 log.println("Checking for Exception in case of null argument");
121 try {
122 xSchemaHandlerImpl.cleanCalls();
123 oObj.readSchema(null);
124 } catch (com.sun.star.lang.NullPointerException e) {
125 log.println("Expected Exception -- OK");
126 res = true;
127 } catch (com.sun.star.lang.WrappedTargetException e) {
128 log.println("Unexpected Exception (" + e + ") -- FAILED");
129 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
130 log.println("Unexpected Exception (" + e + ") -- FAILED");
133 log.println(
134 "checking read data with own XSchemeHandler implementation");
136 try {
137 xSchemaHandlerImpl.cleanCalls();
138 oObj.readSchema(xSchemaHandlerImpl);
140 String implCalled = xSchemaHandlerImpl.getCalls();
142 int sc = implCalled.indexOf("startSchema");
144 if (sc < 0) {
145 log.println("startSchema wasn't called -- FAILED");
146 res &= false;
147 } else {
148 log.println("startSchema was called -- OK");
149 res &= true;
152 int ec = implCalled.indexOf("endSchema");
154 if (ec < 0) {
155 log.println("endSchema wasn't called -- FAILED");
156 res &= false;
157 } else {
158 log.println("endSchema was called -- OK");
159 res &= true;
161 } catch (com.sun.star.lang.NullPointerException e) {
162 log.println("Unexpected Exception (" + e + ") -- FAILED");
163 res &= false;
164 } catch (com.sun.star.lang.WrappedTargetException e) {
165 log.println("Unexpected Exception (" + e + ") -- FAILED");
166 res &= false;
167 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
168 log.println("Unexpected Exception (" + e + ") -- FAILED");
169 res &= false;
172 // check for the wrapped target exception
173 try {
174 xSchemaHandlerImpl.cleanCalls();
175 oObj.readSchema(xSchemaHandlerImpl);
176 } catch (com.sun.star.lang.NullPointerException e) {
177 log.println("Unexpected Exception (" + e + ") -- FAILED");
178 } catch (com.sun.star.lang.WrappedTargetException e) {
179 log.println("Expected Exception -- OK");
180 res = true;
181 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
182 log.println("Unexpected Exception (" + e + ") -- FAILED");
185 tRes.tested("readSchema()", res);
186 reopenFile();
189 public void _readTemplates() {
190 boolean res = false;
192 log.println("Checking for Exception in case of null argument");
194 try {
195 oObj.readTemplates(null);
196 } catch (com.sun.star.lang.NullPointerException e) {
197 log.println("Expected Exception -- OK");
198 res = true;
199 } catch (com.sun.star.lang.WrappedTargetException e) {
200 log.println("Unexpected Exception (" + e + ") -- FAILED");
201 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
202 log.println("Unexpected Exception (" + e + ") -- FAILED");
205 log.println(
206 "checking readComponent with own XSchemeHandler implementation");
208 try {
209 xSchemaHandlerImpl.cleanCalls();
210 oObj.readComponent(xSchemaHandlerImpl);
212 String implCalled = xSchemaHandlerImpl.getCalls();
214 int sc = implCalled.indexOf("startGroup");
216 if (sc < 0) {
217 log.println("startGroup wasn't called -- FAILED");
218 res &= false;
219 } else {
220 log.println("startGroup was called -- OK");
221 res &= true;
224 int ec = implCalled.indexOf("endNode");
226 if (ec < 0) {
227 log.println("endNode wasn't called -- FAILED");
228 res &= false;
229 } else {
230 log.println("endNode was called -- OK");
231 res &= true;
233 } catch (com.sun.star.lang.NullPointerException e) {
234 log.println("Unexpected Exception (" + e + ") -- FAILED");
235 res &= false;
236 } catch (com.sun.star.lang.WrappedTargetException e) {
237 log.println("Unexpected Exception (" + e + ") -- FAILED");
238 res &= false;
239 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
240 log.println("Unexpected Exception (" + e + ") -- FAILED");
241 res &= false;
244 tRes.tested("readTemplates()", res);
245 reopenFile();
249 * reopen the parsed file again, to avoid the wrapped target exception.
251 private void reopenFile() {
252 XSimpleFileAccess simpleAccess = null;
253 XInputStream xStream = null;
254 try {
255 Object fileacc = ((XMultiServiceFactory)tParam.getMSF()).createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
256 simpleAccess = (XSimpleFileAccess)
257 UnoRuntime.queryInterface(XSimpleFileAccess.class,fileacc);
258 log.println("Going to parse: "+filename);
259 xStream = simpleAccess.openFileRead(filename);
260 } catch (com.sun.star.uno.Exception e) {
263 XActiveDataSink xSink = (XActiveDataSink) UnoRuntime.queryInterface(XActiveDataSink.class, oObj);
264 xSink.setInputStream(xStream);