Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / OSQLMessageDialog.java
blob82099a6c660eb26dd84e8167eb30a984427263ab
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
19 package mod._dbaccess;
21 import java.io.PrintWriter;
23 import lib.Status;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
32 /**
33 * Test for object which is represented by service
34 * <code>com.sun.star.sdb.ErrorMessageDialog</code>. <p>
35 * Object implements the following interfaces :
36 * <ul>
37 * <li> <code>com::sun::star::lang::XInitialization</code></li>
38 * <li> <code>com::sun::star::sdb::ErrorMessageDialog</code></li>
39 * <li> <code>com::sun::star::ui::dialogs::XExecutableDialog</code></li>
40 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
41 * </ul> <p>
42 * This object test <b> is NOT </b> designed to be run in several
43 * threads concurently.
45 * @see com.sun.star.lang.XInitialization
46 * @see com.sun.star.sdb.ErrorMessageDialog
47 * @see com.sun.star.ui.dialogs.XExecutableDialog
48 * @see com.sun.star.beans.XPropertySet
49 * @see ifc.lang._XInitialization
50 * @see ifc.sdb._ErrorMessageDialog
51 * @see ifc.ui.dialogs._XExecutableDialog
52 * @see ifc.beans._XPropertySet
54 public class OSQLMessageDialog extends TestCase {
56 /**
57 * Creating a Testenvironment for the interfaces to be tested.
59 * Creates an instance of the service
60 * <code>com.sun.star.sdb.ErrorMessageDialog</code>.
61 * Object relations created :
62 * <ul>
63 * <li> <code>'ERR1', 'ERR2'</code> for
64 * {@link ifc.sdb._ErrorMessageDialog} </li>
65 * </ul>
67 @Override
68 public TestEnvironment createTestEnvironment( TestParameters Param,
69 PrintWriter log ) throws StatusException {
70 XInterface oObj = null;
71 Object oInterface = null;
73 Object err1 = null;
74 Object err2 = null;
76 try {
77 oInterface = Param.getMSF().createInstance(
78 "com.sun.star.sdb.ErrorMessageDialog" );
80 err1 = new com.sun.star.sdbc.SQLException("err1");
81 err2 = new com.sun.star.sdbc.SQLException("err2");
83 catch( com.sun.star.uno.Exception e ) {
84 log.println("Service not available" );
85 throw new StatusException("Service not available", e) ;
88 if (oInterface == null) {
89 log.println("Service wasn't created") ;
90 throw new StatusException(Status.failed("Service wasn't created")) ;
93 oObj = (XInterface) oInterface;
95 // create XWindow for Object relations...
96 com.sun.star.awt.XToolkit xToolkit = null;
98 try{
99 xToolkit = UnoRuntime.queryInterface(
100 com.sun.star.awt.XToolkit.class,
101 Param.getMSF().createInstance("com.sun.star.awt.Toolkit") );
102 } catch (com.sun.star.uno.Exception e){
103 log.println("could not create instacne of 'com.sun.star.awt.Toolkit'" );
104 throw new StatusException("could not create instacne of 'com.sun.star.awt.Toolkit'", e) ;
107 // Describe the properties of the container window.
108 com.sun.star.awt.WindowDescriptor aDescriptor =
109 new com.sun.star.awt.WindowDescriptor();
111 aDescriptor.Type = com.sun.star.awt.WindowClass.TOP ;
112 aDescriptor.WindowServiceName = "window" ;
113 aDescriptor.ParentIndex = -1;
114 aDescriptor.Parent = null;
115 aDescriptor.Bounds = new com.sun.star.awt.Rectangle(0,0,0,0);
117 aDescriptor.WindowAttributes =
118 com.sun.star.awt.WindowAttribute.BORDER |
119 com.sun.star.awt.WindowAttribute.MOVEABLE |
120 com.sun.star.awt.WindowAttribute.SIZEABLE |
121 com.sun.star.awt.WindowAttribute.CLOSEABLE ;
123 com.sun.star.awt.XWindowPeer xPeer = null;
124 try{
126 xPeer = xToolkit.createWindow(aDescriptor) ;
128 } catch (com.sun.star.lang.IllegalArgumentException e){
129 log.println("could not create window" );
130 throw new StatusException("could not create window", e) ;
133 com.sun.star.awt.XWindow xWindow = UnoRuntime.queryInterface (
134 com.sun.star.awt.XWindow .class, xPeer);
136 log.println( " creating a new environment for object" );
137 TestEnvironment tEnv = new TestEnvironment( oObj );
139 log.println("add ObjectRelations err1 and err2 for 'ErrorMessageDialog'");
140 tEnv.addObjRelation("ERR1",err1);
141 tEnv.addObjRelation("ERR2",err2);
142 tEnv.addObjRelation("ERR_XWindow", xWindow);
144 return tEnv;
145 } // finish method getTestEnvironment
147 } // finish class OSQLMessageDialog