tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / ucb / _XContentProviderManager.java
blob957901775e510f5300b43eb77502f6da7ea8d2f7
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 .
19 package ifc.ucb;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.ucb.ContentProviderInfo;
27 import com.sun.star.ucb.DuplicateProviderException;
28 import com.sun.star.ucb.XContentProvider;
29 import com.sun.star.ucb.XContentProviderManager;
30 import com.sun.star.uno.Exception;
31 import com.sun.star.uno.UnoRuntime;
33 /**
34 * Tests XContentProviderManager. The test registers two ContentProviders, calls
35 * queryXXX methods to verify results, and deregisters them.
37 * Testing <code>com.sun.star.ucb.XContentProviderManager</code>
38 * interface methods :
39 * <ul>
40 * <li><code> registerContentProvider()</code></li>
41 * <li><code> deregisterContentProvider()</code></li>
42 * <li><code> queryContentProviders()</code></li>
43 * <li><code> queryContentProvider()</code></li>
44 * </ul> <p>
45 * The test registers two ContentProviders, calls
46 * queryXXX methods to verify results, and deregisters them. <p>
48 * Test is <b> NOT </b> multithread compliant. <p>
49 * @see com.sun.star.ucb.XContentProviderManager
51 public class _XContentProviderManager extends MultiMethodTest {
52 /**
53 * Contains the tested object.
55 public XContentProviderManager oObj;
57 /**
58 * The test scheme name.
60 static final String myScheme = "test-scheme";
62 /**
63 * Any preexisting content provider. If it exists it will be hidden by
64 * <code>firstContentProvider</code>, registered with the same
65 * <code>myScheme</code>. Typically there is no preexisting content
66 * provider, unless the catch-all providers GnomeVFSContentProvider or
67 * GIOContentProvider is installed
69 XContentProvider preexistingContentProvider;
71 /**
72 * First content provider. It will be hidden by <code>contentProvider
73 * </code>, registered with the same <code>myScheme</code> to test
74 * the "hiding" behaviour.
76 XContentProvider firstContentProvider;
78 /**
79 * The main content provider.
81 XContentProvider contentProvider;
83 /**
84 * <code>ContentProvider</code>s information which are in the manager
85 * before registering the testing providers.
87 ContentProviderInfo[] initialProvidersInfo;
89 /**
90 * Creates two testing providers.
92 * @see #firstContentProvider
93 * @see #contentProvider
95 @Override
96 public void before() {
97 XMultiServiceFactory xMSF = tParam.getMSF();
99 log.println("creating testing content providers");
100 try {
101 firstContentProvider = UnoRuntime.queryInterface(
102 XContentProvider.class, xMSF.createInstance(
103 "com.sun.star.ucb.FileContentProvider"));
105 contentProvider = UnoRuntime.queryInterface(
106 XContentProvider.class, xMSF.createInstance(
107 "com.sun.star.ucb.FileContentProvider"));
108 } catch (Exception e) {
109 log.println("Can't create content providers " + e.getMessage());
110 e.printStackTrace(log);
111 throw new StatusException("Unexpected exception", e);
116 * At the beginning call <code>queryContentProviders</code> method
118 * to have info about providers existing before new adding.
119 * It adds two testing contents providers, both for the same scheme.
120 * The second one is added two times: first, in non-replacing mode, to test
121 * <code>DuplicateProviderException</code>, and second, in replacing mode,
122 * to hide the first provider. <p>
124 * The evaluation of results are performed later, in
125 * <code>queryContentProvider()</code>.
127 * Has <b> OK </b> status if in the first provider is registered
128 * without exceptions, the second throws
129 * <code>DuplicateProviderException</code> in non-replacing mode,
130 * and no exceptions in replacing mode. <p>
132 * @see #_queryContentProvider
134 public void _registerContentProvider() {
135 // querying providers info before inserting them, to verify results
136 initialProvidersInfo = oObj.queryContentProviders();
138 // GnomeVFSContentProvider or GIOContentProvider ?, typically null
139 preexistingContentProvider = oObj.queryContentProvider(myScheme);
141 log.println("registering the first provider");
142 try {
143 oObj.registerContentProvider(firstContentProvider, myScheme,false);
144 } catch (DuplicateProviderException e) {
145 log.println("Unexpected exception thrown " + e.getMessage());
146 e.printStackTrace(log);
147 throw new StatusException("Unexpected exception ", e);
150 log.println("registering the second provider in non-replacing mode");
151 try {
152 oObj.registerContentProvider(contentProvider, myScheme, false);
153 throw new StatusException(Status.failed("registerContentProvider(.., .., false)"));
154 } catch (DuplicateProviderException e) {
155 log.println("DuplicateProviderException thrown - OK");
158 XContentProvider result;
160 log.println("registering the second provider in the replace mode");
161 try {
162 result = oObj.registerContentProvider(contentProvider, myScheme, true);
163 } catch (DuplicateProviderException e) {
164 log.println("Unexpected exception thrown " + e.getMessage());
165 e.printStackTrace(log);
166 throw new StatusException("Unexpected exception ", e);
169 // check the result is the first provider
170 tRes.tested("registerContentProvider()",
171 result.equals(firstContentProvider));
175 * It calls the method (after registering providers) and compares
176 * its result with the result before registering.
178 * Has <b> OK </b> status if the number of providers increases
179 * by one after registering custom provider.
181 * The following method tests are to be completed successfully before :
182 * <ul>
183 * <li> <code> registerContentProvider() </code> : to compare number
184 * of providers. </li>
185 * </ul>
186 * @see #_registerContentProvider
188 public void _queryContentProviders() {
189 executeMethod("registerContentProvider()");
191 ContentProviderInfo[] providersInfo = oObj.queryContentProviders();
192 // verifying that the number of providers increased by 1
193 tRes.tested("queryContentProviders()",
194 providersInfo.length == initialProvidersInfo.length + 1);
198 * It queries for added custom provider using its scheme
199 * and verifies its result with
200 * <code>queryContentProviders()</code> result and with
201 * custom provider created in <code>registerContentProvider()</code>.
202 * Also verifies <code>registerContentProvider()</code>. <p>
204 * Has <b>OK</b> status if the provider returned is found within
205 * all providers and is equal to provider created before.
207 * The following method tests are to be completed successfully before :
208 * <ul>
209 * <li> <code> registerContentProvider() </code> </li>
210 * </ul>
212 public void _queryContentProvider() {
213 executeMethod("registerContentProvider()");
215 XContentProvider result = oObj.queryContentProvider
216 ("http://www.sun.com");
218 log.println("finding queryContentProvider() result");
219 boolean found = false;
221 ContentProviderInfo[] providersInfo = oObj.queryContentProviders();
223 for (int i = 0; i < providersInfo.length; i++) {
224 if (result.equals(providersInfo[i].ContentProvider)) {
225 found = true;
226 break;
230 tRes.tested("queryContentProvider()", found);
234 * At first one provider is deregistered, after that provider
235 * is queried, the second provider must be returned for the
236 * specified scheme. Then the second provider is deregistered.
237 * Now <code>null</code> value must be returned by the method
238 * <code>queryContentProvider</code> on the specified scheme. <p>
240 * Has <b>OK</b> status if in the first case the second provider
241 * remains registered, and after its removing no providers remain
242 * registered for the scheme specified.
244 * The following method tests are to be completed successfully before :
245 * <ul>
246 * <li> <code> registerContentProvider() </code> : two providers
247 * must be registered. </li>
248 * </ul>
249 * The following method tests are to be executed before :
250 * <ul>
251 * <li> <code> queryContentProvider() </code> : to run this test
252 * finally. </li>
253 * <li> <code> queryContentProviders() </code> : to run this test
254 * finally. </li>
255 * </ul>
257 public void _deregisterContentProvider() {
258 executeMethod("queryContentProvider()");
259 executeMethod("queryContentProviders()");
260 requiredMethod("registerContentProvider()");
262 log.println("deregistering the second provider");
263 oObj.deregisterContentProvider(contentProvider, myScheme);
265 XContentProvider res = oObj.queryContentProvider(myScheme);
267 log.println("deregistering the first provider");
268 oObj.deregisterContentProvider(firstContentProvider, myScheme);
270 res = oObj.queryContentProvider(myScheme);
272 // verifying that the original provider (typically none) is returned.
273 tRes.tested("deregisterContentProvider()", res == preexistingContentProvider);