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 
28 package lib;
29 
30 /**
31  * The class is a simple implementation of Status class. It implements simple
32  * Status behaviour: its state, reason and log are defined when creating
33  * the SimpleSTatus instance.
34  */
35 class SimpleStatus {
36     /* Run states. */
37 
38     /**
39      * The constatnt represents PASSED runtime state.
40      */
41     public final static int PASSED = 0;
42 
43     /**
44      * The constant represents EXCEPTION runtime state.
45      */
46     public final static int EXCEPTION = 3;
47 
48     /**
49      * The constant represents EXCLUDED runtime state.
50      */
51     public final static int EXCLUDED = 2;
52 
53     /**
54      * The constant represents SKIPPED runtime state.
55      */
56     public final static int SKIPPED = 1;
57 
58     /**
59      * This is a private indicator for a user defined runtime state
60      */
61     private final static int USER_DEFINED = 4;
62 
63     /* Test states */
64 
65     /**
66      * The constant represents FAILED state.
67      */
68     public final static boolean FAILED = false;
69 
70     /**
71      * The constant represents OK state.
72      */
73     public final static boolean OK = true;
74 
75     /**
76      * The field is holding state of the status.
77      */
78     protected final boolean state;
79 
80     /**
81      * The field is holding reason of the status.
82      */
83     protected final int runState;
84 
85     /**
86      * This is the run state: either SKIPPED, PASSED, etc.
87      * or user defined. Deriving classes can overwrite it for own run states.
88      */
89     protected String runStateString;
90 
91     /**
92      * The constructor initialize state and reason field.
93      */
94     protected SimpleStatus( int runState, boolean state ) {
95         this.state = state;
96         this.runState = runState;
97         if ( runState == PASSED ) {
98             runStateString = "PASSED";
99         } else if ( runState == EXCLUDED ) {
100             runStateString = "EXCLUDED";
101         } else if ( runState == SKIPPED ) {
102             runStateString = "SKIPPED";
103         } else if ( runState == EXCEPTION ) {
104             runStateString = "EXCEPTION";
105         } else {
106             runStateString = "UNKNOWN";
107         }
108     }
109 
110     /**
111      * The constructor initialize state and reson field.
112      */
113     protected SimpleStatus(String runStateString, boolean state) {
114         this.state = state;
115         this.runState = USER_DEFINED;
116         this.runStateString = runStateString;
117     }
118 
119     /**
120      * getState implementation. Just returns the state field value.
121      */
122     public boolean getState() {
123         return state;
124     }
125 
126     /**
127      * getRunState() implementation. Just returns th runState field value.
128      */
129     public int getRunState() {
130         return runState;
131     }
132 
133     /**
134      * getReason implementation. Just returns the reason field value.
135      */
136     public String getRunStateString() {
137         return runStateString;
138     }
139 
140     /**
141      * Get the ressult: passed or failed.
142      */
143     public String getStateString() {
144         if (state)
145             return "OK";
146         return "FAILED";
147 
148     }
149 }