1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._dbaccess;
25 
26 import java.io.PrintWriter;
27 
28 import lib.Status;
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 
38 /**
39  * Test for object which is represented by service
40  * <code>com.sun.star.sdb.ErrorMessageDialog</code>. <p>
41  * Object implements the following interfaces :
42  * <ul>
43  *  <li> <code>com::sun::star::lang::XInitialization</code></li>
44  *  <li> <code>com::sun::star::sdb::ErrorMessageDialog</code></li>
45  *  <li> <code>com::sun::star::ui::dialogs::XExecutableDialog</code></li>
46  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
47  * </ul> <p>
48  * This object test <b> is NOT </b> designed to be run in several
49  * threads concurently.
50  *
51  * @see com.sun.star.lang.XInitialization
52  * @see com.sun.star.sdb.ErrorMessageDialog
53  * @see com.sun.star.ui.dialogs.XExecutableDialog
54  * @see com.sun.star.beans.XPropertySet
55  * @see ifc.lang._XInitialization
56  * @see ifc.sdb._ErrorMessageDialog
57  * @see ifc.ui.dialogs._XExecutableDialog
58  * @see ifc.beans._XPropertySet
59  */
60 public class OSQLMessageDialog extends TestCase {
61 
62     /**
63      * Creating a Testenvironment for the interfaces to be tested.
64      *
65      * Creates an instance of the service
66      * <code>com.sun.star.sdb.ErrorMessageDialog</code>.
67      *     Object relations created :
68      * <ul>
69      *  <li> <code>'ERR1', 'ERR2'</code> for
70      *      {@link ifc.sdb._ErrorMessageDialog} </li>
71      * </ul>
72      */
createTestEnvironment( TestParameters Param, PrintWriter log )73     public TestEnvironment createTestEnvironment( TestParameters Param,
74         PrintWriter log ) throws StatusException {
75         XInterface oObj = null;
76         Object oInterface = null;
77 
78         Object err1 = null;
79         Object err2 = null;
80 
81         try {
82             oInterface = ((XMultiServiceFactory)Param.getMSF()).createInstance(
83                             "com.sun.star.sdb.ErrorMessageDialog" );
84 
85             err1 = new com.sun.star.sdbc.SQLException("err1");
86             err2 = new com.sun.star.sdbc.SQLException("err2");
87         }
88         catch( com.sun.star.uno.Exception e ) {
89             log.println("Service not available" );
90             throw new StatusException("Service not available", e) ;
91         }
92 
93         if (oInterface == null) {
94             log.println("Service wasn't created") ;
95             throw new StatusException(Status.failed("Service wasn't created")) ;
96         }
97 
98         oObj = (XInterface) oInterface;
99 
100         // create XWindow for Object relations...
101         com.sun.star.awt.XToolkit xToolkit = null;
102 
103         try{
104             xToolkit = (com.sun.star.awt.XToolkit)UnoRuntime.queryInterface(
105                         com.sun.star.awt.XToolkit.class,
106             ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.awt.Toolkit") );
107         } catch (com.sun.star.uno.Exception e){
108             log.println("could not create instacne of 'com.sun.star.awt.Toolkit'" );
109             throw new StatusException("could not create instacne of 'com.sun.star.awt.Toolkit'", e) ;
110         }
111 
112         // Describe the properties of the container window.
113         com.sun.star.awt.WindowDescriptor aDescriptor =
114         new com.sun.star.awt.WindowDescriptor();
115 
116         aDescriptor.Type              = com.sun.star.awt.WindowClass.TOP ;
117         aDescriptor.WindowServiceName = "window" ;
118         aDescriptor.ParentIndex       = -1;
119         aDescriptor.Parent            = null;
120         aDescriptor.Bounds            = new com.sun.star.awt.Rectangle(0,0,0,0);
121 
122         aDescriptor.WindowAttributes  =
123         com.sun.star.awt.WindowAttribute.BORDER    |
124         com.sun.star.awt.WindowAttribute.MOVEABLE  |
125         com.sun.star.awt.WindowAttribute.SIZEABLE  |
126         com.sun.star.awt.WindowAttribute.CLOSEABLE ;
127 
128         com.sun.star.awt.XWindowPeer xPeer = null;
129         try{
130 
131             xPeer = xToolkit.createWindow(aDescriptor) ;
132 
133         } catch (com.sun.star.lang.IllegalArgumentException e){
134             log.println("could not create window" );
135             throw new StatusException("could not create window", e) ;
136         }
137 
138         com.sun.star.awt.XWindow xWindow = (com.sun.star.awt.XWindow)UnoRuntime.queryInterface (
139         com.sun.star.awt.XWindow .class, xPeer);
140 
141         log.println( "    creating a new environment for object" );
142         TestEnvironment tEnv = new TestEnvironment( oObj );
143 
144         log.println("add ObjectRelations err1 and err2 for 'ErrorMessageDialog'");
145         tEnv.addObjRelation("ERR1",err1);
146         tEnv.addObjRelation("ERR2",err2);
147         tEnv.addObjRelation("ERR_XWindow", xWindow);
148 
149         return tEnv;
150     } // finish method getTestEnvironment
151 
152 } // finish class OSQLMessageDialog
153 
154