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