| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 4 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 10 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
* contributor license agreements. See the NOTICE file distributed |
| 12 |
* with this work for additional information regarding copyright |
| 13 |
* ownership. The ASF licenses this file to you under the Apache |
| 14 |
* License, Version 2.0 (the "License"); you may not use this file |
| 15 |
* except in compliance with the License. You may obtain a copy of |
| 16 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
*/ |
| 18 |
package complex.desktop; |
| 19 |
|
| 20 |
|
| 21 |
import com.sun.star.lang.XMultiServiceFactory; |
| 22 |
import com.sun.star.frame.XDesktop; |
| 23 |
import com.sun.star.uno.UnoRuntime; |
| 24 |
import org.junit.AfterClass; |
| 25 |
import org.junit.BeforeClass; |
| 26 |
import org.junit.Test; |
| 27 |
import org.openoffice.test.OfficeConnection; |
| 28 |
import static org.junit.Assert.*; |
| 29 |
|
| 30 |
|
| 31 |
/** |
| 32 |
* Parameters: |
| 33 |
* <ul> |
| 34 |
* <li>NoOffice=yes - StarOffice is not started initially.</li> |
| 35 |
* </ul> |
| 36 |
*/ |
| 37 |
public class DesktopTerminate |
| 38 |
{ |
| 39 |
|
| 40 |
private XMultiServiceFactory xMSF; |
| 41 |
private static final int iOfficeCloseTime = 1000; |
| 42 |
|
| 43 |
/** |
| 44 |
* Test if all available document types change the |
| 45 |
* persistent Window Attributes |
| 46 |
* |
| 47 |
* The test follows basically these steps: |
| 48 |
* - Create a configuration reader and a componentloader |
| 49 |
* - Look for all document types in the configuration |
| 50 |
* - Do for every doc type |
| 51 |
* - start office |
| 52 |
* - read configuration attribute settings |
| 53 |
* - create a new document |
| 54 |
* - resize the document and close it |
| 55 |
* - close office |
| 56 |
* - start office |
| 57 |
* - read configuration attribute settings |
| 58 |
* - create another new document |
| 59 |
* - compare old settings with new ones: should be different |
| 60 |
* - compare the document size with the resized document: should be equal |
| 61 |
* - close office |
| 62 |
* - Test finished |
| 63 |
*/ |
| 64 |
@Test public void checkPersistentWindowState() |
| 65 |
{ |
| 66 |
try |
| 67 |
{ |
| 68 |
|
| 69 |
System.out.println("Connect the first time."); |
| 70 |
|
| 71 |
if (!connect()) |
| 72 |
{ |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
if (!disconnect()) |
| 77 |
{ |
| 78 |
return; |
| 79 |
} |
| 80 |
} |
| 81 |
catch (Exception e) |
| 82 |
{ |
| 83 |
e.printStackTrace(); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
private boolean connect() |
| 88 |
{ |
| 89 |
try |
| 90 |
{ |
| 91 |
xMSF = getMSF(); |
| 92 |
util.utils.pause(10000); |
| 93 |
} |
| 94 |
catch (java.lang.Exception e) |
| 95 |
{ |
| 96 |
System.out.println(e.getClass().getName()); |
| 97 |
System.out.println("Message: " + e.getMessage()); |
| 98 |
fail("Cannot connect the Office."); |
| 99 |
return false; |
| 100 |
} |
| 101 |
return true; |
| 102 |
} |
| 103 |
|
| 104 |
private boolean disconnect() |
| 105 |
{ |
| 106 |
try |
| 107 |
{ |
| 108 |
XDesktop desk = null; |
| 109 |
desk = UnoRuntime.queryInterface(XDesktop.class, xMSF.createInstance("com.sun.star.frame.Desktop")); |
| 110 |
desk.terminate(); |
| 111 |
System.out.println("Waiting " + iOfficeCloseTime + " milliseconds for the Office to close down"); |
| 112 |
util.utils.pause(iOfficeCloseTime); |
| 113 |
xMSF = null; |
| 114 |
} |
| 115 |
catch (java.lang.Exception e) |
| 116 |
{ |
| 117 |
e.printStackTrace(); |
| 118 |
fail("Cannot dispose the Office."); |
| 119 |
return false; |
| 120 |
} |
| 121 |
return true; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
private XMultiServiceFactory getMSF() |
| 126 |
{ |
| 127 |
return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); |
| 128 |
} |
| 129 |
|
| 130 |
// setup and close connections |
| 131 |
@BeforeClass public static void setUpConnection() throws Exception { |
| 132 |
System.out.println("setUpConnection()"); |
| 133 |
connection.setUp(); |
| 134 |
} |
| 135 |
|
| 136 |
@AfterClass public static void tearDownConnection() |
| 137 |
{ |
| 138 |
System.out.println("tearDownConnection()"); |
| 139 |
// don't do a tearDown here, desktop is already terminated. |
| 140 |
} |
| 141 |
|
| 142 |
private static final OfficeConnection connection = new OfficeConnection(); |
| 143 |
|
| 144 |
} |