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