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 package ifc.configuration.backend;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.configuration.backend.XLayer;
26cdf0e10cSrcweir import com.sun.star.configuration.backend.XMultiLayerStratum;
27cdf0e10cSrcweir import com.sun.star.configuration.backend.XUpdatableLayer;
28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import lib.MultiMethodTest;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir import util.XLayerHandlerImpl;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir public class _XMultiLayerStratum extends MultiMethodTest {
36cdf0e10cSrcweir     public XMultiLayerStratum oObj;
37cdf0e10cSrcweir     protected String aLayerID;
38cdf0e10cSrcweir 
_getLayer()39cdf0e10cSrcweir     public void _getLayer() {
40cdf0e10cSrcweir         boolean res = true;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir         try {
43cdf0e10cSrcweir             XLayer aLayer = oObj.getLayer("", "");
44cdf0e10cSrcweir             log.println("Exception expected -- FAILED");
45cdf0e10cSrcweir             res = false;
46cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
47cdf0e10cSrcweir             log.println("unexpected Exception " + e + " -- FAILED");
48cdf0e10cSrcweir             res = false;
49cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
50cdf0e10cSrcweir             log.println("expected Exception -- OK");
51cdf0e10cSrcweir         }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         try {
54cdf0e10cSrcweir             XLayer aLayer = oObj.getLayer(aLayerID, "");
55cdf0e10cSrcweir             res &= (aLayer != null);
56cdf0e10cSrcweir 
57cdf0e10cSrcweir             if (aLayer == null) {
58cdf0e10cSrcweir                 log.println("\treturned Layer is NULL -- FAILED");
59cdf0e10cSrcweir             }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir             res &= checkLayer(aLayer);
62cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
63cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
64cdf0e10cSrcweir             res = false;
65cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
66cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
67cdf0e10cSrcweir             res = false;
68cdf0e10cSrcweir         }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         tRes.tested("getLayer()", res);
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
_getLayers()73cdf0e10cSrcweir     public void _getLayers() {
74cdf0e10cSrcweir         boolean res = true;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         try {
77cdf0e10cSrcweir             String[] LayerIds = new String[2];
78cdf0e10cSrcweir             LayerIds[0] = "1 /org/openoffice/Office/Jobs.xcu";
79cdf0e10cSrcweir             LayerIds[1] = "2 /org/openoffice/Office/Linguistic.xcu";
80cdf0e10cSrcweir 
81cdf0e10cSrcweir             XLayer[] Layers = oObj.getLayers(LayerIds, "");
82cdf0e10cSrcweir             res = Layers.length == 2;
83cdf0e10cSrcweir             log.println("Getting two XLayers -- OK");
84cdf0e10cSrcweir             log.println("Checking first on "+LayerIds[0]);
85cdf0e10cSrcweir             res &= checkLayer(Layers[0]);
86cdf0e10cSrcweir             log.println("Checking second on "+LayerIds[1]);
87cdf0e10cSrcweir             res &= checkLayer(Layers[1]);
88cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
89cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
90cdf0e10cSrcweir             res = false;
91cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
92cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
93cdf0e10cSrcweir             res = false;
94cdf0e10cSrcweir         }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         tRes.tested("getLayers()", res);
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
_getMultipleLayers()99cdf0e10cSrcweir     public void _getMultipleLayers() {
100cdf0e10cSrcweir         boolean res = true;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         try {
103cdf0e10cSrcweir             String[] LayerIds = new String[2];
104cdf0e10cSrcweir             LayerIds[0] = "1 /org/openoffice/Office/Jobs.xcu";
105cdf0e10cSrcweir             LayerIds[1] = "2 /org/openoffice/Office/Linguistic.xcu";
106cdf0e10cSrcweir             String[] Times = new String[2];
107cdf0e10cSrcweir             Times[0] = "";
108cdf0e10cSrcweir             Times[1] = "";
109cdf0e10cSrcweir 
110cdf0e10cSrcweir             XLayer[] Layers = oObj.getMultipleLayers(LayerIds, Times);
111cdf0e10cSrcweir             res = Layers.length == 2;
112cdf0e10cSrcweir             log.println("Getting two XLayers -- OK");
113cdf0e10cSrcweir             log.println("Checking first on "+LayerIds[0]);
114cdf0e10cSrcweir             res &= checkLayer(Layers[0]);
115cdf0e10cSrcweir             log.println("Checking second on "+LayerIds[1]);
116cdf0e10cSrcweir             res &= checkLayer(Layers[1]);
117cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
118cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
119cdf0e10cSrcweir             res = false;
120cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
121cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
122cdf0e10cSrcweir             res = false;
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         tRes.tested("getMultipleLayers()", res);
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
_getUpdatableLayer()128cdf0e10cSrcweir     public void _getUpdatableLayer() {
129cdf0e10cSrcweir         boolean res = true;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         try {
132cdf0e10cSrcweir             XUpdatableLayer aLayer = oObj.getUpdatableLayer("");
133cdf0e10cSrcweir             log.println("Exception expected -- FAILED");
134cdf0e10cSrcweir             res = false;
135cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
136cdf0e10cSrcweir             log.println("unexpected Exception " + e + " -- FAILED");
137cdf0e10cSrcweir             res = false;
138cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
139cdf0e10cSrcweir             log.println("expected Exception -- OK");
140cdf0e10cSrcweir         } catch (com.sun.star.lang.NoSupportException e) {
141cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
142cdf0e10cSrcweir             res = false;
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         try {
146cdf0e10cSrcweir             XUpdatableLayer aLayer = oObj.getUpdatableLayer(aLayerID);
147cdf0e10cSrcweir             res &= (aLayer != null);
148cdf0e10cSrcweir 
149cdf0e10cSrcweir             if (aLayer == null) {
150cdf0e10cSrcweir                 log.println("\treturned Layer is NULL -- FAILED");
151cdf0e10cSrcweir             }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir             res &= checkLayer(aLayer);
154cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
155cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
156cdf0e10cSrcweir             res = false;
157cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
158cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
159cdf0e10cSrcweir             res = false;
160cdf0e10cSrcweir         } catch (com.sun.star.lang.NoSupportException e) {
161cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
162cdf0e10cSrcweir             res = false;
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         tRes.tested("getUpdatableLayer()", res);
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
_getUpdateLayerId()168cdf0e10cSrcweir     public void _getUpdateLayerId() {
169cdf0e10cSrcweir         boolean res = true;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         try {
172cdf0e10cSrcweir             String UpdateLayerID = oObj.getUpdateLayerId(
173cdf0e10cSrcweir                                            "org.openoffice.Office.TypeDetection",
174cdf0e10cSrcweir                                            "illegal");
175cdf0e10cSrcweir             log.println("Exception expected -- FAILED");
176cdf0e10cSrcweir             res = false;
177cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
178cdf0e10cSrcweir             log.println("expected Exception -- OK");
179cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
180cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
181cdf0e10cSrcweir             res = false;
182cdf0e10cSrcweir         } catch (com.sun.star.lang.NoSupportException e) {
183cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
184cdf0e10cSrcweir             res = false;
185cdf0e10cSrcweir         }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         try {
188cdf0e10cSrcweir             String ent = util.utils.getOfficeURL(
189cdf0e10cSrcweir                                  (XMultiServiceFactory) tParam.getMSF()) +
190cdf0e10cSrcweir                          "/../share/registry";
191cdf0e10cSrcweir             String UpdateLayerID = oObj.getUpdateLayerId(
192cdf0e10cSrcweir                                            "org.openoffice.Office.Linguistic", ent);
193cdf0e10cSrcweir             res &= UpdateLayerID.endsWith("Linguistic.xcu");
194cdf0e10cSrcweir 
195cdf0e10cSrcweir             if (!UpdateLayerID.endsWith("Linguistic.xcu")) {
196cdf0e10cSrcweir                 log.println("\tExpected the id to end with Linguistic.xcu");
197cdf0e10cSrcweir                 log.println("\tBut got " + UpdateLayerID);
198cdf0e10cSrcweir                 log.println("\t=> FAILED");
199cdf0e10cSrcweir             }
200cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
201cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
202cdf0e10cSrcweir             res = false;
203cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
204cdf0e10cSrcweir             log.println("unexpected Exception "+e+" -- FAILED");
205cdf0e10cSrcweir             res = false;
206cdf0e10cSrcweir         } catch (com.sun.star.lang.NoSupportException e) {
207cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
208cdf0e10cSrcweir             res = false;
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         tRes.tested("getUpdateLayerId()", res);
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 
_listLayerIds()214cdf0e10cSrcweir     public void _listLayerIds() {
215cdf0e10cSrcweir         boolean res = true;
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         try {
218cdf0e10cSrcweir             String[] LayerIDs = oObj.listLayerIds(
219cdf0e10cSrcweir                                         "org.openoffice.Office.TypeDetection",
220cdf0e10cSrcweir                                         "illegal");
221cdf0e10cSrcweir             log.println("Exception expected -- FAILED");
222cdf0e10cSrcweir             res = false;
223cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
224cdf0e10cSrcweir             log.println("expected Exception -- OK");
225cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
226cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
227cdf0e10cSrcweir             res = false;
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         try {
231cdf0e10cSrcweir             String ent = util.utils.getOfficeURL(
232cdf0e10cSrcweir                                  (XMultiServiceFactory) tParam.getMSF()) +
233cdf0e10cSrcweir                          "/../share/registry";
234cdf0e10cSrcweir             String[] LayerIDs = oObj.listLayerIds("org.openoffice.Office.Jobs",
235cdf0e10cSrcweir                                                   ent);
236cdf0e10cSrcweir             res &= LayerIDs[0].endsWith("Jobs.xcu");
237cdf0e10cSrcweir             aLayerID = LayerIDs[0];
238cdf0e10cSrcweir 
239cdf0e10cSrcweir             if (!LayerIDs[0].endsWith("Jobs.xcu")) {
240cdf0e10cSrcweir                 log.println("\tExpected the id to end with Jobs.xcu");
241cdf0e10cSrcweir                 log.println("\tBut got " + LayerIDs[0]);
242cdf0e10cSrcweir                 log.println("\t=> FAILED");
243cdf0e10cSrcweir             }
244cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
245cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
246cdf0e10cSrcweir             res = false;
247cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
248cdf0e10cSrcweir             log.println("unexpected Exception -- FAILED");
249cdf0e10cSrcweir             res = false;
250cdf0e10cSrcweir         }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir         tRes.tested("listLayerIds()", res);
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir 
checkLayer(XLayer aLayer)255cdf0e10cSrcweir     protected boolean checkLayer(XLayer aLayer) {
256cdf0e10cSrcweir         boolean res = false;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         log.println("Checking for Exception in case of null argument");
259cdf0e10cSrcweir 
260cdf0e10cSrcweir         try {
261cdf0e10cSrcweir             aLayer.readData(null);
262cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
263cdf0e10cSrcweir             log.println("Expected Exception -- OK");
264cdf0e10cSrcweir             res = true;
265cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
266cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
267cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
268cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
269cdf0e10cSrcweir         }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         log.println("checking read data with own XLayerHandler implementation");
272cdf0e10cSrcweir 
273cdf0e10cSrcweir         try {
274cdf0e10cSrcweir             XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
275cdf0e10cSrcweir             aLayer.readData(xLayerHandler);
276cdf0e10cSrcweir 
277cdf0e10cSrcweir             String implCalled = xLayerHandler.getCalls();
278cdf0e10cSrcweir             log.println(implCalled);
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             int sl = implCalled.indexOf("startLayer");
281cdf0e10cSrcweir 
282cdf0e10cSrcweir             if (sl < 0) {
283cdf0e10cSrcweir                 log.println("startLayer wasn't called -- FAILED");
284cdf0e10cSrcweir                 res &= false;
285cdf0e10cSrcweir             } else {
286cdf0e10cSrcweir                 log.println("startLayer was called -- OK");
287cdf0e10cSrcweir                 res &= true;
288cdf0e10cSrcweir             }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir             int el = implCalled.indexOf("endLayer");
291cdf0e10cSrcweir 
292cdf0e10cSrcweir             if (el < 0) {
293cdf0e10cSrcweir                 log.println("endLayer wasn't called -- FAILED");
294cdf0e10cSrcweir                 res &= false;
295cdf0e10cSrcweir             } else {
296cdf0e10cSrcweir                 log.println("endLayer was called -- OK");
297cdf0e10cSrcweir                 res &= true;
298cdf0e10cSrcweir             }
299cdf0e10cSrcweir         } catch (com.sun.star.lang.NullPointerException e) {
300cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
301cdf0e10cSrcweir             res &= false;
302cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
303cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
304cdf0e10cSrcweir             res &= false;
305cdf0e10cSrcweir         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
306cdf0e10cSrcweir             log.println("Unexpected Exception (" + e + ") -- FAILED");
307cdf0e10cSrcweir             res &= false;
308cdf0e10cSrcweir         }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir         return res;
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir }