Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / ucb / _XContentProviderManager.java
blobe7cf505cd0e787d86fb5a40cb0844199bb9964e6
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: _XContentProviderManager.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.ucb;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.ucb.ContentProviderInfo;
39 import com.sun.star.ucb.DuplicateProviderException;
40 import com.sun.star.ucb.XContentProvider;
41 import com.sun.star.ucb.XContentProviderManager;
42 import com.sun.star.uno.Exception;
43 import com.sun.star.uno.UnoRuntime;
45 /**
46 * Tests XContentProviderManager. The test registers two ContentProviders, calls
47 * queryXXX methods to verify results, and deregisters them.
49 * Testing <code>com.sun.star.ucb.XContentProviderManager</code>
50 * interface methods :
51 * <ul>
52 * <li><code> registerContentProvider()</code></li>
53 * <li><code> deregisterContentProvider()</code></li>
54 * <li><code> queryContentProviders()</code></li>
55 * <li><code> queryContentProvider()</code></li>
56 * </ul> <p>
57 * The test registers two ContentProviders, calls
58 * queryXXX methods to verify results, and deregisters them. <p>
60 * Test is <b> NOT </b> multithread compilant. <p>
61 * @see com.sun.star.ucb.XContentProviderManager
63 public class _XContentProviderManager extends MultiMethodTest {
64 /**
65 * Contains the tested object.
67 public XContentProviderManager oObj;
69 /**
70 * The test scheme name.
72 static final String myScheme = "test-scheme";
74 /**
75 * First content provider. It will be hidden by <code>contentProvider
76 * </code>, registred with the same <code>myScheme</code> to test
77 * the "hiding" behaviour.
79 XContentProvider firstContentProvider;
81 /**
82 * The main content provider.
84 XContentProvider contentProvider;
86 /**
87 * <code>ContentProvider</code>s information which are in the manager
88 * before registering the testing providers.
90 ContentProviderInfo[] initialProvidersInfo;
92 /**
93 * Creates two testing providers.
95 * @see #firstContentProvider
96 * @see #contentProvider
98 public void before() {
99 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
101 log.println("creating testing content providers");
102 try {
103 firstContentProvider = (XContentProvider)UnoRuntime.queryInterface(
104 XContentProvider.class, xMSF.createInstance(
105 "com.sun.star.ucb.FileContentProvider"));
107 contentProvider = (XContentProvider)UnoRuntime.queryInterface(
108 XContentProvider.class, xMSF.createInstance(
109 "com.sun.star.ucb.FileContentProvider"));
110 } catch (Exception e) {
111 log.println("Can't create content providers " + e.getMessage());
112 e.printStackTrace(log);
113 throw new StatusException("Unexpected exception", e);
118 * At the beginning call <code>queryContentProviders</code> method
120 * to have info about providers existing before new adding.
121 * It adds two testing contents providers, both for the same scheme.
122 * The second one is added two times: first, in non-replacing mode, to test
123 * <code>DuplicateProviderException</code>, and second, in replacing mode,
124 * to hide the first provider. <p>
126 * The evaluation of results are performed later, in
127 * <code>queryContentProvider()</code>.
129 * Has <b> OK </b> status if in the first provider is registered
130 * without exceptions, the second throws
131 * <code>DuplicateProviderException</code> in non-replacing mode,
132 * and no exceptions in replacing mode. <p>
134 * @see #_queryContentProvider
136 public void _registerContentProvider() {
137 // querying providfers info before inserting them, to verify results
138 initialProvidersInfo = oObj.queryContentProviders();
140 log.println("registering the first provider");
141 try {
142 oObj.registerContentProvider(firstContentProvider, myScheme,false);
143 } catch (DuplicateProviderException e) {
144 log.println("Unexpected exception thrown " + e.getMessage());
145 e.printStackTrace(log);
146 throw new StatusException("Unexpected exception ", e);
149 log.println("registering the second provider in non-replacing mode");
150 try {
151 oObj.registerContentProvider(contentProvider, myScheme, false);
152 Status.failed("registerContentProvider(.., .., false)");
153 } catch (DuplicateProviderException e) {
154 log.println("DuplicateProviderException thrown - OK");
157 XContentProvider result;
159 log.println("registering the second provider in the replace mode");
160 try {
161 result = oObj.registerContentProvider(contentProvider, myScheme, true);
162 } catch (DuplicateProviderException e) {
163 log.println("Unexpected exception thrown " + e.getMessage());
164 e.printStackTrace(log);
165 throw new StatusException("Unexpected exception ", e);
168 // check the result is the first provider
169 tRes.tested("registerContentProvider()",
170 result.equals(firstContentProvider));
174 * It calls the method (after registering providers) and compares
175 * its result with the result before registering.
177 * Has <b> OK </b> status if the number of providers increases
178 * by one after registering custom provider.
180 * The following method tests are to be completed successfully before :
181 * <ul>
182 * <li> <code> registerContentProvider() </code> : to compare number
183 * of providers. </li>
184 * </ul>
185 * @see #_registerContentProvider
187 public void _queryContentProviders() {
188 executeMethod("registerContentProvider()");
190 ContentProviderInfo[] providersInfo = oObj.queryContentProviders();
191 // verifying that the number of providers increased by 1
192 tRes.tested("queryContentProviders()",
193 providersInfo.length == initialProvidersInfo.length + 1);
197 * It queries for added custom provider using its scheme
198 * and verifies its result with
199 * <code>queryContentProviders()</code> result and with
200 * custom provider created in <code>registerContentProvider()</code>.
201 * Also verifies <code>registerContentProvider()</code>. <p>
203 * Has <b>OK</b> status if the provider returned is found within
204 * all providers and is equal to provider created before.
206 * The following method tests are to be completed successfully before :
207 * <ul>
208 * <li> <code> registerContentProvider() </code> </li>
209 * </ul>
211 public void _queryContentProvider() {
212 executeMethod("registerContentProvider()");
214 XContentProvider result = oObj.queryContentProvider
215 ("http://www.sun.com");
217 log.println("finding queryContentProvider() result");
218 boolean found = false;
220 ContentProviderInfo[] providersInfo = oObj.queryContentProviders();
222 for (int i = 0; i < providersInfo.length; i++) {
223 if (result.equals(providersInfo[i].ContentProvider)
224 /*&& myScheme.equals(providersInfo[i].Scheme)*/) {
225 found = true;
226 break;
230 // boolean gotTheRightOne = util.ValueComparer.equalValue
231 // (result,contentProvider);
233 tRes.tested("queryContentProvider()", found);
235 // gotTheRightOne = result.equals(contentProvider);
240 * At first one provider is deregistered, after that provider
241 * is queried, the second provider must be returned for the
242 * specified scheme. Then the second provider is deregistered.
243 * Now <code>null</code> value must be retruned by the method
244 * <code>queryContentProvider</code> on the specified scheme. <p>
246 * Has <b>OK</b> status if in the first case the second provider
247 * remains registered, and after its removing no providers remain
248 * registered for the scheme specified.
250 * The following method tests are to be completed successfully before :
251 * <ul>
252 * <li> <code> registerContentProvider() </code> : two providers
253 * must be registered. </li>
254 * </ul>
255 * The following method tests are to be executed before :
256 * <ul>
257 * <li> <code> queryContentProvider() </code> : to run this test
258 * finally. </li>
259 * <li> <code> queryContentProviders() </code> : to run this test
260 * finally. </li>
261 * </ul>
263 public void _deregisterContentProvider() {
264 executeMethod("queryContentProvider()");
265 executeMethod("queryContentProviders()");
266 requiredMethod("registerContentProvider()");
268 log.println("deregistering the second provider");
269 oObj.deregisterContentProvider(contentProvider, myScheme);
271 XContentProvider res = oObj.queryContentProvider(myScheme);
273 log.println("deregistering the first provider");
274 oObj.deregisterContentProvider(firstContentProvider, myScheme);
276 res = oObj.queryContentProvider(myScheme);
278 // verifying that no provider is returned
279 tRes.tested("deregisterContentProvider()", res == null);