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
.sdbc
.XResultSet
;
24 import com
.sun
.star
.ucb
.Command
;
25 import com
.sun
.star
.ucb
.NumberedSortingInfo
;
26 import com
.sun
.star
.ucb
.OpenCommandArgument2
;
27 import com
.sun
.star
.ucb
.OpenMode
;
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
.ucb
.XSortedDynamicResultSetFactory
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import lib
.MultiMethodTest
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
42 * Testing <code>com.sun.star.ucb.XSortedDynamicResultSetFactory</code>
45 * <li><code> createSortedDynamicResultSet()</code></li>
47 * The following predefined files needed to complete the test:
49 * <li> <code>solibrary.jar</code> : is used to retrieve
50 * content of its root directory.</li>
52 * Test is <b> NOT </b> multithread compliant. <p>
53 * @see com.sun.star.ucb.XSortedDynamicResultSetFactory
55 public class _XSortedDynamicResultSetFactory
extends MultiMethodTest
{
58 * Contains the tested object.
60 public XSortedDynamicResultSetFactory oObj
;
63 * Creates sorted dynamic result set from result set. For this
64 * a dynamic result set is to be created. It is created by
65 * retrieving content list from JAR archive.
66 * Has <b>OK</b> status if numbers of rows are equal and they are
67 * greater than 0 (because JAR file contains at least one entry).
69 public void _createSortedDynamicResultSet() {
70 boolean result
= true ;
72 XMultiServiceFactory xMSF
= tParam
.getMSF();
73 XDynamicResultSet dynResSet
= null ;
75 Object oUCB
= xMSF
.createInstanceWithArguments
76 ("com.sun.star.ucb.UniversalContentBroker",
79 XContentIdentifierFactory ciFac
= UnoRuntime
.queryInterface
80 (XContentIdentifierFactory
.class,oUCB
) ;
82 String url
= util
.utils
.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
83 StringBuilder escUrl
= new StringBuilder();
85 // In base URL of a JAR file in content URL all directory
86 // separators ('/') must be replaced with escape symbol '%2F'.
87 int idx
= url
.indexOf("/") ;
90 escUrl
.append(url
.substring(lastIdx
+ 1, idx
)).append("%2F");
92 idx
= url
.indexOf("/", idx
+ 1) ;
94 escUrl
.append(url
.substring(lastIdx
+ 1));
95 String cntUrl
= "vnd.sun.star.pkg://" + escUrl
.toString() + "/" ;
97 XContentIdentifier CI
= ciFac
.createContentIdentifier(cntUrl
) ;
99 XContentProvider cntProv
= UnoRuntime
.queryInterface(XContentProvider
.class, oUCB
) ;
101 XContent cnt
= cntProv
.queryContent(CI
) ;
103 XCommandProcessor cmdProc
= UnoRuntime
.queryInterface(XCommandProcessor
.class, cnt
) ;
105 Property prop
= new Property() ;
106 prop
.Name
= "Title" ;
108 Command cmd
= new Command("open", -1, new OpenCommandArgument2
109 (OpenMode
.ALL
, 10000, null, new Property
[] {prop
},
110 new NumberedSortingInfo
[0])) ;
112 dynResSet
= (XDynamicResultSet
) AnyConverter
.toObject(
113 new Type(XDynamicResultSet
.class),cmdProc
.execute(cmd
, 0, null));
114 } catch (com
.sun
.star
.uno
.Exception e
) {
115 e
.printStackTrace(log
);
118 XDynamicResultSet sortedSet
= oObj
.createSortedDynamicResultSet
119 (dynResSet
, new NumberedSortingInfo
[0], null) ;
122 if (sortedSet
!= null) {
123 XResultSet set
= null ;
125 set
= sortedSet
.getStaticResultSet() ;
126 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
127 e
.printStackTrace(log
);
132 rowCount
= set
.getRow();
133 log
.println("Number of rows in result set: " + rowCount
);
134 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
135 log
.println("Exception occurred while accessing "+
136 "sorted result set :");
137 e
.printStackTrace(log
);
140 log
.println("Null returned !!!");
144 result
&= rowCount
> 1 ;
146 tRes
.tested("createSortedDynamicResultSet()", result
) ;