svx: prefix members of SdrUnoObj
[LibreOffice.git] / qadevOOo / tests / java / mod / _cached / CachedDynamicResultSetFactory.java
blob87d13d6d36c4fa509c3ddb7f0a4dc97e9298d849
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.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.ucb.CachedDynamicResultSetFactory</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::ucb::XCachedDynamicResultSetFactory</code></li>
49 * </ul> <p>
50 * This object test <b> is NOT </b> designed to be run in several
51 * threads concurrently.
52 * @see com.sun.star.ucb.XCachedDynamicResultSetFactory
53 * @see com.sun.star.ucb.CachedDynamicResultSetFactory
54 * @see ifc.ucb._XCachedDynamicResultSetFactory
56 public class CachedDynamicResultSetFactory extends TestCase {
58 /**
59 * Creating a TestEnvironment for the interfaces to be tested.
60 * Creates an instance of the service
61 * <code>com.sun.star.ucb.CachedDynamicResultSetFactory</code>. <p>
62 * Object relations created :
63 * <ul>
64 * <li> <code>'CachedDynamicResultSetStub'</code> for
65 * {@link ifc.ucb._XCachedDynamicResultSetFactory} : the destination
66 * interface requires as its parameter an instance of
67 * <code>CachedDynamicResultSetStub</code> service. It is created
68 * using <code>UniversalContentBroker</code> and querying it for
69 * <code>PackageContent</code> which represents JAR file mentioned
70 * above. Then the dynamic list of file contents (entries) is retrieved.
71 * Using <code>CachedDynamicResultSetStubFactory</code> service a stub of
72 * Cached result set is created which is relation required.
73 * </li>
74 * </ul>
76 @Override
77 public TestEnvironment createTestEnvironment( TestParameters Param,
78 PrintWriter log )
79 throws Exception {
80 XMultiServiceFactory xMSF = Param.getMSF();
81 Object oInterface = xMSF.createInstance
82 ( "com.sun.star.ucb.CachedDynamicResultSetFactory" );
83 XInterface oObj = (XInterface) oInterface;
85 TestEnvironment tEnv = new TestEnvironment( oObj );
87 // creating relation for XCachedDynamicResultSetFactory
88 XDynamicResultSet resSetStub = null ;
89 Object oUCB = xMSF.createInstanceWithArguments
90 ("com.sun.star.ucb.UniversalContentBroker",
91 new Object[0]) ;
93 XContentIdentifierFactory ciFac = UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ;
95 String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
96 StringBuilder escUrl = new StringBuilder();
98 // In base URL of a JAR file in content URL all directory
99 // separators ('/') must be replaced with escape symbol '%2F'.
100 int idx = url.indexOf("/") ;
101 int lastIdx = -1 ;
102 while (idx >= 0) {
103 escUrl.append(url.substring(lastIdx + 1, idx)).append("%2F");
104 lastIdx = idx ;
105 idx = url.indexOf("/", idx + 1) ;
107 escUrl.append(url.substring(lastIdx + 1));
108 String cntUrl = "vnd.sun.star.pkg://" + escUrl.toString() + "/" ;
110 XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ;
112 XContentProvider cntProv = UnoRuntime.queryInterface(XContentProvider.class, oUCB) ;
114 XContent cnt = cntProv.queryContent(CI) ;
116 XCommandProcessor cmdProc = UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ;
118 Property prop = new Property() ;
119 prop.Name = "Title" ;
121 Command cmd = new Command("open", -1, new OpenCommandArgument2
122 (OpenMode.ALL, 10000, null, new Property[] {prop},
123 new NumberedSortingInfo[0])) ;
125 XDynamicResultSet dynResSet = (XDynamicResultSet)
126 AnyConverter.toObject(new Type(XDynamicResultSet.class),
127 cmdProc.execute(cmd, 0, null));
129 Object oStubFactory = xMSF.createInstance
130 ("com.sun.star.ucb.CachedDynamicResultSetStubFactory") ;
132 XCachedDynamicResultSetStubFactory xStubFactory =
133 UnoRuntime.queryInterface
134 (XCachedDynamicResultSetStubFactory.class, oStubFactory) ;
136 resSetStub =
137 xStubFactory.createCachedDynamicResultSetStub(dynResSet) ;
139 tEnv.addObjRelation("CachedDynamicResultSetStub", resSetStub) ;
141 return tEnv;
142 } // finish method getTestEnvironment