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 package ifc.form;
28 
29 import com.sun.star.form.XDatabaseParameterBroadcaster;
30 import com.sun.star.form.XDatabaseParameterListener;
31 import com.sun.star.sdbc.XRowSet;
32 import com.sun.star.uno.UnoRuntime;
33 import java.io.PrintWriter;
34 import lib.MultiMethodTest;
35 
36 /**
37  *
38  */
39 public class _XDatabaseParameterBroadcaster extends MultiMethodTest {
40 
41     // oObj filled by MultiMethodTest
42     public XDatabaseParameterBroadcaster oObj = null ;
43     private CheckParameterListener listenerChecker = null;
44 
45     /**
46      * Interface to implement so the call of the listener can be checked.
47      */
48     public static interface CheckParameterListener extends XDatabaseParameterListener {
49         /**
50          * Set a log of the listener, so messages of the listener get printed
51          * into the file of the interface
52          */
53         public void setLog(PrintWriter log);
54         /**
55          * Return True, when the listener was called correctly.
56          */
57         public boolean checkListener();
58     }
59 
60     /**
61      * Get the object relation 'ParameterListenerChecker' and
62      * set the log inside of the implementation.
63      */
64     protected void before() {
65         listenerChecker = (CheckParameterListener)
66                         tEnv.getObjRelation("ParameterListenerChecker");
67         listenerChecker.setLog((PrintWriter)log);
68     }
69 
70     /**
71      */
72     public void _addParameterListener() {
73         oObj.addParameterListener(listenerChecker);
74         tRes.tested("addParameterListener()", true);
75     }
76 
77     /**
78      */
79     public void _removeParameterListener() {
80         requiredMethod("addParameterListener()");
81 
82         // trigger the action.
83         try {
84             XRowSet xRowSet = (XRowSet)UnoRuntime.queryInterface(XRowSet.class, oObj);
85             xRowSet.execute();
86         }
87         catch(com.sun.star.sdbc.SQLException e) {
88             log.println("Exception in XDatabaseParameterBroadcaster test.");
89             log.println("This does not let the test fail, but should be inquired.");
90             e.printStackTrace((PrintWriter)log);
91         }
92         // was the listener called?
93         oObj.removeParameterListener(listenerChecker);
94         tRes.tested("removeParameterListener()", listenerChecker.checkListener());
95     }
96 
97     protected void after() {
98         disposeEnvironment();
99     }
100 }
101