1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski package complex.broken_document; 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski import com.sun.star.beans.PropertyValue; 26*b1cdbd2cSJim Jagielski // import com.sun.star.frame.FrameSearchFlag; 27*b1cdbd2cSJim Jagielski import com.sun.star.frame.XComponentLoader; 28*b1cdbd2cSJim Jagielski import com.sun.star.frame.XFrame; 29*b1cdbd2cSJim Jagielski import com.sun.star.lang.XMultiServiceFactory; 30*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 31*b1cdbd2cSJim Jagielski 32*b1cdbd2cSJim Jagielski 33*b1cdbd2cSJim Jagielski // ---------- junit imports ----------------- 34*b1cdbd2cSJim Jagielski import org.junit.After; 35*b1cdbd2cSJim Jagielski import org.junit.AfterClass; 36*b1cdbd2cSJim Jagielski import org.junit.Before; 37*b1cdbd2cSJim Jagielski import org.junit.BeforeClass; 38*b1cdbd2cSJim Jagielski import org.junit.Test; 39*b1cdbd2cSJim Jagielski import org.openoffice.test.OfficeConnection; 40*b1cdbd2cSJim Jagielski import static org.junit.Assert.*; 41*b1cdbd2cSJim Jagielski // ------------------------------------------ 42*b1cdbd2cSJim Jagielski 43*b1cdbd2cSJim Jagielski /** 44*b1cdbd2cSJim Jagielski * Check, if message boxes appear when the Office is in "headless" mode. Tests 45*b1cdbd2cSJim Jagielski * bug i15809. This test uses the broken document dbf.dbf.emf. 46*b1cdbd2cSJim Jagielski */ 47*b1cdbd2cSJim Jagielski public class LoadDocument { 48*b1cdbd2cSJim Jagielski 49*b1cdbd2cSJim Jagielski /** defect file to load **/ 50*b1cdbd2cSJim Jagielski // private final String mFileName = "dbf.dbf.emf"; 51*b1cdbd2cSJim Jagielski 52*b1cdbd2cSJim Jagielski /** 53*b1cdbd2cSJim Jagielski * Get all test methods. 54*b1cdbd2cSJim Jagielski * @return The test methods. 55*b1cdbd2cSJim Jagielski */ 56*b1cdbd2cSJim Jagielski // public String[] getTestMethodNames() { 57*b1cdbd2cSJim Jagielski // return new String[]{"checkHeadlessState"}; 58*b1cdbd2cSJim Jagielski // } 59*b1cdbd2cSJim Jagielski 60*b1cdbd2cSJim Jagielski /** 61*b1cdbd2cSJim Jagielski * Start Office with "-headless" parameter, then 62*b1cdbd2cSJim Jagielski * load the broken document "dbf.dbf.emf", that brings a message box up in 63*b1cdbd2cSJim Jagielski * the ui, see if the headless mode of SOffice changes. 64*b1cdbd2cSJim Jagielski */ checkHeadlessState()65*b1cdbd2cSJim Jagielski @Test public void checkHeadlessState() 66*b1cdbd2cSJim Jagielski { 67*b1cdbd2cSJim Jagielski XMultiServiceFactory xMSF = getMSF(); 68*b1cdbd2cSJim Jagielski XFrame xDesktop = null; 69*b1cdbd2cSJim Jagielski 70*b1cdbd2cSJim Jagielski try { 71*b1cdbd2cSJim Jagielski xDesktop = UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Desktop")); 72*b1cdbd2cSJim Jagielski } 73*b1cdbd2cSJim Jagielski catch(com.sun.star.uno.Exception e) { 74*b1cdbd2cSJim Jagielski fail("Could not create a desktop instance."); 75*b1cdbd2cSJim Jagielski } 76*b1cdbd2cSJim Jagielski 77*b1cdbd2cSJim Jagielski XComponentLoader xDesktopLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop); 78*b1cdbd2cSJim Jagielski System.out.println("xDektopLoader is null: " + (xDesktopLoader == null)); 79*b1cdbd2cSJim Jagielski PropertyValue[] val = new PropertyValue[0]; 80*b1cdbd2cSJim Jagielski 81*b1cdbd2cSJim Jagielski // String workingDir = (String)param.get("WorkingDir") + System.getProperty("file.separator") + mFileName; 82*b1cdbd2cSJim Jagielski // System.out.println("Working dir: " + workingDir); 83*b1cdbd2cSJim Jagielski String fileUrl = complex.broken_document.TestDocument.getUrl("dbf.dbf.emf"); 84*b1cdbd2cSJim Jagielski System.out.println("File Url: " + fileUrl); 85*b1cdbd2cSJim Jagielski 86*b1cdbd2cSJim Jagielski try { 87*b1cdbd2cSJim Jagielski xDesktopLoader.loadComponentFromURL(fileUrl, "_blank", 0, val); 88*b1cdbd2cSJim Jagielski } 89*b1cdbd2cSJim Jagielski catch(com.sun.star.io.IOException e) { 90*b1cdbd2cSJim Jagielski fail("Could not load document"); 91*b1cdbd2cSJim Jagielski } 92*b1cdbd2cSJim Jagielski catch(com.sun.star.lang.IllegalArgumentException e) { 93*b1cdbd2cSJim Jagielski fail("Could not load document"); 94*b1cdbd2cSJim Jagielski } 95*b1cdbd2cSJim Jagielski 96*b1cdbd2cSJim Jagielski // try again: headless mode defect now? 97*b1cdbd2cSJim Jagielski try { 98*b1cdbd2cSJim Jagielski xDesktopLoader.loadComponentFromURL(fileUrl, "_blank", 0, val); 99*b1cdbd2cSJim Jagielski } 100*b1cdbd2cSJim Jagielski catch(com.sun.star.io.IOException e) { 101*b1cdbd2cSJim Jagielski fail("Could not load document"); 102*b1cdbd2cSJim Jagielski } 103*b1cdbd2cSJim Jagielski catch(com.sun.star.lang.IllegalArgumentException e) { 104*b1cdbd2cSJim Jagielski fail("Could not load document"); 105*b1cdbd2cSJim Jagielski } 106*b1cdbd2cSJim Jagielski 107*b1cdbd2cSJim Jagielski } 108*b1cdbd2cSJim Jagielski 109*b1cdbd2cSJim Jagielski 110*b1cdbd2cSJim Jagielski getMSF()111*b1cdbd2cSJim Jagielski private XMultiServiceFactory getMSF() 112*b1cdbd2cSJim Jagielski { 113*b1cdbd2cSJim Jagielski final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 114*b1cdbd2cSJim Jagielski return xMSF1; 115*b1cdbd2cSJim Jagielski } 116*b1cdbd2cSJim Jagielski 117*b1cdbd2cSJim Jagielski // setup and close connections setUpConnection()118*b1cdbd2cSJim Jagielski @BeforeClass public static void setUpConnection() throws Exception { 119*b1cdbd2cSJim Jagielski System.out.println("setUpConnection()"); 120*b1cdbd2cSJim Jagielski connection.setUp(); 121*b1cdbd2cSJim Jagielski } 122*b1cdbd2cSJim Jagielski tearDownConnection()123*b1cdbd2cSJim Jagielski @AfterClass public static void tearDownConnection() 124*b1cdbd2cSJim Jagielski throws InterruptedException, com.sun.star.uno.Exception 125*b1cdbd2cSJim Jagielski { 126*b1cdbd2cSJim Jagielski System.out.println("tearDownConnection()"); 127*b1cdbd2cSJim Jagielski connection.tearDown(); 128*b1cdbd2cSJim Jagielski } 129*b1cdbd2cSJim Jagielski 130*b1cdbd2cSJim Jagielski private static final OfficeConnection connection = new OfficeConnection(); 131*b1cdbd2cSJim Jagielski 132*b1cdbd2cSJim Jagielski } 133