1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package ifc.ucb; 29 30 import lib.MultiMethodTest; 31 import lib.Status; 32 import lib.StatusException; 33 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; 38 39 /** 40 * Testing <code>com.sun.star.ucb.XContentProvider</code> 41 * interface methods : 42 * <ul> 43 * <li><code> queryContent()</code></li> 44 * <li><code> compareContentIds()</code></li> 45 * </ul> <p> 46 * This test needs the following object relations : 47 * <ul> 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> 57 * <ul> <p> 58 * Test is <b> NOT </b> multithread compilant. <p> 59 * @see com.sun.star.ucb.XContentProvider 60 */ 61 public class _XContentProvider extends MultiMethodTest { 62 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://" ; 67 68 /** 69 * Retrieves object relations. 70 * @throws StatusException If one of relations not found. 71 */ 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 ; 78 79 if (CIF == null) throw new StatusException( 80 Status.failed("'FACTORY' relation is not found.")) ; 81 } 82 83 /** 84 * Tries to query for some content suitable for this provider. <p> 85 * Has <b>OK</b> status if not null value is returned. 86 */ 87 public void _queryContent() { 88 try { 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); 95 boolean res = true; 96 Object nc = tEnv.getObjRelation("NoCONTENT"); 97 if (nc == null) { 98 res = aContent != null; 99 } 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); 105 } 106 } 107 108 /** 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>. 113 */ 114 public void _compareContentIds() { 115 XContentIdentifierFactory CIF = (XContentIdentifierFactory) 116 tEnv.getObjRelation("FACTORY"); 117 String aURL = content1 ; 118 XContentIdentifier CI = CIF.createContentIdentifier(aURL); 119 aURL = content2 ; 120 XContentIdentifier CI2 = CIF.createContentIdentifier(aURL); 121 int compare = oObj.compareContentIds(CI,CI2); 122 boolean res = (compare != 0); 123 if (!res) { 124 log.println("Didn't work with differnt IDs"); 125 log.println(compare+" was returned"); 126 } 127 compare = oObj.compareContentIds(CI,CI); 128 res &= (compare == 0); 129 if (!res) { 130 log.println("Didn't work with equal IDs"); 131 log.println(compare+" was returned"); 132 } 133 tRes.tested("compareContentIds()",res); 134 } 135 136 } 137 138 139