1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CheckContentProvider.java,v $
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 ************************************************************************/
32 import com
.sun
.star
.beans
.XPropertiesChangeNotifier
;
33 import com
.sun
.star
.beans
.XPropertyContainer
;
34 import com
.sun
.star
.beans
.XPropertySetInfoChangeNotifier
;
35 import com
.sun
.star
.container
.XChild
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.lang
.XServiceInfo
;
39 import com
.sun
.star
.lang
.XTypeProvider
;
40 import com
.sun
.star
.text
.XTextDocument
;
41 import com
.sun
.star
.ucb
.XCommandInfoChangeNotifier
;
42 import com
.sun
.star
.ucb
.XCommandProcessor
;
43 import com
.sun
.star
.ucb
.XContent
;
44 import com
.sun
.star
.ucb
.XContentIdentifier
;
45 import com
.sun
.star
.ucb
.XContentIdentifierFactory
;
46 import com
.sun
.star
.ucb
.XContentProvider
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import complexlib
.ComplexTestCase
;
49 import complex
.tdoc
.interfaces
._XChild
;
50 import complex
.tdoc
.interfaces
._XCommandInfoChangeNotifier
;
51 import complex
.tdoc
.interfaces
._XComponent
;
52 import complex
.tdoc
.interfaces
._XServiceInfo
;
53 import complex
.tdoc
.interfaces
._XTypeProvider
;
54 import complex
.tdoc
.interfaces
._XCommandProcessor
;
55 import complex
.tdoc
.interfaces
._XContent
;
56 import complex
.tdoc
.interfaces
._XPropertiesChangeNotifier
;
57 import complex
.tdoc
.interfaces
._XPropertyContainer
;
58 import complex
.tdoc
.interfaces
._XPropertySetInfoChangeNotifier
;
59 import lib
.TestEnvironment
;
60 import util
.WriterTools
;
64 * Check the TransientDocumentsContentProvider (TDOC). Three documents are
65 * loaded. Then every possible TDCP content type is instantiated and its
66 * interfaces are tested.<br>
67 * Important: opened documents are numbered in the order they are opened and
68 * numbers are not reused. This test will work only, if you start a new office
69 * with an accept parameter (writer is initially opened). Otherwise loaded
70 * documents are not found.
72 public class CheckContentProvider
extends ComplexTestCase
{
73 private final String testDocuments
[] = new String
[]{"filter.sxw", "chinese.sxw", "Iterator.sxw"};
74 private final int countDocs
= testDocuments
.length
;
75 private XMultiServiceFactory xMSF
= null;
76 private XTextDocument
[] xTextDoc
= null;
77 private XContent xContent
= null;
80 * The test methods: the test methods have to be executed in a specified
81 * order. This order is:
83 * <li>"checkTDOCRoot"</li>
84 * <li>"checkTDOCRootInterfaces"</li>
85 * <li>"checkTDOCDocument"</li>
86 * <li>"checkTDOCDocumentInterfaces"</li>
87 * <li>"checkTDOCFolder"</li>
88 * <li>"checkTDOCFolderInterfaces"</li>
89 * <li>"checkTDOCStream"</li>
90 * <li>"checkTDOCStreamInterfaces"</li>
92 * Important is, that the test of the element comes first, then the test of
95 public String
[] getTestMethodNames() {
96 return new String
[]{"checkTDOCRoot",
97 "checkTDOCRootInterfaces",
99 "checkTDOCDocumentInterfaces",
101 "checkTDOCFolderInterfaces",
103 "checkTDOCStreamInterfaces",
108 * Open some documents before the test
110 public void before() {
111 xMSF
= (XMultiServiceFactory
)param
.getMSF();
112 xTextDoc
= new XTextDocument
[countDocs
];
113 log
.println("Open some new documents.");
114 for (int i
=0; i
<countDocs
; i
++) {
115 String fileName
= utils
.getFullTestURL(testDocuments
[i
]);
116 System
.out
.println("Doc " + i
+ ": " + fileName
);
117 xTextDoc
[i
] = WriterTools
.loadTextDoc(xMSF
, fileName
);
122 * Close the documents
124 public void after() {
125 log
.println("Close all documents.");
126 for (int i
=0; i
<countDocs
; i
++) {
127 xTextDoc
[i
].dispose();
132 * Check the tdcp root.
134 public void checkTDOCRoot() {
136 // create a content provider
137 Object o
= xMSF
.createInstance("com.sun.star.comp.ucb.TransientDocumentsContentProvider");
138 XContentProvider xContentProvider
=
139 (XContentProvider
)UnoRuntime
.queryInterface(XContentProvider
.class, o
);
142 XContentIdentifierFactory xContentIdentifierFactory
=
143 (XContentIdentifierFactory
)UnoRuntime
.queryInterface(
144 XContentIdentifierFactory
.class, xMSF
.createInstance(
145 "com.sun.star.ucb.UniversalContentBroker"));
146 // create a content identifier from the ucb for tdoc
147 XContentIdentifier xContentIdentifier
=
148 xContentIdentifierFactory
.createContentIdentifier("vnd.sun.star.tdoc:/");
150 xContent
= xContentProvider
.queryContent(xContentIdentifier
);
152 String content
= xContent
.getContentType();
153 log
.println("#### Content root: " + content
);
155 // try to get some documents: should be "countDocs" at least.
156 XContentIdentifier
[] xContentId
= new XContentIdentifier
[countDocs
+5];
157 XContent
[] xCont
= new XContent
[countDocs
+5];
159 for (int i
=0; i
<countDocs
+5; i
++) {
160 xContentId
[i
] = xContentIdentifierFactory
.createContentIdentifier("vnd.sun.star.tdoc:/" + i
);
162 xCont
[i
] = xContentProvider
.queryContent(xContentId
[i
]);
163 int returnVal
= xContentProvider
.compareContentIds(xContentId
[i
], xContentIdentifier
);
165 if (xCont
[i
] != null)
166 cont
= xCont
[i
].getContentType();
167 log
.println("Document Content " + i
+ ": " + cont
+ " compare with root: " + returnVal
);
169 xContentId
[i
] = xContentIdentifierFactory
.createContentIdentifier("vnd.sun.star.tdoc:/" + i
+ "/content.xml");
171 xCont
[i
] = xContentProvider
.queryContent(xContentId
[i
]);
173 if (xCont
[i
] != null)
174 cont
= xCont
[i
].getContentType();
175 log
.println("\tContent.xml Content " + i
+ ": " + cont
);
178 util
.dbg
.printInterfaces(xContent
);
181 e
.printStackTrace((java
.io
.PrintWriter
)log
);
182 failed("Unexpected Exception: " + e
.getMessage());
187 * Check the interfaces of the root.
189 public void checkTDOCRootInterfaces() {
190 checkInterfaces(false);
194 * Check the tdcp document: document 3 is used.
196 public void checkTDOCDocument() {
199 Object o
= xMSF
.createInstance("com.sun.star.comp.ucb.TransientDocumentsContentProvider");
200 XContentProvider xContentProvider
=
201 (XContentProvider
)UnoRuntime
.queryInterface(XContentProvider
.class, o
);
203 XContentIdentifierFactory xContentIdentifierFactory
=
204 (XContentIdentifierFactory
)UnoRuntime
.queryInterface(
205 XContentIdentifierFactory
.class, xMSF
.createInstance(
206 "com.sun.star.ucb.UniversalContentBroker"));
207 // create a content identifier from the ucb for tdoc
208 XContentIdentifier xContentIdentifier
=
209 xContentIdentifierFactory
.createContentIdentifier("vnd.sun.star.tdoc:/3");
211 xContent
= xContentProvider
.queryContent(xContentIdentifier
);
213 String content
= xContent
.getContentType();
214 log
.println("#### Document root: " + content
);
217 e
.printStackTrace((java
.io
.PrintWriter
)log
);
218 failed("Unexpected Exception: " + e
.getMessage());
223 * Check the interfaces on the document.
225 public void checkTDOCDocumentInterfaces() {
226 checkInterfaces(true);
230 * Check a folder on document 2 (document 2 contains an embedded picture and
231 * therefore contans a subfolder "Pictures"
233 public void checkTDOCFolder() {
236 Object o
= xMSF
.createInstance("com.sun.star.comp.ucb.TransientDocumentsContentProvider");
237 XContentProvider xContentProvider
=
238 (XContentProvider
)UnoRuntime
.queryInterface(XContentProvider
.class, o
);
240 XContentIdentifierFactory xContentIdentifierFactory
=
241 (XContentIdentifierFactory
)UnoRuntime
.queryInterface(
242 XContentIdentifierFactory
.class, xMSF
.createInstance(
243 "com.sun.star.ucb.UniversalContentBroker"));
244 // create a content identifier from the ucb for tdoc
245 XContentIdentifier xContentIdentifier
=
246 xContentIdentifierFactory
.createContentIdentifier("vnd.sun.star.tdoc:/2/Pictures");
248 xContent
= xContentProvider
.queryContent(xContentIdentifier
);
250 String content
= xContent
.getContentType();
251 log
.println("#### Folder type: " + content
);
254 e
.printStackTrace((java
.io
.PrintWriter
)log
);
255 failed("Unexpected Exception: " + e
.getMessage());
260 * Check the interfaces on the folder.
262 public void checkTDOCFolderInterfaces() {
263 checkInterfaces(true);
267 * Open a stream to the embedded picture of document 1.
269 public void checkTDOCStream() {
272 Object o
= xMSF
.createInstance("com.sun.star.comp.ucb.TransientDocumentsContentProvider");
273 XContentProvider xContentProvider
=
274 (XContentProvider
)UnoRuntime
.queryInterface(XContentProvider
.class, o
);
277 XContentIdentifierFactory xContentIdentifierFactory
=
278 (XContentIdentifierFactory
)UnoRuntime
.queryInterface(
279 XContentIdentifierFactory
.class, xMSF
.createInstance(
280 "com.sun.star.ucb.UniversalContentBroker"));
281 // create a content identifier from the ucb for tdoc
282 XContentIdentifier xContentIdentifier
=
283 xContentIdentifierFactory
.createContentIdentifier("vnd.sun.star.tdoc:/1/Pictures/10000000000000640000004B9C743800.gif");
285 xContent
= xContentProvider
.queryContent(xContentIdentifier
);
287 String content
= xContent
.getContentType();
288 log
.println("#### Folder type: " + content
);
291 e
.printStackTrace((java
.io
.PrintWriter
)log
);
292 failed("Unexpected Exception: " + e
.getMessage());
297 * Check the interfaces on the stream.
299 public void checkTDOCStreamInterfaces() {
300 checkInterfaces(true);
304 * Since all tdcp content types implement (nearly) the same interfaces, they
306 * Executed interface tests are (in this order):
308 * <li>XTypeProvider</li>
309 * <li>XServiceInfo</li>
310 * <li>XCommandProcessor</li>
312 * <li>XPropertiesChangeNotifier</li>
313 * <li>XPropertySetInfoChangeNotifier</li>
314 * <li>XCommandInfoChangeNotifier</li>
316 * <li>XPropertyContainer</li>
317 * <li>XComponent</li>
319 * @param hasParent True, if the tested content type does have a parent:
320 * only the root has not. Used in the XChild interface test.
322 private void checkInterfaces(boolean hasParent
) {
323 // check the XTypeProvider interface
324 _XTypeProvider xTypeProvider
= new _XTypeProvider();
325 xTypeProvider
.oObj
= (XTypeProvider
)UnoRuntime
.queryInterface(XTypeProvider
.class, xContent
);
326 xTypeProvider
.log
= log
;
327 assure("getImplementationId()", xTypeProvider
._getImplementationId());
328 assure("getTypes()", xTypeProvider
._getTypes());
330 // check the XSewrviceInfo interface
331 _XServiceInfo xServiceInfo
= new _XServiceInfo();
332 xServiceInfo
.oObj
= (XServiceInfo
)UnoRuntime
.queryInterface(XServiceInfo
.class, xContent
);
333 xServiceInfo
.log
= log
;
334 assure("getImplementationName()", xServiceInfo
._getImplementationName());
335 assure("getSupportedServiceNames()", xServiceInfo
._getSupportedServiceNames());
336 assure("supportsService()", xServiceInfo
._supportsService());
338 // check the XCommandProcessor interface
339 _XCommandProcessor xCommandProcessor
= new _XCommandProcessor();
340 xCommandProcessor
.oObj
= (XCommandProcessor
)UnoRuntime
.queryInterface(XCommandProcessor
.class, xContent
);
341 xCommandProcessor
.log
= log
;
342 xCommandProcessor
.before((XMultiServiceFactory
)param
.getMSF());
343 assure("createCommandIdentifier()", xCommandProcessor
._createCommandIdentifier());
344 assure("execute()", xCommandProcessor
._execute());
345 assure("abort()", xCommandProcessor
._abort());
347 // check the XChild interface
348 _XChild xChild
= new _XChild();
349 xChild
.oObj
= (XChild
)UnoRuntime
.queryInterface(XChild
.class, xContent
);
351 // hasParent dermines, if this content has a parent
352 assure("getParent()", xChild
._getParent(hasParent
));
353 // parameter does dermine, if this funczion is supported: generally not supported with tdcp content
354 assure("setParent()", xChild
._setParent(false));
356 // check the XPropertyChangeNotifier interface
357 _XPropertiesChangeNotifier xPropChange
= new _XPropertiesChangeNotifier();
358 xPropChange
.oObj
= (XPropertiesChangeNotifier
)UnoRuntime
.queryInterface(XPropertiesChangeNotifier
.class, xContent
);
359 xPropChange
.log
= log
;
360 assure("addPropertiesChangeListener()", xPropChange
._addPropertiesChangeListener());
361 assure("removePropertiesChangeListener()", xPropChange
._removePropertiesChangeListener());
363 // check the XPropertySetInfoChangeNotifier interface
364 _XPropertySetInfoChangeNotifier xPropSetInfo
= new _XPropertySetInfoChangeNotifier();
365 xPropSetInfo
.oObj
= (XPropertySetInfoChangeNotifier
)UnoRuntime
.queryInterface(XPropertySetInfoChangeNotifier
.class, xContent
);
366 xPropSetInfo
.log
= log
;
367 assure("addPropertiesChangeListener()", xPropSetInfo
._addPropertiesChangeListener());
368 assure("removePropertiesChangeListener()", xPropSetInfo
._removePropertiesChangeListener());
370 // check the XCommandInfoChangeNotifier interface
371 _XCommandInfoChangeNotifier xCommandChange
= new _XCommandInfoChangeNotifier();
372 xCommandChange
.oObj
= (XCommandInfoChangeNotifier
)UnoRuntime
.queryInterface(XCommandInfoChangeNotifier
.class, xContent
);
373 xCommandChange
.log
= log
;
374 assure("addCommandInfoChangeListener()", xCommandChange
._addCommandInfoChangeListener());
375 assure("removeCommandInfoChangeListener()", xCommandChange
._removeCommandInfoChangeListener());
377 // check the XContent interface
378 _XContent xCont
= new _XContent();
379 xCont
.oObj
= (XContent
)UnoRuntime
.queryInterface(XContent
.class, xContent
);
381 assure("addContentEventListener()", xCont
._addContentEventListener());
382 assure("getContentType()", xCont
._getContentType());
383 assure("getIdentifier()", xCont
._getIdentifier());
384 assure("removeContentEventListener()", xCont
._removeContentEventListener());
386 // check the XPropertyContainer interface
387 _XPropertyContainer xPropCont
= new _XPropertyContainer();
388 xPropCont
.oObj
= (XPropertyContainer
)UnoRuntime
.queryInterface(XPropertyContainer
.class, xContent
);
390 assure("addProperty()", xPropCont
._addProperty());
391 assure("removeProperty()", xPropCont
._removeProperty());
393 // check the XComponent interface
394 _XComponent xComponent
= new _XComponent();
395 xComponent
.oObj
= (XComponent
)UnoRuntime
.queryInterface(XComponent
.class, xContent
);
396 xComponent
.log
= log
;
397 assure("addEventListener()", xComponent
._addEventListener());
398 assure("removeEventListener()", xComponent
._removeEventListener());
399 // assure("dispose()", xComponent._dispose());