1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.ucb;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.ucb.XContent;
31cdf0e10cSrcweir import com.sun.star.ucb.XContentIdentifier;
32cdf0e10cSrcweir import com.sun.star.ucb.XContentIdentifierFactory;
33cdf0e10cSrcweir import com.sun.star.ucb.XContentProvider;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir * Testing <code>com.sun.star.ucb.XContentProvider</code>
37cdf0e10cSrcweir * interface methods :
38cdf0e10cSrcweir * <ul>
39cdf0e10cSrcweir *  <li><code> queryContent()</code></li>
40cdf0e10cSrcweir *  <li><code> compareContentIds()</code></li>
41cdf0e10cSrcweir * </ul> <p>
42cdf0e10cSrcweir * This test needs the following object relations :
43cdf0e10cSrcweir * <ul>
44cdf0e10cSrcweir *  <li> <code>'FACTORY'</code> (of type
45cdf0e10cSrcweir *   <code>com.sun.star.ucb.XContentIdentifierFactory</code>):
46cdf0e10cSrcweir *   a suitable factory which can produce content identifiers </li>
47cdf0e10cSrcweir *  <li> <code>'CONTENT1'</code> (<b>optional</b>) (of type <code>String</code>):
48cdf0e10cSrcweir *   name of the suitable content for provider tested. If relation
49cdf0e10cSrcweir *   is not specified the 'vnd.sun.star.help://' name will be used.</li>
50cdf0e10cSrcweir *  <li> <code>'CONTENT2'</code> (<b>optional</b>) (of type <code>String</code>):
51cdf0e10cSrcweir *   another name of the suitable content for provider tested. If relation
52cdf0e10cSrcweir *   is not specified the 'vnd.sun.star.writer://' name will be used.</li>
53cdf0e10cSrcweir * <ul> <p>
54cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
55cdf0e10cSrcweir * @see com.sun.star.ucb.XContentProvider
56cdf0e10cSrcweir */
57cdf0e10cSrcweir public class _XContentProvider extends MultiMethodTest {
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     public static XContentProvider oObj = null;
60cdf0e10cSrcweir     protected XContentIdentifierFactory CIF = null ;
61cdf0e10cSrcweir     protected String content1 = "vnd.sun.star.help://" ;
62cdf0e10cSrcweir     protected String content2 = "vnd.sun.star.writer://" ;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     /**
65cdf0e10cSrcweir     * Retrieves object relations.
66cdf0e10cSrcweir     * @throws StatusException If one of relations not found.
67cdf0e10cSrcweir     */
before()68cdf0e10cSrcweir     public void before() {
69cdf0e10cSrcweir         CIF = (XContentIdentifierFactory) tEnv.getObjRelation("FACTORY");
70cdf0e10cSrcweir         String tmp = (String) tEnv.getObjRelation("CONTENT1") ;
71cdf0e10cSrcweir         if (tmp != null) content1 = tmp ;
72cdf0e10cSrcweir         tmp = (String) tEnv.getObjRelation("CONTENT2") ;
73cdf0e10cSrcweir         if (tmp != null) content2 = tmp ;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         if (CIF == null) throw new StatusException(
76cdf0e10cSrcweir             Status.failed("'FACTORY' relation is not found.")) ;
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     /**
80cdf0e10cSrcweir     * Tries to query for some content suitable for this provider. <p>
81cdf0e10cSrcweir     * Has <b>OK</b> status if not null value is returned.
82cdf0e10cSrcweir     */
_queryContent()83cdf0e10cSrcweir     public void _queryContent() {
84cdf0e10cSrcweir         try {
85cdf0e10cSrcweir             XContentIdentifierFactory CIF = (XContentIdentifierFactory)
86cdf0e10cSrcweir                                                 tEnv.getObjRelation("FACTORY");
87cdf0e10cSrcweir             String aURL = content1;
88cdf0e10cSrcweir             log.println("Trying to query "+aURL);
89cdf0e10cSrcweir             XContentIdentifier CI = CIF.createContentIdentifier(aURL);
90cdf0e10cSrcweir             XContent aContent = oObj.queryContent(CI);
91cdf0e10cSrcweir             boolean res = true;
92cdf0e10cSrcweir             Object nc = tEnv.getObjRelation("NoCONTENT");
93cdf0e10cSrcweir             if (nc == null) {
94cdf0e10cSrcweir                 res = aContent != null;
95cdf0e10cSrcweir             }
96cdf0e10cSrcweir             tRes.tested("queryContent()",res);
97cdf0e10cSrcweir         } catch (com.sun.star.ucb.IllegalIdentifierException e) {
98cdf0e10cSrcweir             log.println("Exception while checking 'queryContent'");
99cdf0e10cSrcweir             e.printStackTrace(log);
100cdf0e10cSrcweir             tRes.tested("queryContent()",false);
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     /**
105cdf0e10cSrcweir     * Creates two different content identifiers. First two different
106cdf0e10cSrcweir     * identifiers compared, then two same identifiers. <p>
107cdf0e10cSrcweir     * Has <b>OK</b> status if in the first case <code>false</code>
108cdf0e10cSrcweir     * returned, and in the second - <code>true</code>.
109cdf0e10cSrcweir     */
_compareContentIds()110cdf0e10cSrcweir     public void _compareContentIds() {
111cdf0e10cSrcweir         XContentIdentifierFactory CIF = (XContentIdentifierFactory)
112cdf0e10cSrcweir                                             tEnv.getObjRelation("FACTORY");
113cdf0e10cSrcweir         String aURL = content1 ;
114cdf0e10cSrcweir         XContentIdentifier CI = CIF.createContentIdentifier(aURL);
115cdf0e10cSrcweir         aURL = content2 ;
116cdf0e10cSrcweir         XContentIdentifier CI2 = CIF.createContentIdentifier(aURL);
117cdf0e10cSrcweir         int compare = oObj.compareContentIds(CI,CI2);
118cdf0e10cSrcweir         boolean res = (compare != 0);
119cdf0e10cSrcweir         if (!res) {
120*bb6af6bcSPedro Giffuni             log.println("Didn't work with different IDs");
121cdf0e10cSrcweir             log.println(compare+" was returned");
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir         compare = oObj.compareContentIds(CI,CI);
124cdf0e10cSrcweir         res &= (compare == 0);
125cdf0e10cSrcweir         if (!res) {
126cdf0e10cSrcweir             log.println("Didn't work with equal IDs");
127cdf0e10cSrcweir             log.println(compare+" was returned");
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir         tRes.tested("compareContentIds()",res);
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135