Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / ucb / _XContentProviderManager.java
blob7de56a9b1d350453b950bd6e3b13d48c5edf395e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.ucb;
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import lib.StatusException;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.lang.XServiceInfo;
36 import com.sun.star.ucb.ContentProviderInfo;
37 import com.sun.star.ucb.DuplicateProviderException;
38 import com.sun.star.ucb.XContentProvider;
39 import com.sun.star.ucb.XContentProviderManager;
40 import com.sun.star.uno.Exception;
41 import com.sun.star.uno.UnoRuntime;
43 /**
44 * Tests XContentProviderManager. The test registers two ContentProviders, calls
45 * queryXXX methods to verify results, and deregisters them.
47 * Testing <code>com.sun.star.ucb.XContentProviderManager</code>
48 * interface methods :
49 * <ul>
50 * <li><code> registerContentProvider()</code></li>
51 * <li><code> deregisterContentProvider()</code></li>
52 * <li><code> queryContentProviders()</code></li>
53 * <li><code> queryContentProvider()</code></li>
54 * </ul> <p>
55 * The test registers two ContentProviders, calls
56 * queryXXX methods to verify results, and deregisters them. <p>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * @see com.sun.star.ucb.XContentProviderManager
61 public class _XContentProviderManager extends MultiMethodTest {
62 /**
63 * Contains the tested object.
65 public XContentProviderManager oObj;
67 /**
68 * The test scheme name.
70 static final String myScheme = "test-scheme";
72 /**
73 * Any preexisting content provider. If it exists it will be hidden by
74 * <code>firstContentProvider</code>, registered with the same
75 * <code>myScheme</code>. Typically there is no preexisting content
76 * provider, unless the catch-all providers GnomeVFSContentProvider or
77 * GIOContentProvider is installed
79 XContentProvider preexistingContentProvider;
81 /**
82 * First content provider. It will be hidden by <code>contentProvider
83 * </code>, registered with the same <code>myScheme</code> to test
84 * the "hiding" behaviour.
86 XContentProvider firstContentProvider;
88 /**
89 * The main content provider.
91 XContentProvider contentProvider;
93 /**
94 * <code>ContentProvider</code>s information which are in the manager
95 * before registering the testing providers.
97 ContentProviderInfo[] initialProvidersInfo;
99 /**
100 * Creates two testing providers.
102 * @see #firstContentProvider
103 * @see #contentProvider
105 public void before() {
106 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
108 log.println("creating testing content providers");
109 try {
110 firstContentProvider = (XContentProvider)UnoRuntime.queryInterface(
111 XContentProvider.class, xMSF.createInstance(
112 "com.sun.star.ucb.FileContentProvider"));
114 contentProvider = (XContentProvider)UnoRuntime.queryInterface(
115 XContentProvider.class, xMSF.createInstance(
116 "com.sun.star.ucb.FileContentProvider"));
117 } catch (Exception e) {
118 log.println("Can't create content providers " + e.getMessage());
119 e.printStackTrace(log);
120 throw new StatusException("Unexpected exception", e);
125 * At the beginning call <code>queryContentProviders</code> method
127 * to have info about providers existing before new adding.
128 * It adds two testing contents providers, both for the same scheme.
129 * The second one is added two times: first, in non-replacing mode, to test
130 * <code>DuplicateProviderException</code>, and second, in replacing mode,
131 * to hide the first provider. <p>
133 * The evaluation of results are performed later, in
134 * <code>queryContentProvider()</code>.
136 * Has <b> OK </b> status if in the first provider is registered
137 * without exceptions, the second throws
138 * <code>DuplicateProviderException</code> in non-replacing mode,
139 * and no exceptions in replacing mode. <p>
141 * @see #_queryContentProvider
143 public void _registerContentProvider() {
144 // querying providfers info before inserting them, to verify results
145 initialProvidersInfo = oObj.queryContentProviders();
147 // GnomeVFSContentProvider or GIOContentProvider ?, typically null
148 preexistingContentProvider = oObj.queryContentProvider(myScheme);
150 log.println("registering the first provider");
151 try {
152 oObj.registerContentProvider(firstContentProvider, myScheme,false);
153 } catch (DuplicateProviderException e) {
154 log.println("Unexpected exception thrown " + e.getMessage());
155 e.printStackTrace(log);
156 throw new StatusException("Unexpected exception ", e);
159 log.println("registering the second provider in non-replacing mode");
160 try {
161 oObj.registerContentProvider(contentProvider, myScheme, false);
162 Status.failed("registerContentProvider(.., .., false)");
163 } catch (DuplicateProviderException e) {
164 log.println("DuplicateProviderException thrown - OK");
167 XContentProvider result;
169 log.println("registering the second provider in the replace mode");
170 try {
171 result = oObj.registerContentProvider(contentProvider, myScheme, true);
172 } catch (DuplicateProviderException e) {
173 log.println("Unexpected exception thrown " + e.getMessage());
174 e.printStackTrace(log);
175 throw new StatusException("Unexpected exception ", e);
178 // check the result is the first provider
179 tRes.tested("registerContentProvider()",
180 result.equals(firstContentProvider));
184 * It calls the method (after registering providers) and compares
185 * its result with the result before registering.
187 * Has <b> OK </b> status if the number of providers increases
188 * by one after registering custom provider.
190 * The following method tests are to be completed successfully before :
191 * <ul>
192 * <li> <code> registerContentProvider() </code> : to compare number
193 * of providers. </li>
194 * </ul>
195 * @see #_registerContentProvider
197 public void _queryContentProviders() {
198 executeMethod("registerContentProvider()");
200 ContentProviderInfo[] providersInfo = oObj.queryContentProviders();
201 // verifying that the number of providers increased by 1
202 tRes.tested("queryContentProviders()",
203 providersInfo.length == initialProvidersInfo.length + 1);
207 * It queries for added custom provider using its scheme
208 * and verifies its result with
209 * <code>queryContentProviders()</code> result and with
210 * custom provider created in <code>registerContentProvider()</code>.
211 * Also verifies <code>registerContentProvider()</code>. <p>
213 * Has <b>OK</b> status if the provider returned is found within
214 * all providers and is equal to provider created before.
216 * The following method tests are to be completed successfully before :
217 * <ul>
218 * <li> <code> registerContentProvider() </code> </li>
219 * </ul>
221 public void _queryContentProvider() {
222 executeMethod("registerContentProvider()");
224 XContentProvider result = oObj.queryContentProvider
225 ("http://www.sun.com");
227 log.println("finding queryContentProvider() result");
228 boolean found = false;
230 ContentProviderInfo[] providersInfo = oObj.queryContentProviders();
232 for (int i = 0; i < providersInfo.length; i++) {
233 if (result.equals(providersInfo[i].ContentProvider)
234 /*&& myScheme.equals(providersInfo[i].Scheme)*/) {
235 found = true;
236 break;
240 // boolean gotTheRightOne = util.ValueComparer.equalValue
241 // (result,contentProvider);
243 tRes.tested("queryContentProvider()", found);
245 // gotTheRightOne = result.equals(contentProvider);
250 * At first one provider is deregistered, after that provider
251 * is queried, the second provider must be returned for the
252 * specified scheme. Then the second provider is deregistered.
253 * Now <code>null</code> value must be retruned by the method
254 * <code>queryContentProvider</code> on the specified scheme. <p>
256 * Has <b>OK</b> status if in the first case the second provider
257 * remains registered, and after its removing no providers remain
258 * registered for the scheme specified.
260 * The following method tests are to be completed successfully before :
261 * <ul>
262 * <li> <code> registerContentProvider() </code> : two providers
263 * must be registered. </li>
264 * </ul>
265 * The following method tests are to be executed before :
266 * <ul>
267 * <li> <code> queryContentProvider() </code> : to run this test
268 * finally. </li>
269 * <li> <code> queryContentProviders() </code> : to run this test
270 * finally. </li>
271 * </ul>
273 public void _deregisterContentProvider() {
274 executeMethod("queryContentProvider()");
275 executeMethod("queryContentProviders()");
276 requiredMethod("registerContentProvider()");
278 log.println("deregistering the second provider");
279 oObj.deregisterContentProvider(contentProvider, myScheme);
281 XContentProvider res = oObj.queryContentProvider(myScheme);
283 log.println("deregistering the first provider");
284 oObj.deregisterContentProvider(firstContentProvider, myScheme);
286 res = oObj.queryContentProvider(myScheme);
288 // verifying that the original provider (typically none) is returned.
289 tRes.tested("deregisterContentProvider()", res == preexistingContentProvider);