fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / qa / complex / tdoc / CheckTransientDocumentsContentProvider.java
blobeef459c8148b3cb902aae615992680831d18d3ae
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package complex.tdoc;
20 import com.sun.star.lang.XMultiServiceFactory;
21 import com.sun.star.lang.XServiceInfo;
22 import com.sun.star.sdbc.XResultSet;
23 import com.sun.star.text.XTextDocument;
24 import com.sun.star.ucb.Command;
25 import com.sun.star.ucb.OpenCommandArgument2;
26 import com.sun.star.ucb.OpenMode;
27 import com.sun.star.ucb.XCommandProcessor;
28 import com.sun.star.ucb.XContent;
29 import com.sun.star.ucb.XContentAccess;
30 import com.sun.star.ucb.XContentIdentifier;
31 import com.sun.star.ucb.XContentIdentifierFactory;
32 import com.sun.star.ucb.XContentProvider;
33 import com.sun.star.ucb.XDynamicResultSet;
34 import com.sun.star.uno.UnoRuntime;
35 import util.WriterTools;
37 import org.junit.After;
38 import org.junit.AfterClass;
39 import org.junit.Before;
40 import org.junit.BeforeClass;
41 import org.junit.Test;
42 import org.openoffice.test.OfficeConnection;
43 import static org.junit.Assert.*;
45 /**
48 public class CheckTransientDocumentsContentProvider {
49 // TODO: document doesn't exists
50 private final String testDocuments[] = new String[]{/*"sForm.sxw",*/ "chinese.sxw", "Iterator.sxw"};
51 private final int countDocs = testDocuments.length;
52 private XMultiServiceFactory xMSF = null;
53 private XTextDocument[] xTextDoc = null;
55 public String[] getTestMethodNames() {
56 return new String[]{"checkTransientDocumentsContentProvider"};
59 @Before public void before() {
60 xMSF = getMSF();
61 xTextDoc = new XTextDocument[countDocs];
62 System.out.println("Open some documents.");
63 for (int i=0; i<countDocs; i++) {
64 String fileName = TestDocument.getUrl(testDocuments[i]);
65 xTextDoc[i] = WriterTools.loadTextDoc(xMSF, fileName);
66 assertNotNull("Can't load document " + fileName, xTextDoc[i]);
69 @After public void after() {
70 System.out.println("Close all documents.");
71 for (int i=0; i<countDocs; i++) {
72 xTextDoc[i].dispose();
76 /**
77 * Check the provider of document content: open some documents
78 * and look if they are accessible.
80 @Test public void checkTransientDocumentsContentProvider() {
81 try {
82 // create a content provider
83 Object o = xMSF.createInstance("com.sun.star.comp.ucb.TransientDocumentsContentProvider");
84 XContentProvider xContentProvider =
85 UnoRuntime.queryInterface(XContentProvider.class, o);
87 // create unconfigured ucb
88 XContentIdentifierFactory xContentIdentifierFactory =
89 UnoRuntime.queryInterface(XContentIdentifierFactory.class, xMSF.createInstance("com.sun.star.ucb.UniversalContentBroker"));
90 // create a content identifier from the ucb for tdoc
91 XContentIdentifier xContentIdentifier =
92 xContentIdentifierFactory.createContentIdentifier("vnd.sun.star.tdoc:/");
93 // get content
94 XContent xContent = xContentProvider.queryContent(xContentIdentifier);
96 // actual test: execute an "open" command with the content
97 XCommandProcessor xCommandProcessor = UnoRuntime.queryInterface(XCommandProcessor.class, xContent);
98 // build up the command
99 Command command = new Command();
100 OpenCommandArgument2 commandarg2 = new OpenCommandArgument2();
101 commandarg2.Mode = OpenMode.ALL;
102 command.Name = "open";
103 command.Argument = commandarg2;
105 // execute the command
106 Object result = xCommandProcessor.execute(command, 0, null);
108 // check the result
109 System.out.println("Result: "+ result.getClass().toString());
110 XDynamicResultSet xDynamicResultSet = UnoRuntime.queryInterface(XDynamicResultSet.class, result);
112 // check bug of wrong returned service name.
113 XServiceInfo xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, xDynamicResultSet);
114 String[] sNames = xServiceInfo.getSupportedServiceNames();
115 String serviceName = sNames[0];
116 if (sNames.length > 1)
118 fail("Implementation has been changed. Check this test!");
120 assertTrue("The service name '" + serviceName + "' is not valid.", !serviceName.equals("com.sun.star.ucb.DynamicContentResultSet"));
122 XResultSet xResultSet = xDynamicResultSet.getStaticResultSet();
123 XContentAccess xContentAccess = UnoRuntime.queryInterface(XContentAccess.class, xResultSet);
124 // iterate over the result: three docs were opened, we should have at least three content identifier strings
125 int countContentIdentifiers = 0;
126 while(xResultSet.next()) {
127 countContentIdentifiers++;
128 String identifier = xContentAccess.queryContentIdentifierString();
129 System.out.println("Identifier of row " + xResultSet.getRow() + ": " + identifier);
131 // some feeble test: if the amount >2, we're ok.
132 // 2do: check better
133 assertTrue("Did only find " + countContentIdentifiers + " open documents." +
134 " Should have been at least 3.", countContentIdentifiers>2);
136 catch (com.sun.star.uno.Exception e) {
137 e.printStackTrace();
138 fail("Could not create test objects.");
143 private XMultiServiceFactory getMSF()
145 return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
148 // setup and close connections
149 @BeforeClass public static void setUpConnection() throws Exception {
150 System.out.println("setUpConnection()");
151 connection.setUp();
154 @AfterClass public static void tearDownConnection()
155 throws InterruptedException, com.sun.star.uno.Exception
157 System.out.println("tearDownConnection()");
158 connection.tearDown();
161 private static final OfficeConnection connection = new OfficeConnection();