update dev300-m58
[ooovba.git] / ucb / qa / complex / tdoc / CheckTransientDocumentsContentProvider.java
blobacf8be4c6031fb127fe9462163416370b3317658
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: CheckTransientDocumentsContentProvider.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 ************************************************************************/
30 package complex.tdoc;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.lang.XServiceInfo;
34 import com.sun.star.sdbc.XResultSet;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.ucb.Command;
37 import com.sun.star.ucb.OpenCommandArgument2;
38 import com.sun.star.ucb.OpenMode;
39 import com.sun.star.ucb.XCommandProcessor;
40 import com.sun.star.ucb.XContent;
41 import com.sun.star.ucb.XContentAccess;
42 import com.sun.star.ucb.XContentIdentifier;
43 import com.sun.star.ucb.XContentIdentifierFactory;
44 import com.sun.star.ucb.XContentProvider;
45 import com.sun.star.ucb.XDynamicResultSet;
46 import com.sun.star.uno.UnoRuntime;
47 import complexlib.ComplexTestCase;
48 import util.WriterTools;
49 import util.utils;
51 /**
54 public class CheckTransientDocumentsContentProvider extends ComplexTestCase {
55 private final String testDocuments[] = new String[]{"sForm.sxw", "chinese.sxw", "Iterator.sxw"};
56 private final int countDocs = testDocuments.length;
57 private XMultiServiceFactory xMSF = null;
58 private XTextDocument[] xTextDoc = null;
60 public String[] getTestMethodNames() {
61 return new String[]{"checkTransientDocumentsContentProvider"};
64 public void before() {
65 xMSF = (XMultiServiceFactory)param.getMSF();
66 xTextDoc = new XTextDocument[countDocs];
67 log.println("Open some documents.");
68 for (int i=0; i<countDocs; i++) {
69 String fileName = utils.getFullTestURL(testDocuments[i]);
70 xTextDoc[i] = WriterTools.loadTextDoc(xMSF, fileName);
73 public void after() {
74 log.println("Close all documents.");
75 for (int i=0; i<countDocs; i++) {
76 xTextDoc[i].dispose();
80 /**
81 * Check the provider of document content: open some documents
82 * and look if they are accessible.
84 public void checkTransientDocumentsContentProvider() {
85 try {
86 // create a content provider
87 Object o = xMSF.createInstance("com.sun.star.comp.ucb.TransientDocumentsContentProvider");
88 XContentProvider xContentProvider =
89 (XContentProvider)UnoRuntime.queryInterface(XContentProvider.class, o);
91 // create the ucb
92 XContentIdentifierFactory xContentIdentifierFactory =
93 (XContentIdentifierFactory)UnoRuntime.queryInterface(
94 XContentIdentifierFactory.class, xMSF.createInstance(
95 "com.sun.star.ucb.UniversalContentBroker"));
96 // create a content identifier from the ucb for tdoc
97 XContentIdentifier xContentIdentifier =
98 xContentIdentifierFactory.createContentIdentifier("vnd.sun.star.tdoc:/");
99 // get content
100 XContent xContent = xContentProvider.queryContent(xContentIdentifier);
102 // actual test: execute an "open" command with the content
103 XCommandProcessor xCommandProcessor = (XCommandProcessor)UnoRuntime.queryInterface(XCommandProcessor.class, xContent);
104 // build up the command
105 Command command = new Command();
106 OpenCommandArgument2 commandarg2 = new OpenCommandArgument2();
107 commandarg2.Mode = OpenMode.ALL;
108 command.Name = "open";
109 command.Argument = commandarg2;
111 // execute the command
112 Object result = xCommandProcessor.execute(command, 0, null);
114 // check the result
115 log.println("Result: "+ result.getClass().toString());
116 XDynamicResultSet xDynamicResultSet = (XDynamicResultSet)UnoRuntime.queryInterface(XDynamicResultSet.class, result);
118 // check bug of wrong returned service name.
119 XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(XServiceInfo.class, xDynamicResultSet);
120 String[] sNames = xServiceInfo.getSupportedServiceNames();
121 String serviceName = sNames[0];
122 if (sNames.length > 1)
123 failed("Implementation has been changed. Check this test!");
124 assure("The service name '" + serviceName + "' is not valid.", !serviceName.equals("com.sun.star.ucb.DynamicContentResultSet"), true);
126 XResultSet xResultSet = xDynamicResultSet.getStaticResultSet();
127 XContentAccess xContentAccess = (XContentAccess)UnoRuntime.queryInterface(XContentAccess.class, xResultSet);
128 // iterate over the result: three docs were opened, we should have at least three content identifier strings
129 int countContentIdentifiers = 0;
130 while(xResultSet.next()) {
131 countContentIdentifiers++;
132 String identifier = xContentAccess.queryContentIdentifierString();
133 log.println("Identifier of row " + xResultSet.getRow() + ": " + identifier);
135 // some feeble test: if the amount >2, we're ok.
136 // 2do: check better
137 assure("Did only find " + countContentIdentifiers + " open documents." +
138 " Should have been at least 3.", countContentIdentifiers>2);
140 catch (com.sun.star.uno.Exception e) {
141 e.printStackTrace((java.io.PrintWriter)log);
142 failed("Could not create test objects.");