1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSchema.java,v $
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
{
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()");
57 log
.println("Checking for Exception in case of null argument");
60 oObj
.readComponent(null);
61 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
62 log
.println("Expected Exception -- OK");
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");
71 "checking readComponent with own XSchemeHandler implementation");
74 xSchemaHandlerImpl
.cleanCalls();
75 oObj
.readComponent(xSchemaHandlerImpl
);
77 String implCalled
= xSchemaHandlerImpl
.getCalls();
79 System
.out
.println(implCalled
);
81 int sc
= implCalled
.indexOf("startComponent");
84 log
.println("startComponent wasn't called -- FAILED");
87 log
.println("startComponent was called -- OK");
91 int ec
= implCalled
.indexOf("endComponent");
94 log
.println("endComponent wasn't called -- FAILED");
97 log
.println("endComponent was called -- OK");
100 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
101 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
103 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
104 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
106 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
107 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
111 tRes
.tested("readComponent()", res
);
115 public void _readSchema() {
116 requiredMethod("readComponent()");
119 log
.println("Checking for Exception in case of null argument");
122 xSchemaHandlerImpl
.cleanCalls();
123 oObj
.readSchema(null);
124 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
125 log
.println("Expected Exception -- OK");
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");
134 "checking read data with own XSchemeHandler implementation");
137 xSchemaHandlerImpl
.cleanCalls();
138 oObj
.readSchema(xSchemaHandlerImpl
);
140 String implCalled
= xSchemaHandlerImpl
.getCalls();
142 int sc
= implCalled
.indexOf("startSchema");
145 log
.println("startSchema wasn't called -- FAILED");
148 log
.println("startSchema was called -- OK");
152 int ec
= implCalled
.indexOf("endSchema");
155 log
.println("endSchema wasn't called -- FAILED");
158 log
.println("endSchema was called -- OK");
161 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
162 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
164 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
165 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
167 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
168 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
172 // check for the wrapped target exception
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");
181 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
182 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
185 tRes
.tested("readSchema()", res
);
189 public void _readTemplates() {
192 log
.println("Checking for Exception in case of null argument");
195 oObj
.readTemplates(null);
196 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
197 log
.println("Expected Exception -- OK");
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");
206 "checking readComponent with own XSchemeHandler implementation");
209 xSchemaHandlerImpl
.cleanCalls();
210 oObj
.readComponent(xSchemaHandlerImpl
);
212 String implCalled
= xSchemaHandlerImpl
.getCalls();
214 int sc
= implCalled
.indexOf("startGroup");
217 log
.println("startGroup wasn't called -- FAILED");
220 log
.println("startGroup was called -- OK");
224 int ec
= implCalled
.indexOf("endNode");
227 log
.println("endNode wasn't called -- FAILED");
230 log
.println("endNode was called -- OK");
233 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
234 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
236 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
237 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
239 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
240 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
244 tRes
.tested("readTemplates()", res
);
249 * reopen the parsed file again, to avoid the wrapped target exception.
251 private void reopenFile() {
252 XSimpleFileAccess simpleAccess
= null;
253 XInputStream xStream
= null;
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
);