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: _XMultiLayerStratum.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
.XLayer
;
33 import com
.sun
.star
.configuration
.backend
.XMultiLayerStratum
;
34 import com
.sun
.star
.configuration
.backend
.XUpdatableLayer
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import lib
.MultiMethodTest
;
39 import util
.XLayerHandlerImpl
;
42 public class _XMultiLayerStratum
extends MultiMethodTest
{
43 public XMultiLayerStratum oObj
;
44 protected String aLayerID
;
46 public void _getLayer() {
50 XLayer aLayer
= oObj
.getLayer("", "");
51 log
.println("Exception expected -- FAILED");
53 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
54 log
.println("unexpected Exception " + e
+ " -- FAILED");
56 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
57 log
.println("expected Exception -- OK");
61 XLayer aLayer
= oObj
.getLayer(aLayerID
, "");
62 res
&= (aLayer
!= null);
65 log
.println("\treturned Layer is NULL -- FAILED");
68 res
&= checkLayer(aLayer
);
69 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
70 log
.println("unexpected Exception -- FAILED");
72 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
73 log
.println("unexpected Exception -- FAILED");
77 tRes
.tested("getLayer()", res
);
80 public void _getLayers() {
84 String
[] LayerIds
= new String
[2];
85 LayerIds
[0] = "1 /org/openoffice/Office/Jobs.xcu";
86 LayerIds
[1] = "2 /org/openoffice/Office/Linguistic.xcu";
88 XLayer
[] Layers
= oObj
.getLayers(LayerIds
, "");
89 res
= Layers
.length
== 2;
90 log
.println("Getting two XLayers -- OK");
91 log
.println("Checking first on "+LayerIds
[0]);
92 res
&= checkLayer(Layers
[0]);
93 log
.println("Checking second on "+LayerIds
[1]);
94 res
&= checkLayer(Layers
[1]);
95 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
96 log
.println("unexpected Exception -- FAILED");
98 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
99 log
.println("unexpected Exception -- FAILED");
103 tRes
.tested("getLayers()", res
);
106 public void _getMultipleLayers() {
110 String
[] LayerIds
= new String
[2];
111 LayerIds
[0] = "1 /org/openoffice/Office/Jobs.xcu";
112 LayerIds
[1] = "2 /org/openoffice/Office/Linguistic.xcu";
113 String
[] Times
= new String
[2];
117 XLayer
[] Layers
= oObj
.getMultipleLayers(LayerIds
, Times
);
118 res
= Layers
.length
== 2;
119 log
.println("Getting two XLayers -- OK");
120 log
.println("Checking first on "+LayerIds
[0]);
121 res
&= checkLayer(Layers
[0]);
122 log
.println("Checking second on "+LayerIds
[1]);
123 res
&= checkLayer(Layers
[1]);
124 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
125 log
.println("unexpected Exception -- FAILED");
127 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
128 log
.println("unexpected Exception -- FAILED");
132 tRes
.tested("getMultipleLayers()", res
);
135 public void _getUpdatableLayer() {
139 XUpdatableLayer aLayer
= oObj
.getUpdatableLayer("");
140 log
.println("Exception expected -- FAILED");
142 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
143 log
.println("unexpected Exception " + e
+ " -- FAILED");
145 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
146 log
.println("expected Exception -- OK");
147 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
148 log
.println("unexpected Exception -- FAILED");
153 XUpdatableLayer aLayer
= oObj
.getUpdatableLayer(aLayerID
);
154 res
&= (aLayer
!= null);
156 if (aLayer
== null) {
157 log
.println("\treturned Layer is NULL -- FAILED");
160 res
&= checkLayer(aLayer
);
161 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
162 log
.println("unexpected Exception -- FAILED");
164 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
165 log
.println("unexpected Exception -- FAILED");
167 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
168 log
.println("unexpected Exception -- FAILED");
172 tRes
.tested("getUpdatableLayer()", res
);
175 public void _getUpdateLayerId() {
179 String UpdateLayerID
= oObj
.getUpdateLayerId(
180 "org.openoffice.Office.TypeDetection",
182 log
.println("Exception expected -- FAILED");
184 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
185 log
.println("expected Exception -- OK");
186 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
187 log
.println("unexpected Exception -- FAILED");
189 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
190 log
.println("unexpected Exception -- FAILED");
195 String ent
= util
.utils
.getOfficeURL(
196 (XMultiServiceFactory
) tParam
.getMSF()) +
197 "/../share/registry";
198 String UpdateLayerID
= oObj
.getUpdateLayerId(
199 "org.openoffice.Office.Linguistic", ent
);
200 res
&= UpdateLayerID
.endsWith("Linguistic.xcu");
202 if (!UpdateLayerID
.endsWith("Linguistic.xcu")) {
203 log
.println("\tExpected the id to end with Linguistic.xcu");
204 log
.println("\tBut got " + UpdateLayerID
);
205 log
.println("\t=> FAILED");
207 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
208 log
.println("unexpected Exception -- FAILED");
210 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
211 log
.println("unexpected Exception "+e
+" -- FAILED");
213 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
214 log
.println("unexpected Exception -- FAILED");
218 tRes
.tested("getUpdateLayerId()", res
);
221 public void _listLayerIds() {
225 String
[] LayerIDs
= oObj
.listLayerIds(
226 "org.openoffice.Office.TypeDetection",
228 log
.println("Exception expected -- FAILED");
230 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
231 log
.println("expected Exception -- OK");
232 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
233 log
.println("unexpected Exception -- FAILED");
238 String ent
= util
.utils
.getOfficeURL(
239 (XMultiServiceFactory
) tParam
.getMSF()) +
240 "/../share/registry";
241 String
[] LayerIDs
= oObj
.listLayerIds("org.openoffice.Office.Jobs",
243 res
&= LayerIDs
[0].endsWith("Jobs.xcu");
244 aLayerID
= LayerIDs
[0];
246 if (!LayerIDs
[0].endsWith("Jobs.xcu")) {
247 log
.println("\tExpected the id to end with Jobs.xcu");
248 log
.println("\tBut got " + LayerIDs
[0]);
249 log
.println("\t=> FAILED");
251 } catch (com
.sun
.star
.configuration
.backend
.BackendAccessException e
) {
252 log
.println("unexpected Exception -- FAILED");
254 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
255 log
.println("unexpected Exception -- FAILED");
259 tRes
.tested("listLayerIds()", res
);
262 protected boolean checkLayer(XLayer aLayer
) {
265 log
.println("Checking for Exception in case of null argument");
268 aLayer
.readData(null);
269 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
270 log
.println("Expected Exception -- OK");
272 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
273 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
274 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
275 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
278 log
.println("checking read data with own XLayerHandler implementation");
281 XLayerHandlerImpl xLayerHandler
= new XLayerHandlerImpl();
282 aLayer
.readData(xLayerHandler
);
284 String implCalled
= xLayerHandler
.getCalls();
285 log
.println(implCalled
);
287 int sl
= implCalled
.indexOf("startLayer");
290 log
.println("startLayer wasn't called -- FAILED");
293 log
.println("startLayer was called -- OK");
297 int el
= implCalled
.indexOf("endLayer");
300 log
.println("endLayer wasn't called -- FAILED");
303 log
.println("endLayer was called -- OK");
306 } catch (com
.sun
.star
.lang
.NullPointerException e
) {
307 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
309 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
310 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");
312 } catch (com
.sun
.star
.configuration
.backend
.MalformedDataException e
) {
313 log
.println("Unexpected Exception (" + e
+ ") -- FAILED");