Debian Codegraph @

framework/qa/complex/broken_document/LoadDocument.java

raw
1 /*
2 * This file is part of the LibreOffice project.
3 *
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/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
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 .
17 */
18 package complex.broken_document;
19
20 import com.sun.star.beans.PropertyValue;
21 import com.sun.star.frame.XComponentLoader;
22 import com.sun.star.frame.XFrame;
23 import com.sun.star.lang.XMultiServiceFactory;
24 import com.sun.star.uno.UnoRuntime;
25
26
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.openoffice.test.OfficeConnection;
31 import static org.junit.Assert.*;
32
33
34 /**
35 * Check, if message boxes appear when the Office is in "headless" mode. Tests
36 * bug i15809. This test uses the broken document dbf.dbf.emf.
37 */
38 public class LoadDocument {
39
40
41 /**
42 * Start Office with "--headless" parameter, then
43 * load the broken document "dbf.dbf.emf", that brings a message box up in
44 * the ui, see if the headless mode of SOffice changes.
45 */
46 @Test public void checkHeadlessState()
47 {
48 XMultiServiceFactory xMSF = getMSF();
49 XFrame xDesktop = null;
50
51 try {
52 xDesktop = UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
53 }
54 catch(com.sun.star.uno.Exception e) {
55 fail("Could not create a desktop instance.");
56 }
57
58 XComponentLoader xDesktopLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);
59 System.out.println("xDesktopLoader is null: " + (xDesktopLoader == null));
60 PropertyValue[] val = new PropertyValue[0];
61
62 String fileUrl = complex.broken_document.TestDocument.getUrl("dbf.dbf.emf");
63 System.out.println("File Url: " + fileUrl);
64
65 try {
66 xDesktopLoader.loadComponentFromURL(fileUrl, "_blank", 0, val);
67 }
68 catch(com.sun.star.io.IOException e) {
69 fail("Could not load document");
70 }
71 catch(com.sun.star.lang.IllegalArgumentException e) {
72 fail("Could not load document");
73 }
74
75 // try again: headless mode defect now?
76 try {
77 xDesktopLoader.loadComponentFromURL(fileUrl, "_blank", 0, val);
78 }
79 catch(com.sun.star.io.IOException e) {
80 fail("Could not load document");
81 }
82 catch(com.sun.star.lang.IllegalArgumentException e) {
83 fail("Could not load document");
84 }
85
86 }
87
88 private XMultiServiceFactory getMSF()
89 {
90 return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
91 }
92
93 // setup and close connections
94 @BeforeClass public static void setUpConnection() throws Exception {
95 System.out.println("setUpConnection()");
96 connection.setUp();
97 }
98
99 @AfterClass public static void tearDownConnection()
100 throws InterruptedException, com.sun.star.uno.Exception
101 {
102 System.out.println("tearDownConnection()");
103 connection.tearDown();
104 }
105
106 private static final OfficeConnection connection = new OfficeConnection();
107
108 }