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