bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _cached / CachedDynamicResultSetFactory.java
blob2f3d93cf025225c100ee3c72a3a044a482805cee
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 mod._cached;
21 import com.sun.star.beans.Property;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.ucb.Command;
24 import com.sun.star.ucb.NumberedSortingInfo;
25 import com.sun.star.ucb.OpenCommandArgument2;
26 import com.sun.star.ucb.OpenMode;
27 import com.sun.star.ucb.XCachedDynamicResultSetStubFactory;
28 import com.sun.star.ucb.XCommandProcessor;
29 import com.sun.star.ucb.XContent;
30 import com.sun.star.ucb.XContentIdentifier;
31 import com.sun.star.ucb.XContentIdentifierFactory;
32 import com.sun.star.ucb.XContentProvider;
33 import com.sun.star.ucb.XDynamicResultSet;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.AnyConverter;
38 import java.io.PrintWriter;
39 import lib.StatusException;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.ucb.CachedDynamicResultSetFactory</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::ucb::XCachedDynamicResultSetFactory</code></li>
50 * </ul> <p>
51 * This object test <b> is NOT </b> designed to be run in several
52 * threads concurently.
53 * @see com.sun.star.ucb.XCachedDynamicResultSetFactory
54 * @see com.sun.star.ucb.CachedDynamicResultSetFactory
55 * @see ifc.ucb._XCachedDynamicResultSetFactory
57 public class CachedDynamicResultSetFactory extends TestCase {
59 /**
60 * Creating a TestEnvironment for the interfaces to be tested.
61 * Creates an instance of the service
62 * <code>com.sun.star.ucb.CachedDynamicResultSetFactory</code>. <p>
63 * Object relations created :
64 * <ul>
65 * <li> <code>'CachedDynamicResultSetStub'</code> for
66 * {@link ifc.ucb._XCachedDynamicResultSetFactory} : the destination
67 * interface requires as its parameter an instance of
68 * <code>CachedDynamicResultSetStub</code> service. It is created
69 * using <code>UniversalContentBroker</code> and queriing it for
70 * <code>PackageContent</code> which represents JAR file mentioned
71 * above. Then the dynamic list of file contents (entries) is retrieved.
72 * Using <code>CachedDynamicResultSetStubFactory</code> service a stub of
73 * Cached result set is created which is relation required.
74 * </li>
75 * </ul>
77 public TestEnvironment createTestEnvironment( TestParameters Param,
78 PrintWriter log )
79 throws StatusException {
80 XInterface oObj = null;
81 Object oInterface = null;
82 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
83 try {
84 oInterface = xMSF.createInstance
85 ( "com.sun.star.ucb.CachedDynamicResultSetFactory" );
87 // adding one child container
89 catch( com.sun.star.uno.Exception e ) {
90 log.println("Can't create an object." );
91 throw new StatusException( "Can't create an object", e );
94 oObj = (XInterface) oInterface;
96 TestEnvironment tEnv = new TestEnvironment( oObj );
98 // creating relation for XCachedDynamicResultSetFactory
99 XDynamicResultSet resSetStub = null ;
100 try {
101 Object oUCB = xMSF.createInstanceWithArguments
102 ("com.sun.star.ucb.UniversalContentBroker",
103 new Object[0]) ;
105 XContentIdentifierFactory ciFac = UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ;
107 String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
108 String escUrl = "" ;
110 // In base URL of a JAR file in content URL all directory
111 // separators ('/') must be replaced with escape symbol '%2F'.
112 int idx = url.indexOf("/") ;
113 int lastIdx = -1 ;
114 while (idx >= 0) {
115 escUrl += url.substring(lastIdx + 1, idx) + "%2F" ;
116 lastIdx = idx ;
117 idx = url.indexOf("/", idx + 1) ;
119 escUrl += url.substring(lastIdx + 1) ;
120 String cntUrl = "vnd.sun.star.pkg://" + escUrl + "/" ;
122 XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ;
124 XContentProvider cntProv = UnoRuntime.queryInterface(XContentProvider.class, oUCB) ;
126 XContent cnt = cntProv.queryContent(CI) ;
128 XCommandProcessor cmdProc = UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ;
130 Property prop = new Property() ;
131 prop.Name = "Title" ;
133 Command cmd = new Command("open", -1, new OpenCommandArgument2
134 (OpenMode.ALL, 10000, null, new Property[] {prop},
135 new NumberedSortingInfo[0])) ;
137 XDynamicResultSet dynResSet = null;
138 try {
139 dynResSet = (XDynamicResultSet)
140 AnyConverter.toObject(new Type(XDynamicResultSet.class),
141 cmdProc.execute(cmd, 0, null));
142 } catch (com.sun.star.lang.IllegalArgumentException iae) {
143 throw new StatusException("Couldn't convert Any ",iae);
146 Object oStubFactory = xMSF.createInstance
147 ("com.sun.star.ucb.CachedDynamicResultSetStubFactory") ;
149 XCachedDynamicResultSetStubFactory xStubFactory =
150 UnoRuntime.queryInterface
151 (XCachedDynamicResultSetStubFactory.class, oStubFactory) ;
153 resSetStub =
154 xStubFactory.createCachedDynamicResultSetStub(dynResSet) ;
156 } catch (com.sun.star.uno.Exception e) {
157 log.println("Can't create relation." );
158 e.printStackTrace(log) ;
159 throw new StatusException( "Can't create relation", e );
162 tEnv.addObjRelation("CachedDynamicResultSetStub", resSetStub) ;
164 return tEnv;
165 } // finish method getTestEnvironment