xref: /AOO41X/main/qadevOOo/runner/lib/MultiMethodTest.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package lib;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import java.io.PrintWriter;
30*cdf0e10cSrcweir import java.lang.reflect.Field;
31*cdf0e10cSrcweir import java.lang.reflect.InvocationTargetException;
32*cdf0e10cSrcweir import java.lang.reflect.Method;
33*cdf0e10cSrcweir import java.util.Vector;
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
36*cdf0e10cSrcweir import com.sun.star.uno.XInterface;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir import share.DescEntry;
39*cdf0e10cSrcweir import lib.TestParameters;
40*cdf0e10cSrcweir import stats.Summarizer;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir /**
43*cdf0e10cSrcweir  * The class supports method based interface tests development.
44*cdf0e10cSrcweir  *
45*cdf0e10cSrcweir  * <p>There are some points that should be fulfilled in a subclass to work
46*cdf0e10cSrcweir  * correctly in the multi-method framework:
47*cdf0e10cSrcweir  *
48*cdf0e10cSrcweir  *   1. each subclass schould define a public field named oObj of type tested
49*cdf0e10cSrcweir  *   by the subclass, e.g. 'public XText oObj;'. That field will be initialized
50*cdf0e10cSrcweir  *   by the MultiMethodTest code with the instance of the interface to test.
51*cdf0e10cSrcweir  *   In a case of service testing the field type should be XPropertySet.
52*cdf0e10cSrcweir  *
53*cdf0e10cSrcweir  *   2. for the test of each method of the tested interface(or a property in the
54*cdf0e10cSrcweir  *   case of service testing) should be method with the following signature
55*cdf0e10cSrcweir  *   provided: 'public void _<method name>()', e.g. 'public void _getText()'.
56*cdf0e10cSrcweir  *   The methods will be called by MultiMethodText code using reflection API
57*cdf0e10cSrcweir  *   for each method in the interface description.
58*cdf0e10cSrcweir  *
59*cdf0e10cSrcweir  *   3. to set status for a call 'tRes.tested(String method,
60*cdf0e10cSrcweir  *   boolean result)' should be used. For example 'tRes.tested("getText()",
61*cdf0e10cSrcweir  *   true)'. Also 'tRes.assert(String assertion, boolean result)' call can
62*cdf0e10cSrcweir  *   be used. Note, that one can call the methods not neccesarily from the
63*cdf0e10cSrcweir  *   test for the tested method, but from other method tests too (in the
64*cdf0e10cSrcweir  *   MultiMethodTest subclass). See also TestResult and MultiMethodTest.tRes
65*cdf0e10cSrcweir  *   documentation.
66*cdf0e10cSrcweir  *
67*cdf0e10cSrcweir  *   4. the before() and after() methods can be overriden to perform some
68*cdf0e10cSrcweir  *   actions, accordingly, before and after calling the test methods.
69*cdf0e10cSrcweir  *
70*cdf0e10cSrcweir  *   5. besides tRes, there are some fields initialized in the MultiMethodTest,
71*cdf0e10cSrcweir  *   that can be used for implementing tests:
72*cdf0e10cSrcweir  *
73*cdf0e10cSrcweir  *     - tEnv contains the environment tested
74*cdf0e10cSrcweir  *     - tParam contains parameters of the test
75*cdf0e10cSrcweir  *     - log a writer to log information about the test
76*cdf0e10cSrcweir  *
77*cdf0e10cSrcweir  * @see TestResult
78*cdf0e10cSrcweir  */
79*cdf0e10cSrcweir public class MultiMethodTest
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     /**
83*cdf0e10cSrcweir      * Contains the TestEnvironment being tested, to allow for tests to access
84*cdf0e10cSrcweir      * it.
85*cdf0e10cSrcweir      */
86*cdf0e10cSrcweir     protected TestEnvironment tEnv;
87*cdf0e10cSrcweir     /**
88*cdf0e10cSrcweir      * Contains the TestParameters for the tests, to allow for tests to access
89*cdf0e10cSrcweir      * it.
90*cdf0e10cSrcweir      */
91*cdf0e10cSrcweir     protected TestParameters tParam;
92*cdf0e10cSrcweir     /**
93*cdf0e10cSrcweir      * Contains the Description for the test
94*cdf0e10cSrcweir      * it.
95*cdf0e10cSrcweir      */
96*cdf0e10cSrcweir     protected DescEntry entry;
97*cdf0e10cSrcweir     /**
98*cdf0e10cSrcweir      * Contains a writer to log an information about the interface testing, to
99*cdf0e10cSrcweir      * allows for tests to access it.
100*cdf0e10cSrcweir      */
101*cdf0e10cSrcweir     protected PrintWriter log;
102*cdf0e10cSrcweir     /**
103*cdf0e10cSrcweir      * Contains the TestResult instance for the interface test to collect
104*cdf0e10cSrcweir      * information about methods test.
105*cdf0e10cSrcweir      */
106*cdf0e10cSrcweir     protected TestResult tRes;
107*cdf0e10cSrcweir     /**
108*cdf0e10cSrcweir      * Contains names of the methods have been alreadycalled
109*cdf0e10cSrcweir      */
110*cdf0e10cSrcweir     private Vector methCalled = new Vector(10);
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     /**
113*cdf0e10cSrcweir      * Disposes the test environment, which was corrupted by the test.
114*cdf0e10cSrcweir      *
115*cdf0e10cSrcweir      * @param tEnv the environment to dispose
116*cdf0e10cSrcweir      */
117*cdf0e10cSrcweir     public void disposeEnvironment(TestEnvironment tEnv)
118*cdf0e10cSrcweir     {
119*cdf0e10cSrcweir         disposeEnvironment();
120*cdf0e10cSrcweir     }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     /**
123*cdf0e10cSrcweir      * Disposes the current test environment, which was corrupted by the test.
124*cdf0e10cSrcweir      *
125*cdf0e10cSrcweir      * @see #disposeEnvironment(TestEnvironment)
126*cdf0e10cSrcweir      */
127*cdf0e10cSrcweir     public void disposeEnvironment()
128*cdf0e10cSrcweir     {
129*cdf0e10cSrcweir         tEnv.dispose();
130*cdf0e10cSrcweir         TestCase tCase = tEnv.getTestCase();
131*cdf0e10cSrcweir         tCase.disposeTestEnvironment(tEnv, tParam);
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     /**
135*cdf0e10cSrcweir      * Runs the interface test: its method tests. First, it initializes some
136*cdf0e10cSrcweir      * of MultiMethodTest fields, like tRes, log, tEnv, etc. Then, it queries
137*cdf0e10cSrcweir      * the tested interface and initializes 'oObj' field (defined in a
138*cdf0e10cSrcweir      * subclass). Before calling method tests, before() method calles to allow
139*cdf0e10cSrcweir      * initialization of s stuff before testing. Then, the method tests are
140*cdf0e10cSrcweir      * called. After them, after() method is called, to allow cleaning up the
141*cdf0e10cSrcweir      * stuff initialized in before() and test methods.
142*cdf0e10cSrcweir      *
143*cdf0e10cSrcweir      * @param entry the interface test state
144*cdf0e10cSrcweir      * @param tEnv the environment to test
145*cdf0e10cSrcweir      * @param tParam the parameters of the test
146*cdf0e10cSrcweir      *
147*cdf0e10cSrcweir      * @see #before
148*cdf0e10cSrcweir      * @see #after
149*cdf0e10cSrcweir      */
150*cdf0e10cSrcweir     public TestResult run(DescEntry entry, TestEnvironment tEnv, TestParameters tParam)
151*cdf0e10cSrcweir     {
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir         log = (PrintWriter) entry.Logger;
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir         this.tEnv = tEnv;
156*cdf0e10cSrcweir         this.tParam = tParam;
157*cdf0e10cSrcweir         // this.log = log;
158*cdf0e10cSrcweir         this.entry = entry;
159*cdf0e10cSrcweir         this.tRes = new TestResult();
160*cdf0e10cSrcweir         Class testedClass;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         // Some fake code for a self test.
163*cdf0e10cSrcweir         // For normal test we must not be a "ifc.qadevooo._SelfTest"
164*cdf0e10cSrcweir         if (! entry.entryName.equals("ifc.qadevooo._SelfTest"))
165*cdf0e10cSrcweir         {
166*cdf0e10cSrcweir             String ifcName = getInterfaceName();
167*cdf0e10cSrcweir             // System.out.println("checking : " + ifcName);
168*cdf0e10cSrcweir             System.out.print("checking: [" + entry.longName + "]");
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir             // defining a name of the class corresponding to the tested interface
171*cdf0e10cSrcweir             // or service
172*cdf0e10cSrcweir             String testedClassName;
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir             testedClassName = getTestedClassName();
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir             if (entry.EntryType.equals("service"))
177*cdf0e10cSrcweir             {
178*cdf0e10cSrcweir                 testedClassName = "com.sun.star.beans.XPropertySet";
179*cdf0e10cSrcweir             }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir             try
182*cdf0e10cSrcweir             {
183*cdf0e10cSrcweir                 testedClass = Class.forName(testedClassName);
184*cdf0e10cSrcweir             }
185*cdf0e10cSrcweir             catch (ClassNotFoundException cnfE)
186*cdf0e10cSrcweir             {
187*cdf0e10cSrcweir                 System.out.println();
188*cdf0e10cSrcweir                 cnfE.printStackTrace(log);
189*cdf0e10cSrcweir                 log.println("could not find a class : " + getTestedClassName());
190*cdf0e10cSrcweir                 return null;
191*cdf0e10cSrcweir             }
192*cdf0e10cSrcweir             System.out.println(" is iface: [" + testedClassName + "] testcode: [" + entry.entryName + "]");
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir             // quering the tested interface from the tested object
195*cdf0e10cSrcweir             XInterface tCase = tEnv.getTestObject();
196*cdf0e10cSrcweir             Object oObj = UnoRuntime.queryInterface(testedClass, tEnv.getTestObject());
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir             if (oObj == null)
199*cdf0e10cSrcweir             {
200*cdf0e10cSrcweir                 if (entry.isOptional)
201*cdf0e10cSrcweir                 {
202*cdf0e10cSrcweir                     Summarizer.summarizeDown(entry, "Not supported but optional.OK");
203*cdf0e10cSrcweir                 }
204*cdf0e10cSrcweir                 else
205*cdf0e10cSrcweir                 {
206*cdf0e10cSrcweir                     Summarizer.summarizeDown(entry, "queryInterface returned null.FAILED");
207*cdf0e10cSrcweir                     entry.ErrorMsg = "queryInterface returned null";
208*cdf0e10cSrcweir                     entry.hasErrorMsg = true;
209*cdf0e10cSrcweir                 }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir                 return null;
212*cdf0e10cSrcweir             }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir             //setting the field oObj
215*cdf0e10cSrcweir             setField("oObj", oObj);
216*cdf0e10cSrcweir         }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         // to perform some stuff before all method tests
219*cdf0e10cSrcweir         try
220*cdf0e10cSrcweir         {
221*cdf0e10cSrcweir             before();
222*cdf0e10cSrcweir         }
223*cdf0e10cSrcweir         catch (Exception e)
224*cdf0e10cSrcweir         {
225*cdf0e10cSrcweir             setSubStates(e.toString());
226*cdf0e10cSrcweir             return tRes;
227*cdf0e10cSrcweir         }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir         // executing methods tests
230*cdf0e10cSrcweir         for (int i = 0; i < entry.SubEntryCount; i++)
231*cdf0e10cSrcweir         {
232*cdf0e10cSrcweir             DescEntry aSubEntry = entry.SubEntries[i];
233*cdf0e10cSrcweir             try
234*cdf0e10cSrcweir             {
235*cdf0e10cSrcweir                 final String sEntryName = aSubEntry.entryName;
236*cdf0e10cSrcweir                 executeMethod(sEntryName);
237*cdf0e10cSrcweir             }
238*cdf0e10cSrcweir             catch (Exception e)
239*cdf0e10cSrcweir             {
240*cdf0e10cSrcweir                 log.println("Exception while checking: " + aSubEntry.entryName + " : " + e.getMessage());
241*cdf0e10cSrcweir             }
242*cdf0e10cSrcweir         }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir         // to perform some stuff after all method tests
245*cdf0e10cSrcweir         try
246*cdf0e10cSrcweir         {
247*cdf0e10cSrcweir             after();
248*cdf0e10cSrcweir         }
249*cdf0e10cSrcweir         catch (Exception e)
250*cdf0e10cSrcweir         {
251*cdf0e10cSrcweir         }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir         return tRes;
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir     /**
257*cdf0e10cSrcweir      * Is called before calling method tests, but after initialization.
258*cdf0e10cSrcweir      * Subclasses may override to perform actions before method tests.
259*cdf0e10cSrcweir      */
260*cdf0e10cSrcweir     protected void before()
261*cdf0e10cSrcweir     {
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     /**
265*cdf0e10cSrcweir      * Is called after calling method tests. Subclasses may override
266*cdf0e10cSrcweir      * to perform actions after method tests.
267*cdf0e10cSrcweir      */
268*cdf0e10cSrcweir     protected void after()
269*cdf0e10cSrcweir     {
270*cdf0e10cSrcweir     }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     /**
273*cdf0e10cSrcweir      * @return the name of the interface or the service tested.
274*cdf0e10cSrcweir      */
275*cdf0e10cSrcweir     protected String getTestedClassName()
276*cdf0e10cSrcweir     {
277*cdf0e10cSrcweir         String clsName = this.getClass().getName();
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir         int firstDot = clsName.indexOf(".");
280*cdf0e10cSrcweir         int lastDot = clsName.lastIndexOf(".");
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir         String append = "com.sun.star.";
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir         if (entry.longName.indexOf("::drafts::com::") > -1)
285*cdf0e10cSrcweir         {
286*cdf0e10cSrcweir             append = "drafts.com.sun.star.";
287*cdf0e10cSrcweir         }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir         return append + clsName.substring(firstDot + 1, lastDot + 1) + clsName.substring(lastDot + 2);
290*cdf0e10cSrcweir     }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     /**
293*cdf0e10cSrcweir      * Sets a method status.
294*cdf0e10cSrcweir      *
295*cdf0e10cSrcweir      * @param methName the method name to set status
296*cdf0e10cSrcweir      * @param methStatus the status to set to the method
297*cdf0e10cSrcweir      */
298*cdf0e10cSrcweir     protected void setStatus(String methName, Status methStatus)
299*cdf0e10cSrcweir     {
300*cdf0e10cSrcweir         tRes.tested(methName, methStatus);
301*cdf0e10cSrcweir     }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     /**
304*cdf0e10cSrcweir      * sets the substates
305*cdf0e10cSrcweir      */
306*cdf0e10cSrcweir     protected void setSubStates(String msg)
307*cdf0e10cSrcweir     {
308*cdf0e10cSrcweir         for (int k = 0; k < entry.SubEntryCount; k++)
309*cdf0e10cSrcweir         {
310*cdf0e10cSrcweir             entry.SubEntries[k].hasErrorMsg = true;
311*cdf0e10cSrcweir             entry.SubEntries[k].ErrorMsg = msg;
312*cdf0e10cSrcweir             if (entry.SubEntries[k].State.equals("UNKNOWN"))
313*cdf0e10cSrcweir             {
314*cdf0e10cSrcweir                 entry.SubEntries[k].State = msg;
315*cdf0e10cSrcweir             }
316*cdf0e10cSrcweir         }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir     /**
321*cdf0e10cSrcweir      * Checks if the <code>method</code> is optional in the service.
322*cdf0e10cSrcweir      */
323*cdf0e10cSrcweir     protected boolean isOptional(String _method)
324*cdf0e10cSrcweir     {
325*cdf0e10cSrcweir         for (int k = 0; k < entry.SubEntryCount; k++)
326*cdf0e10cSrcweir         {
327*cdf0e10cSrcweir             final String sName = entry.SubEntries[k].entryName;
328*cdf0e10cSrcweir             if (sName.equals(_method))
329*cdf0e10cSrcweir             {
330*cdf0e10cSrcweir                 final boolean bIsOptional = entry.SubEntries[k].isOptional;
331*cdf0e10cSrcweir                 return bIsOptional;
332*cdf0e10cSrcweir             }
333*cdf0e10cSrcweir         }
334*cdf0e10cSrcweir         return false;
335*cdf0e10cSrcweir     }
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir     /**
338*cdf0e10cSrcweir      * Checks if the <code>method</code> test has been already called.
339*cdf0e10cSrcweir      */
340*cdf0e10cSrcweir     protected boolean isCalled(String method)
341*cdf0e10cSrcweir     {
342*cdf0e10cSrcweir         return methCalled.contains(method);
343*cdf0e10cSrcweir     }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir     /**
346*cdf0e10cSrcweir      * Calling of the method indicates that the <code>method</code> test should
347*cdf0e10cSrcweir      * be called. The method checks this and if it is not called, calls it.
348*cdf0e10cSrcweir      * If the method is failed or skipped, it throws StatusException.
349*cdf0e10cSrcweir      */
350*cdf0e10cSrcweir     protected void requiredMethod(String method)
351*cdf0e10cSrcweir     {
352*cdf0e10cSrcweir         log.println("starting required method: " + method);
353*cdf0e10cSrcweir         executeMethod(method);
354*cdf0e10cSrcweir         Status mtStatus = tRes.getStatusFor(method);
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir         if (mtStatus != null && (!mtStatus.isPassed() || mtStatus.isFailed()))
357*cdf0e10cSrcweir         {
358*cdf0e10cSrcweir             log.println("! Required method " + method + " failed");
359*cdf0e10cSrcweir             throw new StatusException(mtStatus);
360*cdf0e10cSrcweir         }
361*cdf0e10cSrcweir     }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir     /**
364*cdf0e10cSrcweir      * Checks if the <code>method</code> was called, and if not, call it.
365*cdf0e10cSrcweir      * On contrary to requiredMethod(), he method doesn't check its status.
366*cdf0e10cSrcweir      */
367*cdf0e10cSrcweir     protected void executeMethod(String method)
368*cdf0e10cSrcweir     {
369*cdf0e10cSrcweir         if (!isCalled(method))
370*cdf0e10cSrcweir         {
371*cdf0e10cSrcweir             log.println("Execute: " + method);
372*cdf0e10cSrcweir             callMethod(method);
373*cdf0e10cSrcweir             log.println(method + ": " + tRes.getStatusFor(method));
374*cdf0e10cSrcweir             log.println();
375*cdf0e10cSrcweir         }
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir     /**
379*cdf0e10cSrcweir      * Just calls the <code>method</code> test.
380*cdf0e10cSrcweir      */
381*cdf0e10cSrcweir     protected void callMethod(String method)
382*cdf0e10cSrcweir     {
383*cdf0e10cSrcweir         methCalled.add(method);
384*cdf0e10cSrcweir         invokeTestMethod(getMethodFor(method), method);
385*cdf0e10cSrcweir     }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir     /**
388*cdf0e10cSrcweir      * Invokes a test method of the subclass using reflection API. Handles
389*cdf0e10cSrcweir      * the method results and sets its status.
390*cdf0e10cSrcweir      *
391*cdf0e10cSrcweir      * @param meth the subclass' method to invoke
392*cdf0e10cSrcweir      * @param methName the name of the method
393*cdf0e10cSrcweir      */
394*cdf0e10cSrcweir     protected void invokeTestMethod(Method meth, String methName)
395*cdf0e10cSrcweir     {
396*cdf0e10cSrcweir         if (meth == null)
397*cdf0e10cSrcweir         {
398*cdf0e10cSrcweir             setStatus(methName, Status.skipped(false));
399*cdf0e10cSrcweir         }
400*cdf0e10cSrcweir         else
401*cdf0e10cSrcweir         {
402*cdf0e10cSrcweir             Status stat;
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir             try
405*cdf0e10cSrcweir             {
406*cdf0e10cSrcweir                 meth.invoke(this, new Object[0]);
407*cdf0e10cSrcweir                 return;
408*cdf0e10cSrcweir             }
409*cdf0e10cSrcweir             catch (InvocationTargetException itE)
410*cdf0e10cSrcweir             {
411*cdf0e10cSrcweir                 Throwable t = itE.getTargetException();
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir                 if (t instanceof StatusException)
414*cdf0e10cSrcweir                 {
415*cdf0e10cSrcweir                     stat = ((StatusException) t).getStatus();
416*cdf0e10cSrcweir                 }
417*cdf0e10cSrcweir                 else
418*cdf0e10cSrcweir                 {
419*cdf0e10cSrcweir                     t.printStackTrace(log);
420*cdf0e10cSrcweir                     stat = Status.exception(t);
421*cdf0e10cSrcweir                 }
422*cdf0e10cSrcweir             }
423*cdf0e10cSrcweir             catch (IllegalAccessException iaE)
424*cdf0e10cSrcweir             {
425*cdf0e10cSrcweir                 iaE.printStackTrace(log);
426*cdf0e10cSrcweir                 stat = Status.exception(iaE);
427*cdf0e10cSrcweir             }
428*cdf0e10cSrcweir             catch (IllegalArgumentException iaE)
429*cdf0e10cSrcweir             {
430*cdf0e10cSrcweir                 iaE.printStackTrace(log);
431*cdf0e10cSrcweir                 stat = Status.exception(iaE);
432*cdf0e10cSrcweir             }
433*cdf0e10cSrcweir             catch (ClassCastException ccE)
434*cdf0e10cSrcweir             {
435*cdf0e10cSrcweir                 ccE.printStackTrace(log);
436*cdf0e10cSrcweir                 stat = Status.exception(ccE);
437*cdf0e10cSrcweir             }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir             setStatus(methName, stat);
440*cdf0e10cSrcweir         }
441*cdf0e10cSrcweir     }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir     /**
444*cdf0e10cSrcweir      * Finds a testing method for the <code>method</code> of the interface.
445*cdf0e10cSrcweir      *
446*cdf0e10cSrcweir      * @return the testing method, if found, <tt>null</tt> otherwise
447*cdf0e10cSrcweir      */
448*cdf0e10cSrcweir     protected Method getMethodFor(String method)
449*cdf0e10cSrcweir     {
450*cdf0e10cSrcweir         String mName = "_" + method;
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir         if (mName.endsWith("()"))
453*cdf0e10cSrcweir         {
454*cdf0e10cSrcweir             mName = mName.substring(0, mName.length() - 2);
455*cdf0e10cSrcweir         }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir         final Class[] paramTypes = new Class[0];
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir         try
460*cdf0e10cSrcweir         {
461*cdf0e10cSrcweir             return this.getClass().getDeclaredMethod(mName, paramTypes);
462*cdf0e10cSrcweir         }
463*cdf0e10cSrcweir         catch (NoSuchMethodException nsmE)
464*cdf0e10cSrcweir         {
465*cdf0e10cSrcweir             return null;
466*cdf0e10cSrcweir         }
467*cdf0e10cSrcweir     }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir     /**
470*cdf0e10cSrcweir      * @return the name of the interface tested
471*cdf0e10cSrcweir      */
472*cdf0e10cSrcweir     public String getInterfaceName()
473*cdf0e10cSrcweir     {
474*cdf0e10cSrcweir         String clName = this.getClass().getName();
475*cdf0e10cSrcweir         return clName.substring(clName.lastIndexOf('.') + 1);
476*cdf0e10cSrcweir     }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir     /**
479*cdf0e10cSrcweir      * Initializes <code>fieldName</code> of the subclass with
480*cdf0e10cSrcweir      * <code>value</code>.
481*cdf0e10cSrcweir      *
482*cdf0e10cSrcweir      * @return Status describing the result of the operation.
483*cdf0e10cSrcweir      */
484*cdf0e10cSrcweir     protected Status setField(String fieldName, Object value)
485*cdf0e10cSrcweir     {
486*cdf0e10cSrcweir         Field objField;
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir         try
489*cdf0e10cSrcweir         {
490*cdf0e10cSrcweir             objField = this.getClass().getField(fieldName);
491*cdf0e10cSrcweir         }
492*cdf0e10cSrcweir         catch (NoSuchFieldException nsfE)
493*cdf0e10cSrcweir         {
494*cdf0e10cSrcweir             return Status.exception(nsfE);
495*cdf0e10cSrcweir         }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir         try
498*cdf0e10cSrcweir         {
499*cdf0e10cSrcweir             objField.set(this, value);
500*cdf0e10cSrcweir             return Status.passed(true);
501*cdf0e10cSrcweir         }
502*cdf0e10cSrcweir         catch (IllegalArgumentException iaE)
503*cdf0e10cSrcweir         {
504*cdf0e10cSrcweir             return Status.exception(iaE);
505*cdf0e10cSrcweir         }
506*cdf0e10cSrcweir         catch (IllegalAccessException iaE)
507*cdf0e10cSrcweir         {
508*cdf0e10cSrcweir             return Status.exception(iaE);
509*cdf0e10cSrcweir         }
510*cdf0e10cSrcweir     }
511*cdf0e10cSrcweir }
512