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 
28*cdf0e10cSrcweir package lib;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import java.util.Hashtable;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir /**
33*cdf0e10cSrcweir  * The class supports interface tests development and Status calculation.
34*cdf0e10cSrcweir  */
35*cdf0e10cSrcweir public class TestResult {
36*cdf0e10cSrcweir     /**
37*cdf0e10cSrcweir      * Contains methods having been tested and their results.
38*cdf0e10cSrcweir      */
39*cdf0e10cSrcweir     protected Hashtable testedMethods = new Hashtable();
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir     /**
42*cdf0e10cSrcweir      * The method makes method tested with the result, i.e. it adds to its
43*cdf0e10cSrcweir      * state OK (if result == true) or FAILED (if result == false) status
44*cdf0e10cSrcweir      * and makes the state of the method completed. It's equal to
45*cdf0e10cSrcweir      * tested(method, Status(result)) call.
46*cdf0e10cSrcweir      *
47*cdf0e10cSrcweir      * @param method reffers to the method whoch was tested
48*cdf0e10cSrcweir      * @param result the result of testing the method
49*cdf0e10cSrcweir      *
50*cdf0e10cSrcweir      * @return the result value
51*cdf0e10cSrcweir      *
52*cdf0e10cSrcweir      * @throw java.lang.IllegalArgumentException if the method is not
53*cdf0e10cSrcweir      * available in the interface.
54*cdf0e10cSrcweir      *
55*cdf0e10cSrcweir      * @see #tested(String, Status)
56*cdf0e10cSrcweir      */
57*cdf0e10cSrcweir     public boolean tested( String method, boolean result) {
58*cdf0e10cSrcweir         System.out.println("Method "+method+" finished with state "+(result?"OK":"FAILED"));
59*cdf0e10cSrcweir         return tested( method, Status.passed( result ) );
60*cdf0e10cSrcweir     }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir     /**
63*cdf0e10cSrcweir      * The method makes the method tested with the status, i.e. it adds the
64*cdf0e10cSrcweir      * status to its state and makes it completed.
65*cdf0e10cSrcweir      *
66*cdf0e10cSrcweir      * @param method reffers to the method whoch was tested
67*cdf0e10cSrcweir      * @param status describes the result of testing the method
68*cdf0e10cSrcweir      * @return <tt>true</tt> if status is OK, <tt>false</tt> otherwise.
69*cdf0e10cSrcweir      *
70*cdf0e10cSrcweir      * @throw java.lang.IllegalArgumentException if the method is not
71*cdf0e10cSrcweir      * available in the interface.
72*cdf0e10cSrcweir      */
73*cdf0e10cSrcweir     public boolean tested( String method, Status status ) {
74*cdf0e10cSrcweir     	testedMethods.put(method,status);
75*cdf0e10cSrcweir         return true;
76*cdf0e10cSrcweir     }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     /**
79*cdf0e10cSrcweir      * @return methods available in the interface tested.
80*cdf0e10cSrcweir      */
81*cdf0e10cSrcweir     public String[] getTestedMethods() {
82*cdf0e10cSrcweir         return (String[])testedMethods.keySet().toArray(
83*cdf0e10cSrcweir                 new String[testedMethods.size()]);
84*cdf0e10cSrcweir     }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     /**
87*cdf0e10cSrcweir      * @return <tt>true</tt> if the method belongs to the interface tested,
88*cdf0e10cSrcweir      * <tt>false</tt> otherwise.
89*cdf0e10cSrcweir      */
90*cdf0e10cSrcweir     public boolean hasMethod( String method ) {
91*cdf0e10cSrcweir         return testedMethods.containsKey( method );
92*cdf0e10cSrcweir     }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     /**
95*cdf0e10cSrcweir      * @return status of testing the method, if it is available (was set by
96*cdf0e10cSrcweir      * the tested or assert method), <tt>null</tt> otherwise.
97*cdf0e10cSrcweir      *
98*cdf0e10cSrcweir      * @see #tested(String, boolean)
99*cdf0e10cSrcweir      * @see #tested(String, Status)
100*cdf0e10cSrcweir      * @see #assert
101*cdf0e10cSrcweir      */
102*cdf0e10cSrcweir     public Status getStatusFor( String method ) {
103*cdf0e10cSrcweir         return (Status)testedMethods.get( method );
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir }