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