1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package complex.disposing;
24 
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.frame.XDesktop;
28 
29 // ---------- junit imports -----------------
30 import org.junit.After;
31 import org.junit.AfterClass;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.openoffice.test.OfficeConnection;
36 import static org.junit.Assert.*;
37 // ------------------------------------------
38 
39 /**
40  * This test is for bug110698. The Office is closed and is continually connected
41  * while it closes. This did let the Office freeze. Now when the Office is
42  * closed, the connection is refused.
43  */
44 public class GetServiceWhileDisposingOffice
45 {
46 
47 //    public String[] getTestMethodNames()
48 //    {
49 //        return new String[]
50 //                {
51 //                    "checkServiceWhileDisposing"
52 //                };
53 //    }
54 
55     @Test public void checkServiceWhileDisposing()
56     {
57         XMultiServiceFactory xMSF = getMSF();
58         XDesktop xDesktop = null;
59 
60         try
61         {
62             xDesktop = UnoRuntime.queryInterface(XDesktop.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
63         }
64         catch (com.sun.star.uno.Exception e)
65         {
66             fail("Could not create a desktop instance.");
67         }
68         int step = 0;
69         try
70         {
71             System.out.println("Start the termination of the Office.");
72             xDesktop.terminate();
73             for (; step < 10000; step++)
74             {
75                 Object o = xMSF.createInstance("com.sun.star.frame.Desktop");
76             }
77         }
78         catch (com.sun.star.lang.DisposedException e)
79         {
80             System.out.println("DisposedException in step: " + step);
81         }
82         catch (Exception e)
83         {
84             fail(e.getMessage());
85         }
86 
87     }
88 
89 
90        private XMultiServiceFactory getMSF()
91     {
92         final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
93         return xMSF1;
94     }
95 
96     // setup and close connections
97     @BeforeClass
98     public static void setUpConnection() throws Exception
99     {
100         System.out.println("setUpConnection()");
101         connection.setUp();
102     }
103 
104     @AfterClass
105     public static void tearDownConnection()
106             throws InterruptedException, com.sun.star.uno.Exception
107     {
108         System.out.println("tearDownConnection()");
109         // Office is already terminated.
110         // connection.tearDown();
111     }
112     private static final OfficeConnection connection = new OfficeConnection();
113 
114 }
115