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