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 28 package mod._dbaccess; 29 30 import java.io.PrintWriter; 31 32 import lib.Status; 33 import lib.StatusException; 34 import lib.TestCase; 35 import lib.TestEnvironment; 36 import lib.TestParameters; 37 38 import com.sun.star.lang.XMultiServiceFactory; 39 import com.sun.star.uno.UnoRuntime; 40 import com.sun.star.uno.XInterface; 41 42 /** 43 * Test for object which is represented by service 44 * <code>com.sun.star.sdb.ErrorMessageDialog</code>. <p> 45 * Object implements the following interfaces : 46 * <ul> 47 * <li> <code>com::sun::star::lang::XInitialization</code></li> 48 * <li> <code>com::sun::star::sdb::ErrorMessageDialog</code></li> 49 * <li> <code>com::sun::star::ui::dialogs::XExecutableDialog</code></li> 50 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 51 * </ul> <p> 52 * This object test <b> is NOT </b> designed to be run in several 53 * threads concurently. 54 * 55 * @see com.sun.star.lang.XInitialization 56 * @see com.sun.star.sdb.ErrorMessageDialog 57 * @see com.sun.star.ui.dialogs.XExecutableDialog 58 * @see com.sun.star.beans.XPropertySet 59 * @see ifc.lang._XInitialization 60 * @see ifc.sdb._ErrorMessageDialog 61 * @see ifc.ui.dialogs._XExecutableDialog 62 * @see ifc.beans._XPropertySet 63 */ 64 public class OSQLMessageDialog extends TestCase { 65 66 /** 67 * Creating a Testenvironment for the interfaces to be tested. 68 * 69 * Creates an instance of the service 70 * <code>com.sun.star.sdb.ErrorMessageDialog</code>. 71 * Object relations created : 72 * <ul> 73 * <li> <code>'ERR1', 'ERR2'</code> for 74 * {@link ifc.sdb._ErrorMessageDialog} </li> 75 * </ul> 76 */ 77 public TestEnvironment createTestEnvironment( TestParameters Param, 78 PrintWriter log ) throws StatusException { 79 XInterface oObj = null; 80 Object oInterface = null; 81 82 Object err1 = null; 83 Object err2 = null; 84 85 try { 86 oInterface = ((XMultiServiceFactory)Param.getMSF()).createInstance( 87 "com.sun.star.sdb.ErrorMessageDialog" ); 88 89 err1 = new com.sun.star.sdbc.SQLException("err1"); 90 err2 = new com.sun.star.sdbc.SQLException("err2"); 91 } 92 catch( com.sun.star.uno.Exception e ) { 93 log.println("Service not available" ); 94 throw new StatusException("Service not available", e) ; 95 } 96 97 if (oInterface == null) { 98 log.println("Service wasn't created") ; 99 throw new StatusException(Status.failed("Service wasn't created")) ; 100 } 101 102 oObj = (XInterface) oInterface; 103 104 // create XWindow for Object relations... 105 com.sun.star.awt.XToolkit xToolkit = null; 106 107 try{ 108 xToolkit = (com.sun.star.awt.XToolkit)UnoRuntime.queryInterface( 109 com.sun.star.awt.XToolkit.class, 110 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.awt.Toolkit") ); 111 } catch (com.sun.star.uno.Exception e){ 112 log.println("could not create instacne of 'com.sun.star.awt.Toolkit'" ); 113 throw new StatusException("could not create instacne of 'com.sun.star.awt.Toolkit'", e) ; 114 } 115 116 // Describe the properties of the container window. 117 com.sun.star.awt.WindowDescriptor aDescriptor = 118 new com.sun.star.awt.WindowDescriptor(); 119 120 aDescriptor.Type = com.sun.star.awt.WindowClass.TOP ; 121 aDescriptor.WindowServiceName = "window" ; 122 aDescriptor.ParentIndex = -1; 123 aDescriptor.Parent = null; 124 aDescriptor.Bounds = new com.sun.star.awt.Rectangle(0,0,0,0); 125 126 aDescriptor.WindowAttributes = 127 com.sun.star.awt.WindowAttribute.BORDER | 128 com.sun.star.awt.WindowAttribute.MOVEABLE | 129 com.sun.star.awt.WindowAttribute.SIZEABLE | 130 com.sun.star.awt.WindowAttribute.CLOSEABLE ; 131 132 com.sun.star.awt.XWindowPeer xPeer = null; 133 try{ 134 135 xPeer = xToolkit.createWindow(aDescriptor) ; 136 137 } catch (com.sun.star.lang.IllegalArgumentException e){ 138 log.println("could not create window" ); 139 throw new StatusException("could not create window", e) ; 140 } 141 142 com.sun.star.awt.XWindow xWindow = (com.sun.star.awt.XWindow)UnoRuntime.queryInterface ( 143 com.sun.star.awt.XWindow .class, xPeer); 144 145 log.println( " creating a new environment for object" ); 146 TestEnvironment tEnv = new TestEnvironment( oObj ); 147 148 log.println("add ObjectRelations err1 and err2 for 'ErrorMessageDialog'"); 149 tEnv.addObjRelation("ERR1",err1); 150 tEnv.addObjRelation("ERR2",err2); 151 tEnv.addObjRelation("ERR_XWindow", xWindow); 152 153 return tEnv; 154 } // finish method getTestEnvironment 155 156 } // finish class OSQLMessageDialog 157 158