1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import lib
.StatusException
;
34 import com
.sun
.star
.ucb
.XContent
;
35 import com
.sun
.star
.ucb
.XContentIdentifier
;
36 import com
.sun
.star
.ucb
.XContentIdentifierFactory
;
37 import com
.sun
.star
.ucb
.XContentProvider
;
40 * Testing <code>com.sun.star.ucb.XContentProvider</code>
43 * <li><code> queryContent()</code></li>
44 * <li><code> compareContentIds()</code></li>
46 * This test needs the following object relations :
48 * <li> <code>'FACTORY'</code> (of type
49 * <code>com.sun.star.ucb.XContentIdentifierFactory</code>):
50 * a suitable factory which can produce content identifiers </li>
51 * <li> <code>'CONTENT1'</code> (<b>optional</b>) (of type <code>String</code>):
52 * name of the suitable content for provider tested. If relation
53 * is not specified the 'vnd.sun.star.help://' name will be used.</li>
54 * <li> <code>'CONTENT2'</code> (<b>optional</b>) (of type <code>String</code>):
55 * another name of the suitable content for provider tested. If relation
56 * is not specified the 'vnd.sun.star.writer://' name will be used.</li>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * @see com.sun.star.ucb.XContentProvider
61 public class _XContentProvider
extends MultiMethodTest
{
63 public static XContentProvider oObj
= null;
64 protected XContentIdentifierFactory CIF
= null ;
65 protected String content1
= "vnd.sun.star.help://" ;
66 protected String content2
= "vnd.sun.star.writer://" ;
69 * Retrieves object relations.
70 * @throws StatusException If one of relations not found.
72 public void before() {
73 CIF
= (XContentIdentifierFactory
) tEnv
.getObjRelation("FACTORY");
74 String tmp
= (String
) tEnv
.getObjRelation("CONTENT1") ;
75 if (tmp
!= null) content1
= tmp
;
76 tmp
= (String
) tEnv
.getObjRelation("CONTENT2") ;
77 if (tmp
!= null) content2
= tmp
;
79 if (CIF
== null) throw new StatusException(
80 Status
.failed("'FACTORY' relation is not found.")) ;
84 * Tries to query for some content suitable for this provider. <p>
85 * Has <b>OK</b> status if not null value is returned.
87 public void _queryContent() {
89 XContentIdentifierFactory CIF
= (XContentIdentifierFactory
)
90 tEnv
.getObjRelation("FACTORY");
91 String aURL
= content1
;
92 log
.println("Trying to query "+aURL
);
93 XContentIdentifier CI
= CIF
.createContentIdentifier(aURL
);
94 XContent aContent
= oObj
.queryContent(CI
);
96 Object nc
= tEnv
.getObjRelation("NoCONTENT");
98 res
= aContent
!= null;
100 tRes
.tested("queryContent()",res
);
101 } catch (com
.sun
.star
.ucb
.IllegalIdentifierException e
) {
102 log
.println("Exception while checking 'queryContent'");
103 e
.printStackTrace(log
);
104 tRes
.tested("queryContent()",false);
109 * Creates two different content identifiers. First two different
110 * identifiers compared, then two same identifiers. <p>
111 * Has <b>OK</b> status if in the first case <code>false</code>
112 * returned, and in the second - <code>true</code>.
114 public void _compareContentIds() {
115 XContentIdentifierFactory CIF
= (XContentIdentifierFactory
)
116 tEnv
.getObjRelation("FACTORY");
117 String aURL
= content1
;
118 XContentIdentifier CI
= CIF
.createContentIdentifier(aURL
);
120 XContentIdentifier CI2
= CIF
.createContentIdentifier(aURL
);
121 int compare
= oObj
.compareContentIds(CI
,CI2
);
122 boolean res
= (compare
!= 0);
124 log
.println("Didn't work with differnt IDs");
125 log
.println(compare
+" was returned");
127 compare
= oObj
.compareContentIds(CI
,CI
);
128 res
&= (compare
== 0);
130 log
.println("Didn't work with equal IDs");
131 log
.println(compare
+" was returned");
133 tRes
.tested("compareContentIds()",res
);