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