1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package complex.desktop; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 31*cdf0e10cSrcweir import com.sun.star.frame.XDesktop; 32*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 33*cdf0e10cSrcweir import helper.OfficeProvider; 34*cdf0e10cSrcweir //import complex.persistent_window_states.helper.DocumentHandle; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir // ---------- junit imports ----------------- 37*cdf0e10cSrcweir import org.junit.After; 38*cdf0e10cSrcweir import org.junit.AfterClass; 39*cdf0e10cSrcweir import org.junit.Before; 40*cdf0e10cSrcweir import org.junit.BeforeClass; 41*cdf0e10cSrcweir import org.junit.Test; 42*cdf0e10cSrcweir import org.openoffice.test.OfficeConnection; 43*cdf0e10cSrcweir import static org.junit.Assert.*; 44*cdf0e10cSrcweir // ------------------------------------------ 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir /** 47*cdf0e10cSrcweir * Parameters: 48*cdf0e10cSrcweir * <ul> 49*cdf0e10cSrcweir * <li>NoOffice=yes - StarOffice is not started initially.</li> 50*cdf0e10cSrcweir * </ul> 51*cdf0e10cSrcweir */ 52*cdf0e10cSrcweir public class DesktopTerminate 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir private XMultiServiceFactory xMSF; 56*cdf0e10cSrcweir private int iOfficeCloseTime = 1000; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /** 59*cdf0e10cSrcweir * A frunction to tell the framework, which test functions are available. 60*cdf0e10cSrcweir * Right now, it's only 'checkPersistentWindowState'. 61*cdf0e10cSrcweir * @return All test methods. 62*cdf0e10cSrcweir */ 63*cdf0e10cSrcweir // public String[] getTestMethodNames() 64*cdf0e10cSrcweir // { 65*cdf0e10cSrcweir // return new String[] 66*cdf0e10cSrcweir // { 67*cdf0e10cSrcweir // "checkPersistentWindowState" 68*cdf0e10cSrcweir // }; 69*cdf0e10cSrcweir // } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir /** 72*cdf0e10cSrcweir * Test if all available document types change the 73*cdf0e10cSrcweir * persistent Window Attributes 74*cdf0e10cSrcweir * 75*cdf0e10cSrcweir * The test follows basically these steps: 76*cdf0e10cSrcweir * - Create a configuration reader and a componentloader 77*cdf0e10cSrcweir * - Look for all document types in the configuration 78*cdf0e10cSrcweir * - Do for every doc type 79*cdf0e10cSrcweir * - start office 80*cdf0e10cSrcweir * - read configuration attibute settings 81*cdf0e10cSrcweir * - create a new document 82*cdf0e10cSrcweir * - resize the document and close it 83*cdf0e10cSrcweir * - close office 84*cdf0e10cSrcweir * - start office 85*cdf0e10cSrcweir * - read configuration attribute settings 86*cdf0e10cSrcweir * - create another new document 87*cdf0e10cSrcweir * - compare old settings with new ones: should be different 88*cdf0e10cSrcweir * - compare the document size with the resized document: should be equal 89*cdf0e10cSrcweir * - close office 90*cdf0e10cSrcweir * - Test finished 91*cdf0e10cSrcweir */ 92*cdf0e10cSrcweir @Test public void checkPersistentWindowState() 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir try 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir System.out.println("Connect the first time."); 98*cdf0e10cSrcweir // System.out.println("AppExecCommand: " + (String) param.get("AppExecutionCommand")); 99*cdf0e10cSrcweir // System.out.println("ConnString: " + (String) param.get("ConnectionString")); 100*cdf0e10cSrcweir // oProvider = new OfficeProvider(); 101*cdf0e10cSrcweir // iOfficeCloseTime = param.getInt("OfficeCloseTime"); 102*cdf0e10cSrcweir // if (iOfficeCloseTime == 0) 103*cdf0e10cSrcweir // { 104*cdf0e10cSrcweir // iOfficeCloseTime = 1000; 105*cdf0e10cSrcweir // } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir if (!connect()) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir return; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir if (!disconnect()) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir return; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir catch (Exception e) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir e.printStackTrace(); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir private boolean connect() 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir try 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir xMSF = getMSF(); 128*cdf0e10cSrcweir try 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir Thread.sleep(10000); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir catch (java.lang.InterruptedException e) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir catch (java.lang.Exception e) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir System.out.println(e.getClass().getName()); 139*cdf0e10cSrcweir System.out.println("Message: " + e.getMessage()); 140*cdf0e10cSrcweir fail("Cannot connect the Office."); 141*cdf0e10cSrcweir return false; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir return true; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir private boolean disconnect() 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir try 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir XDesktop desk = null; 151*cdf0e10cSrcweir desk = UnoRuntime.queryInterface(XDesktop.class, xMSF.createInstance("com.sun.star.frame.Desktop")); 152*cdf0e10cSrcweir desk.terminate(); 153*cdf0e10cSrcweir System.out.println("Waiting " + iOfficeCloseTime + " milliseconds for the Office to close down"); 154*cdf0e10cSrcweir try 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir Thread.sleep(iOfficeCloseTime); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir catch (java.lang.InterruptedException e) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir xMSF = null; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir catch (java.lang.Exception e) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir e.printStackTrace(); 166*cdf0e10cSrcweir fail("Cannot dispose the Office."); 167*cdf0e10cSrcweir return false; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir return true; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir private XMultiServiceFactory getMSF() 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 176*cdf0e10cSrcweir return xMSF1; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // setup and close connections 180*cdf0e10cSrcweir @BeforeClass public static void setUpConnection() throws Exception { 181*cdf0e10cSrcweir System.out.println("setUpConnection()"); 182*cdf0e10cSrcweir connection.setUp(); 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir @AfterClass public static void tearDownConnection() 186*cdf0e10cSrcweir throws InterruptedException, com.sun.star.uno.Exception 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir System.out.println("tearDownConnection()"); 189*cdf0e10cSrcweir // don't do a tearDown here, desktop is already terminated. 190*cdf0e10cSrcweir // connection.tearDown(); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir private static final OfficeConnection connection = new OfficeConnection(); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir } 196