1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.configuration.backend;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.configuration.backend.XSchema;
27cdf0e10cSrcweir import com.sun.star.io.XActiveDataSink;
28cdf0e10cSrcweir import com.sun.star.io.XInputStream;
29cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
30cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess;
31cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir import lib.MultiMethodTest;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import util.XSchemaHandlerImpl;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir public class _XSchema extends MultiMethodTest {
38cdf0e10cSrcweir     public XSchema oObj;
39cdf0e10cSrcweir     XSchemaHandlerImpl xSchemaHandlerImpl = new XSchemaHandlerImpl();
40cdf0e10cSrcweir     String filename = null;
41cdf0e10cSrcweir 
before()42cdf0e10cSrcweir     protected void before() {
43cdf0e10cSrcweir         filename = (String)tEnv.getObjRelation("ParsedFileName");
44cdf0e10cSrcweir     }
45cdf0e10cSrcweir 
_readComponent()46cdf0e10cSrcweir     public void _readComponent() {
47cdf0e10cSrcweir         requiredMethod("readTemplates()");
48cdf0e10cSrcweir         boolean res = false;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir         log.println("Checking for Exception in case of null argument");
51cdf0e10cSrcweir 
52cdf0e10cSrcweir         try {
53cdf0e10cSrcweir             oObj.readComponent(null);
54cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
55cdf0e10cSrcweir             log.println("Expected Exception -- OK");
56cdf0e10cSrcweir             res = true;
57cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
58cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
59cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
60cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
61cdf0e10cSrcweir         }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         log.println(
64cdf0e10cSrcweir                 "checking readComponent with own XSchemeHandler implementation");
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         try {
67cdf0e10cSrcweir             xSchemaHandlerImpl.cleanCalls();
68cdf0e10cSrcweir             oObj.readComponent(xSchemaHandlerImpl);
69cdf0e10cSrcweir 
70cdf0e10cSrcweir             String implCalled = xSchemaHandlerImpl.getCalls();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir             System.out.println(implCalled);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             int sc = implCalled.indexOf("startComponent");
75cdf0e10cSrcweir 
76cdf0e10cSrcweir             if (sc < 0) {
77cdf0e10cSrcweir                 log.println("startComponent wasn't called -- FAILED");
78cdf0e10cSrcweir                 res &= false;
79cdf0e10cSrcweir             } else {
80cdf0e10cSrcweir                 log.println("startComponent was called -- OK");
81cdf0e10cSrcweir                 res &= true;
82cdf0e10cSrcweir             }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir             int ec = implCalled.indexOf("endComponent");
85cdf0e10cSrcweir 
86cdf0e10cSrcweir             if (ec < 0) {
87cdf0e10cSrcweir                 log.println("endComponent wasn't called -- FAILED");
88cdf0e10cSrcweir                 res &= false;
89cdf0e10cSrcweir             } else {
90cdf0e10cSrcweir                 log.println("endComponent was called -- OK");
91cdf0e10cSrcweir                 res &= true;
92cdf0e10cSrcweir             }
93cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
94cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
95cdf0e10cSrcweir             res &= false;
96cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
97cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
98cdf0e10cSrcweir             res &= false;
99cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
100cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
101cdf0e10cSrcweir             res &= false;
102cdf0e10cSrcweir         }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         tRes.tested("readComponent()", res);
105cdf0e10cSrcweir         reopenFile();
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
_readSchema()108cdf0e10cSrcweir     public void _readSchema() {
109cdf0e10cSrcweir         requiredMethod("readComponent()");
110cdf0e10cSrcweir         boolean res = false;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         log.println("Checking for Exception in case of null argument");
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         try {
115cdf0e10cSrcweir             xSchemaHandlerImpl.cleanCalls();
116cdf0e10cSrcweir             oObj.readSchema(null);
117cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
118cdf0e10cSrcweir             log.println("Expected Exception -- OK");
119cdf0e10cSrcweir             res = true;
120cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
121cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
122cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
123cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         log.println(
127cdf0e10cSrcweir                 "checking read data with own XSchemeHandler implementation");
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         try {
130cdf0e10cSrcweir             xSchemaHandlerImpl.cleanCalls();
131cdf0e10cSrcweir             oObj.readSchema(xSchemaHandlerImpl);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir             String implCalled = xSchemaHandlerImpl.getCalls();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             int sc = implCalled.indexOf("startSchema");
136cdf0e10cSrcweir 
137cdf0e10cSrcweir             if (sc < 0) {
138cdf0e10cSrcweir                 log.println("startSchema wasn't called -- FAILED");
139cdf0e10cSrcweir                 res &= false;
140cdf0e10cSrcweir             } else {
141cdf0e10cSrcweir                 log.println("startSchema was called -- OK");
142cdf0e10cSrcweir                 res &= true;
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir             int ec = implCalled.indexOf("endSchema");
146cdf0e10cSrcweir 
147cdf0e10cSrcweir             if (ec < 0) {
148cdf0e10cSrcweir                 log.println("endSchema wasn't called -- FAILED");
149cdf0e10cSrcweir                 res &= false;
150cdf0e10cSrcweir             } else {
151cdf0e10cSrcweir                 log.println("endSchema was called -- OK");
152cdf0e10cSrcweir                 res &= true;
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
155cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
156cdf0e10cSrcweir             res &= false;
157cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
158cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
159cdf0e10cSrcweir             res &= false;
160cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
161cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
162cdf0e10cSrcweir             res &= false;
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         // check for the wrapped target exception
166cdf0e10cSrcweir         try {
167cdf0e10cSrcweir             xSchemaHandlerImpl.cleanCalls();
168cdf0e10cSrcweir             oObj.readSchema(xSchemaHandlerImpl);
169cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
170cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
171cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
172cdf0e10cSrcweir             log.println("Expected Exception -- OK");
173cdf0e10cSrcweir             res = true;
174cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
175cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         tRes.tested("readSchema()", res);
179cdf0e10cSrcweir         reopenFile();
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir 
_readTemplates()182cdf0e10cSrcweir     public void _readTemplates() {
183cdf0e10cSrcweir         boolean res = false;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         log.println("Checking for Exception in case of null argument");
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         try {
188cdf0e10cSrcweir             oObj.readTemplates(null);
189cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
190cdf0e10cSrcweir             log.println("Expected Exception -- OK");
191cdf0e10cSrcweir             res = true;
192cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
193cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
194cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
195cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         log.println(
199cdf0e10cSrcweir                 "checking readComponent with own XSchemeHandler implementation");
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         try {
202cdf0e10cSrcweir             xSchemaHandlerImpl.cleanCalls();
203cdf0e10cSrcweir             oObj.readComponent(xSchemaHandlerImpl);
204cdf0e10cSrcweir 
205cdf0e10cSrcweir             String implCalled = xSchemaHandlerImpl.getCalls();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir             int sc = implCalled.indexOf("startGroup");
208cdf0e10cSrcweir 
209cdf0e10cSrcweir             if (sc < 0) {
210cdf0e10cSrcweir                 log.println("startGroup wasn't called -- FAILED");
211cdf0e10cSrcweir                 res &= false;
212cdf0e10cSrcweir             } else {
213cdf0e10cSrcweir                 log.println("startGroup was called -- OK");
214cdf0e10cSrcweir                 res &= true;
215cdf0e10cSrcweir             }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir             int ec = implCalled.indexOf("endNode");
218cdf0e10cSrcweir 
219cdf0e10cSrcweir             if (ec < 0) {
220cdf0e10cSrcweir                 log.println("endNode wasn't called -- FAILED");
221cdf0e10cSrcweir                 res &= false;
222cdf0e10cSrcweir             } else {
223cdf0e10cSrcweir                 log.println("endNode was called -- OK");
224cdf0e10cSrcweir                 res &= true;
225cdf0e10cSrcweir             }
226cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
227cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
228cdf0e10cSrcweir             res &= false;
229cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
230cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
231cdf0e10cSrcweir             res &= false;
232cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
233cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
234cdf0e10cSrcweir             res &= false;
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         tRes.tested("readTemplates()", res);
238cdf0e10cSrcweir         reopenFile();
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     /**
242cdf0e10cSrcweir      * reopen the parsed file again, to avoid the wrapped target exception.
243cdf0e10cSrcweir      */
reopenFile()244cdf0e10cSrcweir     private void reopenFile() {
245cdf0e10cSrcweir         XSimpleFileAccess simpleAccess = null;
246cdf0e10cSrcweir         XInputStream xStream = null;
247cdf0e10cSrcweir         try {
248cdf0e10cSrcweir             Object fileacc = ((XMultiServiceFactory)tParam.getMSF()).createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
249cdf0e10cSrcweir             simpleAccess = (XSimpleFileAccess)
250cdf0e10cSrcweir                             UnoRuntime.queryInterface(XSimpleFileAccess.class,fileacc);
251cdf0e10cSrcweir             log.println("Going to parse: "+filename);
252cdf0e10cSrcweir             xStream = simpleAccess.openFileRead(filename);
253cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
254cdf0e10cSrcweir         }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         XActiveDataSink xSink = (XActiveDataSink) UnoRuntime.queryInterface(XActiveDataSink.class, oObj);
257cdf0e10cSrcweir         xSink.setInputStream(xStream);
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir }