Update git submodules
[LibreOffice.git] / framework / qa / complex / broken_document / LoadDocument.java
blobc8c8da3b003bbbfeb3b893abae5985184e0b406e
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.broken_document;
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;
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.*;
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.
38 public class LoadDocument {
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.
46 @Test public void checkHeadlessState()
48 XMultiServiceFactory xMSF = getMSF();
49 XFrame xDesktop = null;
51 try {
52 xDesktop = UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
54 catch(com.sun.star.uno.Exception e) {
55 fail("Could not create a desktop instance.");
58 XComponentLoader xDesktopLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);
59 System.out.println("xDesktopLoader is null: " + (xDesktopLoader == null));
60 PropertyValue[] val = new PropertyValue[0];
62 String fileUrl = complex.broken_document.TestDocument.getUrl("dbf.dbf.emf");
63 System.out.println("File Url: " + fileUrl);
65 try {
66 xDesktopLoader.loadComponentFromURL(fileUrl, "_blank", 0, val);
68 catch(com.sun.star.io.IOException e) {
69 fail("Could not load document");
71 catch(com.sun.star.lang.IllegalArgumentException e) {
72 fail("Could not load document");
75 // try again: headless mode defect now?
76 try {
77 xDesktopLoader.loadComponentFromURL(fileUrl, "_blank", 0, val);
79 catch(com.sun.star.io.IOException e) {
80 fail("Could not load document");
82 catch(com.sun.star.lang.IllegalArgumentException e) {
83 fail("Could not load document");
88 private XMultiServiceFactory getMSF()
90 return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
93 // setup and close connections
94 @BeforeClass public static void setUpConnection() throws Exception {
95 System.out.println("setUpConnection()");
96 connection.setUp();
99 @AfterClass public static void tearDownConnection()
100 throws InterruptedException, com.sun.star.uno.Exception
102 System.out.println("tearDownConnection()");
103 connection.tearDown();
106 private static final OfficeConnection connection = new OfficeConnection();