tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / ucb / qa / complex / tdoc / CheckTransientDocumentsContent.java
bloba5b2120b2704ef145161738eba188a3c93566bc3
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.XPropertySetInfo;
22 import com.sun.star.frame.XModel;
23 import com.sun.star.lang.XMultiServiceFactory;
24 import com.sun.star.text.XTextDocument;
25 import com.sun.star.ucb.Command;
26 import com.sun.star.ucb.XCommandProcessor;
27 import com.sun.star.ucb.XContent;
28 import com.sun.star.ucb.XContentIdentifier;
29 import com.sun.star.ucb.XContentIdentifierFactory;
30 import com.sun.star.ucb.XContentProvider;
31 import com.sun.star.uno.UnoRuntime;
32 import util.WriterTools;
34 import org.junit.After;
35 import org.junit.AfterClass;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.openoffice.test.OfficeConnection;
40 import static org.junit.Assert.*;
41 /**
44 public class CheckTransientDocumentsContent {
45 // TODO: document doesn't exists
46 private final String testDocuments[] = new String[]{"sForm.sxw"};//, "chinese.sxw", "Iterator.sxw"};
47 private final int countDocs = testDocuments.length;
48 private XMultiServiceFactory xMSF = null;
49 private XTextDocument[] xTextDoc = null;
51 public String[] getTestMethodNames() {
52 return new String[] {"checkTransientDocumentsContent"};
55 @Before public void before() {
56 xMSF = getMSF();
57 xTextDoc = new XTextDocument[countDocs];
58 System.out.println("Open some documents.");
59 for (int i=0; i<countDocs; i++) {
60 String fileName = TestDocument.getUrl(testDocuments[i]);
61 xTextDoc[i] = WriterTools.loadTextDoc(xMSF, fileName);
62 assertNotNull("Can't load document " + fileName, xTextDoc[i]);
65 @After public void after() {
66 System.out.println("Close all documents.");
67 for (int i=0; i<countDocs; i++) {
68 xTextDoc[i].dispose();
72 /**
73 * Check the content of one document
75 @Test public void checkTransientDocumentsContent() {
76 try {
77 // create unconfigured ucb
78 XContentIdentifierFactory xContentIdentifierFactory =
79 UnoRuntime.queryInterface(XContentIdentifierFactory.class, xMSF.createInstance("com.sun.star.ucb.UniversalContentBroker"));
80 XContentProvider xContentProvider =
81 UnoRuntime.queryInterface(XContentProvider.class, xContentIdentifierFactory);
82 // create a content identifier from the ucb for tdoc
83 XContentIdentifier xContentIdentifier =
84 xContentIdentifierFactory.createContentIdentifier("vnd.sun.star.tdoc:/1");
85 // get content
86 XContent xContent = xContentProvider.queryContent(xContentIdentifier);
88 // actual test: commands to get some properties
89 XCommandProcessor xCommandProcessor = UnoRuntime.queryInterface(XCommandProcessor.class, xContent);
90 // build up the command
91 Command command = new Command();
92 command.Name = "getPropertySetInfo";
93 command.Handle = -1;
95 // execute the command
96 Object result = xCommandProcessor.execute(command, 0, null);
98 // check the result
99 System.out.println("Result: "+ result.getClass().toString());
100 XPropertySetInfo xPropertySetInfo = UnoRuntime.queryInterface(XPropertySetInfo.class, result);
101 Property[] props = xPropertySetInfo.getProperties();
102 boolean res = false;
103 for(int i=0; i<props.length; i++) {
104 String propName = props[i].Name;
105 res |= propName.equals("DocumentModel");
106 System.out.println("Found property: " + propName + " type: " + props[i].Type.getTypeName());
108 assertNotNull("Did not find property 'DocumentModel' in the Property array.", res);
110 // get on property
111 command.Name = "getPropertyValues";
112 command.Handle = -1;
113 Property[] prop = new Property[1];
114 prop[0] = new Property();
115 prop[0].Name = "DocumentModel";
116 prop[0].Handle = -1;
117 command.Argument = prop;
119 // execute the command
120 result = xCommandProcessor.execute(command, 0, null);
122 // check the result
123 System.out.println("Result: "+ result.getClass().toString());
125 XModel xModel = UnoRuntime.queryInterface(XModel.class, result);
126 assertTrue("Did not get property 'DocumentModel'.", xModel == null);
128 catch (com.sun.star.uno.Exception e) {
129 e.printStackTrace();
130 fail("Could not create test objects.");
135 private XMultiServiceFactory getMSF()
137 return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
140 // setup and close connections
141 @BeforeClass public static void setUpConnection() throws Exception {
142 System.out.println("setUpConnection()");
143 connection.setUp();
146 @AfterClass public static void tearDownConnection()
147 throws InterruptedException, com.sun.star.uno.Exception
149 System.out.println("tearDownConnection()");
150 connection.tearDown();
153 private static final OfficeConnection connection = new OfficeConnection();