bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / configuration / backend / _XBackend.java
blobc55c4579a918de1192b1789951dd3a629b8ed72f
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package ifc.configuration.backend;
20 import com.sun.star.configuration.backend.XBackend;
21 import com.sun.star.configuration.backend.XLayer;
22 import com.sun.star.configuration.backend.XUpdateHandler;
23 import com.sun.star.lang.XMultiServiceFactory;
24 import com.sun.star.uno.UnoRuntime;
25 import com.sun.star.util.XStringSubstitution;
27 import lib.MultiMethodTest;
29 import util.XLayerHandlerImpl;
32 public class _XBackend extends MultiMethodTest {
33 public XBackend oObj;
35 public void _getOwnUpdateHandler() {
36 boolean res = true;
38 String noUpdate = (String) tEnv.getObjRelation("noUpdate");
40 if (noUpdate != null) {
41 log.println(noUpdate);
42 tRes.tested("getOwnUpdateHandler()", res);
44 return;
47 try {
48 XUpdateHandler aHandler = oObj.getOwnUpdateHandler(
49 "org.openoffice.Office.Linguistic");
50 res &= (aHandler != null);
52 if (aHandler == null) {
53 log.println("\treturned Layer is NULL -- FAILED");
55 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
56 log.println("unexpected Exception " + e + " -- FAILED");
57 res = false;
58 } catch (com.sun.star.lang.IllegalArgumentException e) {
59 log.println("unexpected Exception " + e + " -- FAILED");
60 res = false;
61 } catch (com.sun.star.lang.NoSupportException e) {
62 log.println("unexpected Exception " + e + " -- FAILED");
63 res = false;
66 tRes.tested("getOwnUpdateHandler()", res);
69 public void _getUpdateHandler() {
70 boolean res = true;
72 String noUpdate = (String) tEnv.getObjRelation("noUpdate");
74 if (noUpdate != null) {
75 log.println(noUpdate);
76 tRes.tested("getUpdateHandler()", res);
78 return;
81 try {
82 oObj.getUpdateHandler(
83 "org.openoffice.Office.TypeDetection",
84 "illegal");
85 log.println("Exception expected -- FAILED");
86 res = false;
87 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
88 log.println("expected Exception -- OK");
89 } catch (com.sun.star.lang.IllegalArgumentException e) {
90 log.println("unexpected Exception -- FAILED");
91 res = false;
92 } catch (com.sun.star.lang.NoSupportException e) {
93 log.println("unexpected Exception " + e + " -- FAILED");
94 res = false;
97 try {
98 XStringSubstitution sts = createStringSubstitution(
99 tParam.getMSF());
100 String ent = sts.getSubstituteVariableValue("$(inst)") +
101 "/share/registry";
102 XUpdateHandler aHandler = oObj.getUpdateHandler(
103 "org.openoffice.Office.Jobs",
104 ent);
106 if (aHandler == null) {
107 log.println("\treturned Layer is NULL -- FAILED");
109 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
110 log.println("unexpected Exception -- FAILED");
111 res = false;
112 } catch (com.sun.star.lang.IllegalArgumentException e) {
113 log.println("unexpected Exception -- FAILED");
114 res = false;
115 } catch (com.sun.star.lang.NoSupportException e) {
116 log.println("unexpected Exception " + e + " -- FAILED");
117 res = false;
118 } catch (com.sun.star.container.NoSuchElementException e) {
119 log.println("unexpected Exception " + e + " -- FAILED");
120 res = false;
123 tRes.tested("getUpdateHandler()", res);
126 public void _listLayers() {
127 boolean res = true;
129 try {
130 XStringSubstitution sts = createStringSubstitution(
131 tParam.getMSF());
132 String ent = sts.getSubstituteVariableValue("$(inst)") +
133 "/share/registry";
134 XLayer[] Layers = oObj.listLayers(
135 "org.openoffice.Office.Linguistic", ent);
137 for (int i = 0; i < Layers.length; i++) {
138 log.println("Checking Layer " + i);
139 res &= checkLayer(Layers[i]);
141 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
142 log.println("unexpected Exception " + e + " -- FAILED");
143 res = false;
144 } catch (com.sun.star.lang.IllegalArgumentException e) {
145 log.println("unexpected Exception " + e + " -- FAILED");
146 res = false;
147 } catch (com.sun.star.container.NoSuchElementException e) {
148 log.println("unexpected Exception " + e + " -- FAILED");
149 res = false;
152 tRes.tested("listLayers()", res);
155 public void _listOwnLayers() {
156 boolean res = true;
158 try {
159 XLayer[] Layers = oObj.listOwnLayers(
160 "org.openoffice.Office.Common");
162 for (int i = 0; i < Layers.length; i++) {
163 log.println("Checking Layer " + i);
164 res &= checkLayer(Layers[i]);
166 if (Layers.length==0) {
167 System.out.println("No Layers found -- FAILED");
168 res &= false;
170 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
171 log.println("unexpected Exception " + e + " -- FAILED");
172 res = false;
173 } catch (com.sun.star.lang.IllegalArgumentException e) {
174 log.println("unexpected Exception " + e + " -- FAILED");
175 res = false;
178 tRes.tested("listOwnLayers()", res);
181 protected boolean checkLayer(XLayer aLayer) {
182 boolean res = false;
184 log.println("Checking for Exception in case of null argument");
186 try {
187 aLayer.readData(null);
188 } catch (com.sun.star.lang.NullPointerException e) {
189 log.println("Expected Exception -- OK");
190 res = true;
191 } catch (com.sun.star.lang.WrappedTargetException e) {
192 log.println("Unexpected Exception (" + e + ") -- FAILED");
193 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
194 log.println("Unexpected Exception (" + e + ") -- FAILED");
197 log.println("checking read data with own XLayerHandler implementation");
199 try {
200 XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
201 aLayer.readData(xLayerHandler);
203 String implCalled = xLayerHandler.getCalls();
204 log.println(implCalled);
206 int sl = implCalled.indexOf("startLayer");
208 if (sl < 0) {
209 log.println("startLayer wasn't called -- FAILED");
210 res &= false;
211 } else {
212 log.println("startLayer was called -- OK");
213 res &= true;
216 int el = implCalled.indexOf("endLayer");
218 if (el < 0) {
219 log.println("endLayer wasn't called -- FAILED");
220 res &= false;
221 } else {
222 log.println("endLayer was called -- OK");
223 res &= true;
225 } catch (com.sun.star.lang.NullPointerException e) {
226 log.println("Unexpected Exception (" + e + ") -- FAILED");
227 res &= false;
228 } catch (com.sun.star.lang.WrappedTargetException e) {
229 log.println("Unexpected Exception (" + e + ") -- FAILED");
230 res &= false;
231 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
232 log.println("Unexpected Exception (" + e + ") -- FAILED");
233 res &= false;
236 return res;
239 public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) {
240 Object xPathSubst = null;
242 try {
243 xPathSubst = xMSF.createInstance(
244 "com.sun.star.util.PathSubstitution");
245 } catch (com.sun.star.uno.Exception e) {
246 e.printStackTrace();
249 if (xPathSubst != null) {
250 return UnoRuntime.queryInterface(
251 XStringSubstitution.class, xPathSubst);
252 } else {
253 return null;