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 compliant. <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.
64 public void before() {
65 CIF
= (XContentIdentifierFactory
) tEnv
.getObjRelation("FACTORY");
66 String tmp
= (String
) tEnv
.getObjRelation("CONTENT1") ;
67 if (tmp
!= null) content1
= tmp
;
68 tmp
= (String
) tEnv
.getObjRelation("CONTENT2") ;
69 if (tmp
!= null) content2
= tmp
;
71 if (CIF
== null) throw new StatusException(
72 Status
.failed("'FACTORY' relation is not found.")) ;
76 * Tries to query for some content suitable for this provider. <p>
77 * Has <b>OK</b> status if not null value is returned.
79 public void _queryContent() {
81 XContentIdentifierFactory CIF
= (XContentIdentifierFactory
)
82 tEnv
.getObjRelation("FACTORY");
83 String aURL
= content1
;
84 log
.println("Trying to query "+aURL
);
85 XContentIdentifier CI
= CIF
.createContentIdentifier(aURL
);
86 XContent aContent
= oObj
.queryContent(CI
);
88 Object nc
= tEnv
.getObjRelation("NoCONTENT");
90 res
= aContent
!= null;
92 tRes
.tested("queryContent()",res
);
93 } catch (com
.sun
.star
.ucb
.IllegalIdentifierException e
) {
94 log
.println("Exception while checking 'queryContent'");
95 e
.printStackTrace(log
);
96 tRes
.tested("queryContent()",false);
101 * Creates two different content identifiers. First two different
102 * identifiers compared, then two same identifiers. <p>
103 * Has <b>OK</b> status if in the first case <code>false</code>
104 * returned, and in the second - <code>true</code>.
106 public void _compareContentIds() {
107 XContentIdentifierFactory CIF
= (XContentIdentifierFactory
)
108 tEnv
.getObjRelation("FACTORY");
109 String aURL
= content1
;
110 XContentIdentifier CI
= CIF
.createContentIdentifier(aURL
);
112 XContentIdentifier CI2
= CIF
.createContentIdentifier(aURL
);
113 int compare
= oObj
.compareContentIds(CI
,CI2
);
114 boolean res
= (compare
!= 0);
116 log
.println("Didn't work with different IDs");
117 log
.println(compare
+" was returned");
119 compare
= oObj
.compareContentIds(CI
,CI
);
120 res
&= (compare
== 0);
122 log
.println("Didn't work with equal IDs");
123 log
.println(compare
+" was returned");
125 tRes
.tested("compareContentIds()",res
);