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
{
33 XSchemaHandlerImpl xSchemaHandlerImpl
= new XSchemaHandlerImpl();
34 String filename
= null;
37 protected void before() {
38 filename
= (String
)tEnv
.getObjRelation("ParsedFileName");
41 public void _readComponent() {
42 requiredMethod("readTemplates()");
45 log
.println("Checking for Exception in case of null argument");
48 oObj
.readComponent(null);
49 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
50 log
.println("Expected Exception -- OK");
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");
59 "checking readComponent with own XSchemeHandler implementation");
62 xSchemaHandlerImpl
.cleanCalls();
63 oObj
.readComponent(xSchemaHandlerImpl
);
65 String implCalled
= xSchemaHandlerImpl
.getCalls();
67 System
.out
.println(implCalled
);
69 int sc
= implCalled
.indexOf("startComponent");
72 log
.println("startComponent wasn't called -- FAILED");
75 log
.println("startComponent was called -- OK");
79 int ec
= implCalled
.indexOf("endComponent");
82 log
.println("endComponent wasn't called -- FAILED");
85 log
.println("endComponent was called -- OK");
88 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
89 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
91 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
92 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
94 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
95 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
99 tRes
.tested("readComponent()", res
);
103 public void _readSchema() {
104 requiredMethod("readComponent()");
107 log
.println("Checking for Exception in case of null argument");
110 xSchemaHandlerImpl
.cleanCalls();
111 oObj
.readSchema(null);
112 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
113 log
.println("Expected Exception -- OK");
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");
122 "checking read data with own XSchemeHandler implementation");
125 xSchemaHandlerImpl
.cleanCalls();
126 oObj
.readSchema(xSchemaHandlerImpl
);
128 String implCalled
= xSchemaHandlerImpl
.getCalls();
130 int sc
= implCalled
.indexOf("startSchema");
133 log
.println("startSchema wasn't called -- FAILED");
136 log
.println("startSchema was called -- OK");
140 int ec
= implCalled
.indexOf("endSchema");
143 log
.println("endSchema wasn't called -- FAILED");
146 log
.println("endSchema was called -- OK");
149 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
150 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
152 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
153 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
155 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
156 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
160 // check for the wrapped target exception
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");
169 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
170 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
173 tRes
.tested("readSchema()", res
);
177 public void _readTemplates() {
180 log
.println("Checking for Exception in case of null argument");
183 oObj
.readTemplates(null);
184 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
185 log
.println("Expected Exception -- OK");
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");
194 "checking readComponent with own XSchemeHandler implementation");
197 xSchemaHandlerImpl
.cleanCalls();
198 oObj
.readComponent(xSchemaHandlerImpl
);
200 String implCalled
= xSchemaHandlerImpl
.getCalls();
202 int sc
= implCalled
.indexOf("startGroup");
205 log
.println("startGroup wasn't called -- FAILED");
208 log
.println("startGroup was called -- OK");
212 int ec
= implCalled
.indexOf("endNode");
215 log
.println("endNode wasn't called -- FAILED");
218 log
.println("endNode was called -- OK");
221 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
222 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
224 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
225 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
227 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
228 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
232 tRes
.tested("readTemplates()", res
);
237 * reopen the parsed file again, to avoid the wrapped target exception.
239 private void reopenFile() {
240 XSimpleFileAccess simpleAccess
= null;
241 XInputStream xStream
= null;
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
);