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");
121 } catch (com
.sun
.star
.uno
.Exception e
) {
122 log
.println("unexpected Exception " + e
+ " -- FAILED");
126 tRes
.tested("getUpdateHandler()", res
);
129 public void _listLayers() {
133 XStringSubstitution sts
= createStringSubstitution(tParam
.getMSF());
134 String ent
= sts
.getSubstituteVariableValue("$(inst)") +
136 XLayer
[] Layers
= oObj
.listLayers(
137 "org.openoffice.Office.Linguistic", ent
);
139 for (int i
= 0; i
< Layers
.length
; i
++) {
140 log
.println("Checking Layer " + i
);
141 res
&= checkLayer(Layers
[i
]);
143 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
144 log
.println("unexpected Exception " + e
+ " -- FAILED");
146 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
147 log
.println("unexpected Exception " + e
+ " -- FAILED");
149 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
150 log
.println("unexpected Exception " + e
+ " -- FAILED");
152 } catch (com
.sun
.star
.uno
.Exception e
) {
153 log
.println("unexpected Exception " + e
+ " -- FAILED");
157 tRes
.tested("listLayers()", res
);
160 public void _listOwnLayers() {
164 XLayer
[] Layers
= oObj
.listOwnLayers(
165 "org.openoffice.Office.Common");
167 for (int i
= 0; i
< Layers
.length
; i
++) {
168 log
.println("Checking Layer " + i
);
169 res
&= checkLayer(Layers
[i
]);
171 if (Layers
.length
==0) {
172 System
.out
.println("No Layers found -- FAILED");
175 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
176 log
.println("unexpected Exception " + e
+ " -- FAILED");
178 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
179 log
.println("unexpected Exception " + e
+ " -- FAILED");
183 tRes
.tested("listOwnLayers()", res
);
186 protected boolean checkLayer(XLayer aLayer
) {
189 log
.println("Checking for Exception in case of null argument");
192 aLayer
.readData(null);
193 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
194 log
.println("Expected Exception -- OK");
196 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
197 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
198 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
199 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
202 log
.println("checking read data with own XLayerHandler implementation");
205 XLayerHandlerImpl xLayerHandler
= new XLayerHandlerImpl();
206 aLayer
.readData(xLayerHandler
);
208 String implCalled
= xLayerHandler
.getCalls();
209 log
.println(implCalled
);
211 int sl
= implCalled
.indexOf("startLayer");
214 log
.println("startLayer wasn't called -- FAILED");
217 log
.println("startLayer was called -- OK");
221 int el
= implCalled
.indexOf("endLayer");
224 log
.println("endLayer wasn't called -- FAILED");
227 log
.println("endLayer was called -- OK");
230 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
231 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
233 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
234 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
236 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
237 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
244 public static XStringSubstitution
createStringSubstitution(XMultiServiceFactory xMSF
) throws com
.sun
.star
.uno
.Exception
246 Object xPathSubst
= xMSF
.createInstance(
247 "com.sun.star.util.PathSubstitution");
248 return UnoRuntime
.queryInterface(XStringSubstitution
.class, xPathSubst
);