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 .
18 package ifc
.configuration
.backend
;
20 import com
.sun
.star
.configuration
.backend
.XBackend
;
21 import com
.sun
.star
.configuration
.backend
.XLayer
;
22 import com
.sun
.star
.configuration
.backend
.XUpdateHandler
;
23 import com
.sun
.star
.lang
.XMultiServiceFactory
;
24 import com
.sun
.star
.uno
.UnoRuntime
;
25 import com
.sun
.star
.util
.XStringSubstitution
;
27 import lib
.MultiMethodTest
;
29 import util
.XLayerHandlerImpl
;
32 public class _XBackend
extends MultiMethodTest
{
35 public void _getOwnUpdateHandler() {
38 String noUpdate
= (String
) tEnv
.getObjRelation("noUpdate");
40 if (noUpdate
!= null) {
41 log
.println(noUpdate
);
42 tRes
.tested("getOwnUpdateHandler()", res
);
48 XUpdateHandler aHandler
= oObj
.getOwnUpdateHandler(
49 "org.openoffice.Office.Linguistic");
50 res
&= (aHandler
!= null);
52 if (aHandler
== null) {
53 log
.println("\treturned Layer is NULL -- FAILED");
55 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
56 log
.println("unexpected Exception " + e
+ " -- FAILED");
58 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
59 log
.println("unexpected Exception " + e
+ " -- FAILED");
61 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
62 log
.println("unexpected Exception " + e
+ " -- FAILED");
66 tRes
.tested("getOwnUpdateHandler()", res
);
69 public void _getUpdateHandler() {
72 String noUpdate
= (String
) tEnv
.getObjRelation("noUpdate");
74 if (noUpdate
!= null) {
75 log
.println(noUpdate
);
76 tRes
.tested("getUpdateHandler()", res
);
82 oObj
.getUpdateHandler(
83 "org.openoffice.Office.TypeDetection",
85 log
.println("Exception expected -- FAILED");
87 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
88 log
.println("expected Exception -- OK");
89 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
90 log
.println("unexpected Exception -- FAILED");
92 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
93 log
.println("unexpected Exception " + e
+ " -- FAILED");
98 XStringSubstitution sts
= createStringSubstitution(
100 String ent
= sts
.getSubstituteVariableValue("$(inst)") +
102 XUpdateHandler aHandler
= oObj
.getUpdateHandler(
103 "org.openoffice.Office.Jobs",
106 if (aHandler
== null) {
107 log
.println("\treturned Layer is NULL -- FAILED");
109 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
110 log
.println("unexpected Exception -- FAILED");
112 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
113 log
.println("unexpected Exception -- FAILED");
115 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
116 log
.println("unexpected Exception " + e
+ " -- FAILED");
118 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
119 log
.println("unexpected Exception " + e
+ " -- FAILED");
123 tRes
.tested("getUpdateHandler()", res
);
126 public void _listLayers() {
130 XStringSubstitution sts
= createStringSubstitution(
132 String ent
= sts
.getSubstituteVariableValue("$(inst)") +
134 XLayer
[] Layers
= oObj
.listLayers(
135 "org.openoffice.Office.Linguistic", ent
);
137 for (int i
= 0; i
< Layers
.length
; i
++) {
138 log
.println("Checking Layer " + i
);
139 res
&= checkLayer(Layers
[i
]);
141 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
142 log
.println("unexpected Exception " + e
+ " -- FAILED");
144 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
145 log
.println("unexpected Exception " + e
+ " -- FAILED");
147 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
148 log
.println("unexpected Exception " + e
+ " -- FAILED");
152 tRes
.tested("listLayers()", res
);
155 public void _listOwnLayers() {
159 XLayer
[] Layers
= oObj
.listOwnLayers(
160 "org.openoffice.Office.Common");
162 for (int i
= 0; i
< Layers
.length
; i
++) {
163 log
.println("Checking Layer " + i
);
164 res
&= checkLayer(Layers
[i
]);
166 if (Layers
.length
==0) {
167 System
.out
.println("No Layers found -- FAILED");
170 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
171 log
.println("unexpected Exception " + e
+ " -- FAILED");
173 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
174 log
.println("unexpected Exception " + e
+ " -- FAILED");
178 tRes
.tested("listOwnLayers()", res
);
181 protected boolean checkLayer(XLayer aLayer
) {
184 log
.println("Checking for Exception in case of null argument");
187 aLayer
.readData(null);
188 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
189 log
.println("Expected Exception -- OK");
191 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
192 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
193 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
194 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
197 log
.println("checking read data with own XLayerHandler implementation");
200 XLayerHandlerImpl xLayerHandler
= new XLayerHandlerImpl();
201 aLayer
.readData(xLayerHandler
);
203 String implCalled
= xLayerHandler
.getCalls();
204 log
.println(implCalled
);
206 int sl
= implCalled
.indexOf("startLayer");
209 log
.println("startLayer wasn't called -- FAILED");
212 log
.println("startLayer was called -- OK");
216 int el
= implCalled
.indexOf("endLayer");
219 log
.println("endLayer wasn't called -- FAILED");
222 log
.println("endLayer was called -- OK");
225 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
226 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
228 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
229 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
231 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
232 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
239 public static XStringSubstitution
createStringSubstitution(XMultiServiceFactory xMSF
) {
240 Object xPathSubst
= null;
243 xPathSubst
= xMSF
.createInstance(
244 "com.sun.star.util.PathSubstitution");
245 } catch (com
.sun
.star
.uno
.Exception e
) {
249 if (xPathSubst
!= null) {
250 return UnoRuntime
.queryInterface(
251 XStringSubstitution
.class, xPathSubst
);