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.disposing;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
27cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // ---------- junit imports -----------------
30cdf0e10cSrcweir import org.junit.After;
31cdf0e10cSrcweir import org.junit.AfterClass;
32cdf0e10cSrcweir import org.junit.Before;
33cdf0e10cSrcweir import org.junit.BeforeClass;
34cdf0e10cSrcweir import org.junit.Test;
35cdf0e10cSrcweir import org.openoffice.test.OfficeConnection;
36cdf0e10cSrcweir import static org.junit.Assert.*;
37cdf0e10cSrcweir // ------------------------------------------
38cdf0e10cSrcweir 
39cdf0e10cSrcweir /**
40cdf0e10cSrcweir  * This test is for bug110698. The Office is closed and is continually connected
41cdf0e10cSrcweir  * while it closes. This did let the Office freeze. Now when the Office is
42cdf0e10cSrcweir  * closed, the connection is refused.
43cdf0e10cSrcweir  */
44cdf0e10cSrcweir public class GetServiceWhileDisposingOffice
45cdf0e10cSrcweir {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //    public String[] getTestMethodNames()
48cdf0e10cSrcweir //    {
49cdf0e10cSrcweir //        return new String[]
50cdf0e10cSrcweir //                {
51cdf0e10cSrcweir //                    "checkServiceWhileDisposing"
52cdf0e10cSrcweir //                };
53cdf0e10cSrcweir //    }
54cdf0e10cSrcweir 
checkServiceWhileDisposing()55cdf0e10cSrcweir     @Test public void checkServiceWhileDisposing()
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         XMultiServiceFactory xMSF = getMSF();
58cdf0e10cSrcweir         XDesktop xDesktop = null;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         try
61cdf0e10cSrcweir         {
62cdf0e10cSrcweir             xDesktop = UnoRuntime.queryInterface(XDesktop.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
63cdf0e10cSrcweir         }
64cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             fail("Could not create a desktop instance.");
67cdf0e10cSrcweir         }
68cdf0e10cSrcweir         int step = 0;
69cdf0e10cSrcweir         try
70cdf0e10cSrcweir         {
71cdf0e10cSrcweir             System.out.println("Start the termination of the Office.");
72cdf0e10cSrcweir             xDesktop.terminate();
73cdf0e10cSrcweir             for (; step < 10000; step++)
74cdf0e10cSrcweir             {
75cdf0e10cSrcweir                 Object o = xMSF.createInstance("com.sun.star.frame.Desktop");
76cdf0e10cSrcweir             }
77cdf0e10cSrcweir         }
78cdf0e10cSrcweir         catch (com.sun.star.lang.DisposedException e)
79cdf0e10cSrcweir         {
80cdf0e10cSrcweir             System.out.println("DisposedException in step: " + step);
81cdf0e10cSrcweir         }
82cdf0e10cSrcweir         catch (Exception e)
83cdf0e10cSrcweir         {
84cdf0e10cSrcweir             fail(e.getMessage());
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
getMSF()90cdf0e10cSrcweir        private XMultiServiceFactory getMSF()
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
93cdf0e10cSrcweir         return xMSF1;
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     // setup and close connections
97cdf0e10cSrcweir     @BeforeClass
setUpConnection()98cdf0e10cSrcweir     public static void setUpConnection() throws Exception
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         System.out.println("setUpConnection()");
101cdf0e10cSrcweir         connection.setUp();
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     @AfterClass
tearDownConnection()105cdf0e10cSrcweir     public static void tearDownConnection()
106cdf0e10cSrcweir             throws InterruptedException, com.sun.star.uno.Exception
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         System.out.println("tearDownConnection()");
109cdf0e10cSrcweir         // Office is already terminated.
110cdf0e10cSrcweir         // connection.tearDown();
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir     private static final OfficeConnection connection = new OfficeConnection();
113cdf0e10cSrcweir 
114cdf0e10cSrcweir }
115