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 .
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
.XCommandProcessor
;
28 import com
.sun
.star
.ucb
.XContent
;
29 import com
.sun
.star
.ucb
.XContentIdentifier
;
30 import com
.sun
.star
.ucb
.XContentIdentifierFactory
;
31 import com
.sun
.star
.ucb
.XContentProvider
;
32 import com
.sun
.star
.ucb
.XDynamicResultSet
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
35 import com
.sun
.star
.uno
.Type
;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import java
.io
.PrintWriter
;
39 import lib
.TestEnvironment
;
40 import lib
.TestParameters
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::ucb::XCachedDynamicResultSetStubFactory</code></li>
49 * This object test <b> is NOT </b> designed to be run in several
50 * threads concurrently.
51 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
52 * @see com.sun.star.ucb.CachedDynamicResultSetStubFactory
53 * @see ifc.ucb._XCachedDynamicResultSetStubFactory
55 public class CachedDynamicResultSetStubFactory
extends TestCase
{
58 * Creating a TestEnvironment for the interfaces to be tested.
59 * Creates an instance of the service
60 * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p>
61 * Object relations created :
63 * <li> <code>'DynamicResultSet'</code> for
64 * {@link ifc.ucb._XCachedDynamicResultSetStubFactory} : the destination
65 * interface requires as its parameter an instance of
66 * <code>DynamicResultSet</code> service. It is created
67 * using <code>UniversalContentBroker</code> and querying it for
68 * <code>PackageContent</code> which represents JAR file mentioned
69 * above. Then the dynamic list of file contents (entries) is retrieved.
74 public TestEnvironment
createTestEnvironment( TestParameters Param
,
77 XMultiServiceFactory xMSF
= Param
.getMSF();
78 Object oInterface
= xMSF
.createInstance
79 ( "com.sun.star.ucb.CachedDynamicResultSetStubFactory" );
80 XInterface oObj
= (XInterface
) oInterface
;
82 TestEnvironment tEnv
= new TestEnvironment( oObj
);
84 // creating relation for XCachedDynamicResultSetStubFactory
85 XDynamicResultSet dynResSet
= null ;
86 Object oUCB
= xMSF
.createInstanceWithArguments
87 ("com.sun.star.ucb.UniversalContentBroker",
90 XContentIdentifierFactory ciFac
= UnoRuntime
.queryInterface(XContentIdentifierFactory
.class, oUCB
) ;
92 String url
= util
.utils
.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
93 StringBuilder escUrl
= new StringBuilder();
95 // In base URL of a JAR file in content URL all directory
96 // separators ('/') must be replaced with escape symbol '%2F'.
97 int idx
= url
.indexOf("/") ;
100 escUrl
.append(url
.substring(lastIdx
+ 1, idx
)).append("%2F");
102 idx
= url
.indexOf("/", idx
+ 1) ;
104 escUrl
.append(url
.substring(lastIdx
+ 1));
105 String cntUrl
= "vnd.sun.star.pkg://" + escUrl
.toString() + "/" ;
107 XContentIdentifier CI
= ciFac
.createContentIdentifier(cntUrl
) ;
109 XContentProvider cntProv
= UnoRuntime
.queryInterface(XContentProvider
.class, oUCB
) ;
111 XContent cnt
= cntProv
.queryContent(CI
) ;
113 XCommandProcessor cmdProc
= UnoRuntime
.queryInterface(XCommandProcessor
.class, cnt
) ;
115 Property prop
= new Property() ;
116 prop
.Name
= "Title" ;
118 Command cmd
= new Command("open", -1, new OpenCommandArgument2
119 (OpenMode
.ALL
, 10000, null, new Property
[] {prop
},
120 new NumberedSortingInfo
[0])) ;
122 dynResSet
= (XDynamicResultSet
)
123 AnyConverter
.toObject(new Type(XDynamicResultSet
.class),
124 cmdProc
.execute(cmd
, 0, null));
126 tEnv
.addObjRelation("DynamicResultSet", dynResSet
) ;
129 } // finish method getTestEnvironment