fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / qa / complex / tdoc / CheckTransientDocumentsDocumentContent.java
blob941d68a71a4e549ca0a41ada307ef4dbc1c99dc2
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.beans.Property;
21 import com.sun.star.beans.PropertyValue;
22 import com.sun.star.document.XDocumentSubStorageSupplier;
23 import com.sun.star.embed.ElementModes;
24 import com.sun.star.embed.XStorage;
25 import com.sun.star.frame.XModel;
26 import com.sun.star.frame.XTransientDocumentsDocumentContentFactory;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.sdbc.XResultSet;
29 import com.sun.star.sdbc.XRow;
30 import com.sun.star.text.XTextDocument;
31 import com.sun.star.ucb.Command;
32 import com.sun.star.ucb.ContentInfo;
33 import com.sun.star.ucb.OpenCommandArgument2;
34 import com.sun.star.ucb.OpenMode;
35 import com.sun.star.ucb.XCommandProcessor;
36 import com.sun.star.ucb.XContent;
37 import com.sun.star.ucb.XDynamicResultSet;
38 import com.sun.star.uno.UnoRuntime;
39 import util.WriterTools;
40 import util.utils;
42 import org.junit.After;
43 import org.junit.AfterClass;
44 import org.junit.Before;
45 import org.junit.BeforeClass;
46 import org.junit.Test;
47 import org.openoffice.test.OfficeConnection;
48 import static org.junit.Assert.*;
49 /**
52 public class CheckTransientDocumentsDocumentContent {
53 // TODO: document doesn't exists
54 private static final String testDocuments = "sForm.sxw";
55 private static final String folderName = "TestFolder";
56 private XMultiServiceFactory xMSF = null;
57 private XTextDocument xTextDoc = null;
59 @Before public void before() {
60 xMSF = getMSF();
61 System.out.println("Open a document.");
62 String fileName = TestDocument.getUrl(testDocuments);
63 xTextDoc = WriterTools.loadTextDoc(xMSF, fileName);
64 assertNotNull(xTextDoc);
66 @After public void after() {
67 System.out.println("Close all documents.");
68 xTextDoc.dispose();
71 /**
72 * Check the provider of document content: open some documents
73 * and look if they are accessible.
75 @Test public void checkTransientDocumentsDocumentContent() {
76 try {
77 // create a content provider
78 Object o = xMSF.createInstance("com.sun.star.comp.ucb.TransientDocumentsDocumentContentFactory");
80 XTransientDocumentsDocumentContentFactory xTransientDocumentsDocumentContentFactory =
81 UnoRuntime.queryInterface(XTransientDocumentsDocumentContentFactory.class, o);
82 // get the model from the opened document
83 XModel xModel = xTextDoc.getCurrentController().getModel();
85 // a little additional check for 114733
86 XDocumentSubStorageSupplier xDocumentSubStorageSupplier = UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class, xModel);
87 String[]names = xDocumentSubStorageSupplier.getDocumentSubStoragesNames();
88 for (int i=0; i<names.length; i++) {
89 System.out.println("SubStorage names " + i + ": " +names[i]);
91 XStorage xStorage = xDocumentSubStorageSupplier.getDocumentSubStorage(names[0], ElementModes.READWRITE);
92 assertTrue("Could not get a storage from the XDocumentStorageSupplier.", xStorage != null);
93 // get content
94 XContent xContent = xTransientDocumentsDocumentContentFactory.createDocumentContent(xModel);
95 // actual test: execute some commands
96 XCommandProcessor xCommandProcessor = UnoRuntime.queryInterface(XCommandProcessor.class, xContent);
98 // create the command and arguments
99 Command command = new Command();
100 OpenCommandArgument2 cmargs2 = new OpenCommandArgument2();
101 Property[]props = new Property[1];
102 props[0] = new Property();
103 props[0].Name = "Title";
104 props[0].Handle = -1;
105 cmargs2.Mode = OpenMode.ALL;
106 cmargs2.Properties = props;
108 command.Name = "open";
109 command.Argument = cmargs2;
111 Object result = xCommandProcessor.execute(command, 0, null);
112 XDynamicResultSet xDynamicResultSet = UnoRuntime.queryInterface(XDynamicResultSet.class, result);
113 XResultSet xResultSet = xDynamicResultSet.getStaticResultSet();
114 XRow xRow = UnoRuntime.queryInterface(XRow.class, xResultSet);
115 // create the new folder 'folderName': first, check if it's already there
116 while(xResultSet.next()) {
117 String existingFolderName = xRow.getString(1);
118 System.out.println("Found existing folder: '" + existingFolderName + "'");
119 if (folderName.equals(existingFolderName)) {
120 fail("Cannot create a new folder: folder already exists: adapt test or choose a different document.");
123 // create a folder
124 System.out.println("Create new folder "+ folderName);
125 ContentInfo contentInfo = new ContentInfo();
126 contentInfo.Type = "application/vnd.sun.star.tdoc-folder";
128 command.Name = "createNewContent";
129 command.Argument = contentInfo;
131 result = xCommandProcessor.execute(command, 0, null);
132 XContent xNewFolder = UnoRuntime.queryInterface(XContent.class, result);
134 XCommandProcessor xFolderCommandProcessor = UnoRuntime.queryInterface(XCommandProcessor.class, xNewFolder);
135 System.out.println("Got the new folder: " + utils.getImplName(xNewFolder));
137 // name the new folder
138 PropertyValue[] titleProp = new PropertyValue[1];
139 titleProp[0] = new PropertyValue();
140 titleProp[0].Name = "Title";
141 titleProp[0].Handle = -1;
142 titleProp[0].Value = folderName;
143 Command titleSetCommand = new Command();
144 titleSetCommand.Name = "setPropertyValues";
145 titleSetCommand.Argument = titleProp;
146 xFolderCommandProcessor.execute(titleSetCommand, 0, null);
149 catch (com.sun.star.uno.Exception e) {
150 e.printStackTrace();
151 fail("Could not create test objects.");
157 private XMultiServiceFactory getMSF()
159 return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
162 // setup and close connections
163 @BeforeClass public static void setUpConnection() throws Exception {
164 System.out.println("setUpConnection()");
165 connection.setUp();
168 @AfterClass public static void tearDownConnection()
169 throws InterruptedException, com.sun.star.uno.Exception
171 System.out.println("tearDownConnection()");
172 connection.tearDown();
175 private static final OfficeConnection connection = new OfficeConnection();