Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / configuration / backend / _XBackend.java
bloba530e14fccee98be9098386e6416d08a1c4b4365
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XBackend.java,v $
10 * $Revision: 1.6 $
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 {
45 public XBackend oObj;
47 public void _getOwnUpdateHandler() {
48 boolean res = true;
50 String noUpdate = (String) tEnv.getObjRelation("noUpdate");
52 if (noUpdate != null) {
53 log.println(noUpdate);
54 tRes.tested("getOwnUpdateHandler()", res);
56 return;
59 try {
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");
69 res = false;
70 } catch (com.sun.star.lang.IllegalArgumentException e) {
71 log.println("unexpected Exception " + e + " -- FAILED");
72 res = false;
73 } catch (com.sun.star.lang.NoSupportException e) {
74 log.println("unexpected Exception " + e + " -- FAILED");
75 res = false;
78 tRes.tested("getOwnUpdateHandler()", res);
81 public void _getUpdateHandler() {
82 boolean res = true;
84 String noUpdate = (String) tEnv.getObjRelation("noUpdate");
86 if (noUpdate != null) {
87 log.println(noUpdate);
88 tRes.tested("getUpdateHandler()", res);
90 return;
93 try {
94 XUpdateHandler aHandler = oObj.getUpdateHandler(
95 "org.openoffice.Office.TypeDetection",
96 "illegal");
97 log.println("Exception expected -- FAILED");
98 res = false;
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");
103 res = false;
104 } catch (com.sun.star.lang.NoSupportException e) {
105 log.println("unexpected Exception " + e + " -- FAILED");
106 res = false;
109 try {
110 XStringSubstitution sts = createStringSubstitution(
111 (XMultiServiceFactory) tParam.getMSF());
112 String ent = sts.getSubstituteVariableValue("$(inst)") +
113 "/share/registry";
114 XUpdateHandler aHandler = oObj.getUpdateHandler(
115 "org.openoffice.Office.Jobs",
116 ent);
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");
123 res = false;
124 } catch (com.sun.star.lang.IllegalArgumentException e) {
125 log.println("unexpected Exception -- FAILED");
126 res = false;
127 } catch (com.sun.star.lang.NoSupportException e) {
128 log.println("unexpected Exception " + e + " -- FAILED");
129 res = false;
130 } catch (com.sun.star.container.NoSuchElementException e) {
131 log.println("unexpected Exception " + e + " -- FAILED");
132 res = false;
135 tRes.tested("getUpdateHandler()", res);
138 public void _listLayers() {
139 boolean res = true;
141 try {
142 XStringSubstitution sts = createStringSubstitution(
143 (XMultiServiceFactory) tParam.getMSF());
144 String ent = sts.getSubstituteVariableValue("$(inst)") +
145 "/share/registry";
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");
155 res = false;
156 } catch (com.sun.star.lang.IllegalArgumentException e) {
157 log.println("unexpected Exception " + e + " -- FAILED");
158 res = false;
159 } catch (com.sun.star.container.NoSuchElementException e) {
160 log.println("unexpected Exception " + e + " -- FAILED");
161 res = false;
164 tRes.tested("listLayers()", res);
167 public void _listOwnLayers() {
168 boolean res = true;
170 try {
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");
180 res &= false;
182 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
183 log.println("unexpected Exception " + e + " -- FAILED");
184 res = false;
185 } catch (com.sun.star.lang.IllegalArgumentException e) {
186 log.println("unexpected Exception " + e + " -- FAILED");
187 res = false;
190 tRes.tested("listOwnLayers()", res);
193 protected boolean checkLayer(XLayer aLayer) {
194 boolean res = false;
196 log.println("Checking for Exception in case of null argument");
198 try {
199 aLayer.readData(null);
200 } catch (com.sun.star.lang.NullPointerException e) {
201 log.println("Expected Exception -- OK");
202 res = true;
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");
211 try {
212 XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
213 aLayer.readData(xLayerHandler);
215 String implCalled = xLayerHandler.getCalls();
216 log.println(implCalled);
218 int sl = implCalled.indexOf("startLayer");
220 if (sl < 0) {
221 log.println("startLayer wasn't called -- FAILED");
222 res &= false;
223 } else {
224 log.println("startLayer was called -- OK");
225 res &= true;
228 int el = implCalled.indexOf("endLayer");
230 if (el < 0) {
231 log.println("endLayer wasn't called -- FAILED");
232 res &= false;
233 } else {
234 log.println("endLayer was called -- OK");
235 res &= true;
237 } catch (com.sun.star.lang.NullPointerException e) {
238 log.println("Unexpected Exception (" + e + ") -- FAILED");
239 res &= false;
240 } catch (com.sun.star.lang.WrappedTargetException e) {
241 log.println("Unexpected Exception (" + e + ") -- FAILED");
242 res &= false;
243 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
244 log.println("Unexpected Exception (" + e + ") -- FAILED");
245 res &= false;
248 return res;
251 public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) {
252 Object xPathSubst = null;
254 try {
255 xPathSubst = xMSF.createInstance(
256 "com.sun.star.util.PathSubstitution");
257 } catch (com.sun.star.uno.Exception e) {
258 e.printStackTrace();
261 if (xPathSubst != null) {
262 return (XStringSubstitution) UnoRuntime.queryInterface(
263 XStringSubstitution.class, xPathSubst);
264 } else {
265 return null;