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