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 lib
.MultiMethodTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.ucb
.XContent
;
26 import com
.sun
.star
.ucb
.XContentIdentifier
;
27 import com
.sun
.star
.ucb
.XContentIdentifierFactory
;
28 import com
.sun
.star
.ucb
.XContentProvider
;
31 * Testing <code>com.sun.star.ucb.XContentProvider</code>
34 * <li><code> queryContent()</code></li>
35 * <li><code> compareContentIds()</code></li>
37 * This test needs the following object relations :
39 * <li> <code>'FACTORY'</code> (of type
40 * <code>com.sun.star.ucb.XContentIdentifierFactory</code>):
41 * a suitable factory which can produce content identifiers </li>
42 * <li> <code>'CONTENT1'</code> (<b>optional</b>) (of type <code>String</code>):
43 * name of the suitable content for provider tested. If relation
44 * is not specified the 'vnd.sun.star.help://' name will be used.</li>
45 * <li> <code>'CONTENT2'</code> (<b>optional</b>) (of type <code>String</code>):
46 * another name of the suitable content for provider tested. If relation
47 * is not specified the 'vnd.sun.star.writer://' name will be used.</li>
49 * Test is <b> NOT </b> multithread compilant. <p>
50 * @see com.sun.star.ucb.XContentProvider
52 public class _XContentProvider
extends MultiMethodTest
{
54 public static XContentProvider oObj
= null;
55 protected XContentIdentifierFactory CIF
= null ;
56 protected String content1
= "vnd.sun.star.help://" ;
57 protected String content2
= "vnd.sun.star.writer://" ;
60 * Retrieves object relations.
61 * @throws StatusException If one of relations not found.
63 public void before() {
64 CIF
= (XContentIdentifierFactory
) tEnv
.getObjRelation("FACTORY");
65 String tmp
= (String
) tEnv
.getObjRelation("CONTENT1") ;
66 if (tmp
!= null) content1
= tmp
;
67 tmp
= (String
) tEnv
.getObjRelation("CONTENT2") ;
68 if (tmp
!= null) content2
= tmp
;
70 if (CIF
== null) throw new StatusException(
71 Status
.failed("'FACTORY' relation is not found.")) ;
75 * Tries to query for some content suitable for this provider. <p>
76 * Has <b>OK</b> status if not null value is returned.
78 public void _queryContent() {
80 XContentIdentifierFactory CIF
= (XContentIdentifierFactory
)
81 tEnv
.getObjRelation("FACTORY");
82 String aURL
= content1
;
83 log
.println("Trying to query "+aURL
);
84 XContentIdentifier CI
= CIF
.createContentIdentifier(aURL
);
85 XContent aContent
= oObj
.queryContent(CI
);
87 Object nc
= tEnv
.getObjRelation("NoCONTENT");
89 res
= aContent
!= null;
91 tRes
.tested("queryContent()",res
);
92 } catch (com
.sun
.star
.ucb
.IllegalIdentifierException e
) {
93 log
.println("Exception while checking 'queryContent'");
94 e
.printStackTrace(log
);
95 tRes
.tested("queryContent()",false);
100 * Creates two different content identifiers. First two different
101 * identifiers compared, then two same identifiers. <p>
102 * Has <b>OK</b> status if in the first case <code>false</code>
103 * returned, and in the second - <code>true</code>.
105 public void _compareContentIds() {
106 XContentIdentifierFactory CIF
= (XContentIdentifierFactory
)
107 tEnv
.getObjRelation("FACTORY");
108 String aURL
= content1
;
109 XContentIdentifier CI
= CIF
.createContentIdentifier(aURL
);
111 XContentIdentifier CI2
= CIF
.createContentIdentifier(aURL
);
112 int compare
= oObj
.compareContentIds(CI
,CI2
);
113 boolean res
= (compare
!= 0);
115 log
.println("Didn't work with different IDs");
116 log
.println(compare
+" was returned");
118 compare
= oObj
.compareContentIds(CI
,CI
);
119 res
&= (compare
== 0);
121 log
.println("Didn't work with equal IDs");
122 log
.println(compare
+" was returned");
124 tRes
.tested("compareContentIds()",res
);