1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package complex.broken_document;
28 
29 import com.sun.star.beans.PropertyValue;
30 // import com.sun.star.frame.FrameSearchFlag;
31 import com.sun.star.frame.XComponentLoader;
32 import com.sun.star.frame.XFrame;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.UnoRuntime;
35 
36 
37 // ---------- junit imports -----------------
38 import org.junit.After;
39 import org.junit.AfterClass;
40 import org.junit.Before;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43 import org.openoffice.test.OfficeConnection;
44 import static org.junit.Assert.*;
45 // ------------------------------------------
46 
47 /**
48  * Check, if message boxes appear when the Office is in "headless" mode. Tests
49  * bug i15809. This test uses the broken document dbf.dbf.emf.
50  */
51 public class LoadDocument {
52 
53     /** defect file to load **/
54     // private final String mFileName = "dbf.dbf.emf";
55 
56     /**
57      * Get all test methods.
58      * @return The test methods.
59      */
60 //    public String[] getTestMethodNames() {
61 //        return new String[]{"checkHeadlessState"};
62 //    }
63 
64     /**
65      * Start Office with "-headless" parameter, then
66      * load the broken document "dbf.dbf.emf", that brings a message box up in
67      * the ui, see if the headless mode of SOffice changes.
68      */
69     @Test public void checkHeadlessState()
70     {
71         XMultiServiceFactory xMSF = getMSF();
72         XFrame xDesktop = null;
73 
74         try {
75             xDesktop = UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
76         }
77         catch(com.sun.star.uno.Exception e) {
78             fail("Could not create a desktop instance.");
79         }
80 
81         XComponentLoader xDesktopLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);
82         System.out.println("xDektopLoader is null: " + (xDesktopLoader == null));
83         PropertyValue[] val = new PropertyValue[0];
84 
85         // String workingDir = (String)param.get("WorkingDir") + System.getProperty("file.separator") + mFileName;
86         // System.out.println("Working dir: " + workingDir);
87         String fileUrl = complex.broken_document.TestDocument.getUrl("dbf.dbf.emf");
88         System.out.println("File Url: " + fileUrl);
89 
90         try {
91             xDesktopLoader.loadComponentFromURL(fileUrl, "_blank", 0, val);
92         }
93         catch(com.sun.star.io.IOException e) {
94             fail("Could not load document");
95         }
96         catch(com.sun.star.lang.IllegalArgumentException e) {
97             fail("Could not load document");
98         }
99 
100         // try again: headless mode defect now?
101         try {
102             xDesktopLoader.loadComponentFromURL(fileUrl, "_blank", 0, val);
103         }
104         catch(com.sun.star.io.IOException e) {
105             fail("Could not load document");
106         }
107         catch(com.sun.star.lang.IllegalArgumentException e) {
108             fail("Could not load document");
109         }
110 
111     }
112 
113 
114 
115   private XMultiServiceFactory getMSF()
116     {
117         final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
118         return xMSF1;
119     }
120 
121     // setup and close connections
122     @BeforeClass public static void setUpConnection() throws Exception {
123         System.out.println("setUpConnection()");
124         connection.setUp();
125     }
126 
127     @AfterClass public static void tearDownConnection()
128         throws InterruptedException, com.sun.star.uno.Exception
129     {
130         System.out.println("tearDownConnection()");
131         connection.tearDown();
132     }
133 
134     private static final OfficeConnection connection = new OfficeConnection();
135 
136 }
137