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