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: _XBackend.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 ************************************************************************/
30 package ifc
.configuration
.backend
;
32 import com
.sun
.star
.configuration
.backend
.XBackend
;
33 import com
.sun
.star
.configuration
.backend
.XLayer
;
34 import com
.sun
.star
.configuration
.backend
.XUpdateHandler
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.util
.XStringSubstitution
;
39 import lib
.MultiMethodTest
;
41 import util
.XLayerHandlerImpl
;
44 public class _XBackend
extends MultiMethodTest
{
47 public void _getOwnUpdateHandler() {
50 String noUpdate
= (String
) tEnv
.getObjRelation("noUpdate");
52 if (noUpdate
!= null) {
53 log
.println(noUpdate
);
54 tRes
.tested("getOwnUpdateHandler()", res
);
60 XUpdateHandler aHandler
= oObj
.getOwnUpdateHandler(
61 "org.openoffice.Office.Linguistic");
62 res
&= (aHandler
!= null);
64 if (aHandler
== null) {
65 log
.println("\treturned Layer is NULL -- FAILED");
67 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
68 log
.println("unexpected Exception " + e
+ " -- FAILED");
70 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
71 log
.println("unexpected Exception " + e
+ " -- FAILED");
73 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
74 log
.println("unexpected Exception " + e
+ " -- FAILED");
78 tRes
.tested("getOwnUpdateHandler()", res
);
81 public void _getUpdateHandler() {
84 String noUpdate
= (String
) tEnv
.getObjRelation("noUpdate");
86 if (noUpdate
!= null) {
87 log
.println(noUpdate
);
88 tRes
.tested("getUpdateHandler()", res
);
94 XUpdateHandler aHandler
= oObj
.getUpdateHandler(
95 "org.openoffice.Office.TypeDetection",
97 log
.println("Exception expected -- FAILED");
99 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
100 log
.println("expected Exception -- OK");
101 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
102 log
.println("unexpected Exception -- FAILED");
104 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
105 log
.println("unexpected Exception " + e
+ " -- FAILED");
110 XStringSubstitution sts
= createStringSubstitution(
111 (XMultiServiceFactory
) tParam
.getMSF());
112 String ent
= sts
.getSubstituteVariableValue("$(inst)") +
114 XUpdateHandler aHandler
= oObj
.getUpdateHandler(
115 "org.openoffice.Office.Jobs",
118 if (aHandler
== null) {
119 log
.println("\treturned Layer is NULL -- FAILED");
121 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
122 log
.println("unexpected Exception -- FAILED");
124 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
125 log
.println("unexpected Exception -- FAILED");
127 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
128 log
.println("unexpected Exception " + e
+ " -- FAILED");
130 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
131 log
.println("unexpected Exception " + e
+ " -- FAILED");
135 tRes
.tested("getUpdateHandler()", res
);
138 public void _listLayers() {
142 XStringSubstitution sts
= createStringSubstitution(
143 (XMultiServiceFactory
) tParam
.getMSF());
144 String ent
= sts
.getSubstituteVariableValue("$(inst)") +
146 XLayer
[] Layers
= oObj
.listLayers(
147 "org.openoffice.Office.Linguistic", ent
);
149 for (int i
= 0; i
< Layers
.length
; i
++) {
150 log
.println("Checking Layer " + i
);
151 res
&= checkLayer(Layers
[i
]);
153 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
154 log
.println("unexpected Exception " + e
+ " -- FAILED");
156 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
157 log
.println("unexpected Exception " + e
+ " -- FAILED");
159 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
160 log
.println("unexpected Exception " + e
+ " -- FAILED");
164 tRes
.tested("listLayers()", res
);
167 public void _listOwnLayers() {
171 XLayer
[] Layers
= oObj
.listOwnLayers(
172 "org.openoffice.Office.Common");
174 for (int i
= 0; i
< Layers
.length
; i
++) {
175 log
.println("Checking Layer " + i
);
176 res
&= checkLayer(Layers
[i
]);
178 if (Layers
.length
==0) {
179 System
.out
.println("No Layers found -- FAILED");
182 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
183 log
.println("unexpected Exception " + e
+ " -- FAILED");
185 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
186 log
.println("unexpected Exception " + e
+ " -- FAILED");
190 tRes
.tested("listOwnLayers()", res
);
193 protected boolean checkLayer(XLayer aLayer
) {
196 log
.println("Checking for Exception in case of null argument");
199 aLayer
.readData(null);
200 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
201 log
.println("Expected Exception -- OK");
203 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
204 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
205 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
206 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
209 log
.println("checking read data with own XLayerHandler implementation");
212 XLayerHandlerImpl xLayerHandler
= new XLayerHandlerImpl();
213 aLayer
.readData(xLayerHandler
);
215 String implCalled
= xLayerHandler
.getCalls();
216 log
.println(implCalled
);
218 int sl
= implCalled
.indexOf("startLayer");
221 log
.println("startLayer wasn't called -- FAILED");
224 log
.println("startLayer was called -- OK");
228 int el
= implCalled
.indexOf("endLayer");
231 log
.println("endLayer wasn't called -- FAILED");
234 log
.println("endLayer was called -- OK");
237 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
238 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
240 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
241 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
243 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
244 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
251 public static XStringSubstitution
createStringSubstitution(XMultiServiceFactory xMSF
) {
252 Object xPathSubst
= null;
255 xPathSubst
= xMSF
.createInstance(
256 "com.sun.star.util.PathSubstitution");
257 } catch (com
.sun
.star
.uno
.Exception e
) {
261 if (xPathSubst
!= null) {
262 return (XStringSubstitution
) UnoRuntime
.queryInterface(
263 XStringSubstitution
.class, xPathSubst
);