Class Status
java.lang.Object
com.sun.javatest.Status
A class to embody the result of a test: a status-code and a related message.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA return code indicating that the test was not run because some error occurred before the test could even be attempted.static final StringA string used to prefix the status when it is written to System.err byexit().static final int[]Exit codes used by Status.exit corresponding to PASSED, FAILED, ERROR, NOT_RUN.static final intA return code indicating that the test was executed but the test reported that it failed.static final intA return code indicating that the test has not yet been run in this context.static final intNumber of states which are predefined as "constants".static final intA return code indicating that the test was executed and was successful. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn a new Status object with a possibly augmented reason field.Return a new Status object with a possibly augmented reason field.static StringDecodes string encoded by encode(String) method.static StringEncodes strings containing non-ascii characters, where all characters are replaced with with their Unicode code.static StatusCreate a Status to indicate that an error occurred while trying to run a test: i.e.voidexit()Convenience exit() function for the main() of tests to exit in such a way that the status passes up across process boundaries without losing information (ie exit codes don't give the associated text of the status and return codes when exceptions are thrown could cause unintended results).static StatusCreate a Status to indicate the unsuccessful outcome of a test: i.e.Get the message given when the status was created.intgetType()Get the type code indicating the type of this Status object.booleanisError()Check if the type code of the status is ERROR.booleanisFailed()Check if the type code of the status is FAILED.booleanisNotRun()Check if the type code of the status is NOT_RUN.booleanisPassed()Check if the type code of the status is PASSED.static StatusnotApplicable(String reason) Deprecated.static StatusParse a string-form of a Status.static StatusCreate a Status to indicate the successful outcome of a test.toString()Convert a Status to a string.static StringtypeToString(int typeNum) Translate the type number to a descriptive string.
-
Field Details
-
PASSED
public static final int PASSEDA return code indicating that the test was executed and was successful.- See Also:
-
FAILED
public static final int FAILEDA return code indicating that the test was executed but the test reported that it failed.- See Also:
-
ERROR
public static final int ERRORA return code indicating that the test was not run because some error occurred before the test could even be attempted. This is generally a more serious error than FAILED.- See Also:
-
NOT_RUN
public static final int NOT_RUNA return code indicating that the test has not yet been run in this context. (More specifically, no status file has been recorded for this test in the current work directory.) This is for the internal use of the harness only.- See Also:
-
NUM_STATES
public static final int NUM_STATESNumber of states which are predefined as "constants".- See Also:
-
EXIT_PREFIX
-
exitCodes
public static final int[] exitCodesExit codes used by Status.exit corresponding to PASSED, FAILED, ERROR, NOT_RUN. The only values that should normally be returned from a test are the first three; the other value is provided for completeness. Note: The assignment is historical and cannot easily be changed.
-
-
Constructor Details
-
Status
Create a Status object. Seepassed(String),failed(String),error(String)etc. for more convenient factory methods to create Status objects.- Parameters:
type- The type code for the Status object.reason- A short string to store in the status. Unprintable characters (i.e. outside the range 040C to 177C) in the string are replaced by a space. All whitespace runs are reduced to a single whitespace.- Throws:
IllegalArgumentException- if the specified type is invalid.
-
-
Method Details
-
passed
-
failed
Create a Status to indicate the unsuccessful outcome of a test: i.e. the test completed, but the test determined that what was being tested did not pass the test.- Parameters:
reason- A short string describing why the test failed.- Returns:
- a Status to indicate the unsuccessful outcome of a test.
-
error
Create a Status to indicate that an error occurred while trying to run a test: i.e. the test did not complete for some reason, and so it could not determine whether what was being tested passed or failed.- Parameters:
reason- A short string describing the error that occurred.- Returns:
- a Status to indicate the error outcome of a test.
-
notApplicable
Deprecated.Create a Status to indicate that the test was not run because under the conditions given it was not applicable. This method is retained for backwards compatibility only; the resultant object is of FAILED type.- Parameters:
reason- A short string describing why the test was not applicable.- Returns:
- a Status to indicate that a test failed because it was not applicable
-
parse
Parse a string-form of a Status.- Parameters:
s- a string containing the string form of a Status as generated bytoString()- Returns:
- the corresponding Status, or null if it could not be parsed successfully
- See Also:
-
typeToString
Translate the type number to a descriptive string. For example, type 0 corresponds to the "Passed." string.- Parameters:
typeNum- A number between zero and NUM_STATES- Returns:
- null if the given integer was out of range, otherwise an appropriate string.
-
encode
Encodes strings containing non-ascii characters, where all characters are replaced with with their Unicode code. Encoded string will have the certain prefix and suffix to be distinguished from non-encode one. Strings of ASCII chars only are encoded into themselves.
Example:System.out.println(Status.encode("X ?")); // Encoded 58 20 1AB System.out.println(Status.encode("Abc1")); // Abc1- Parameters:
str- - string to encode- Returns:
- Encoded string or the same string if none non-ascii chars were found
- See Also:
-
decode
-
isPassed
public boolean isPassed()Check if the type code of the status is PASSED.- Returns:
- true if the type code is PASSED.
- See Also:
-
isFailed
public boolean isFailed()Check if the type code of the status is FAILED.- Returns:
- true if the type code is FAILED.
- See Also:
-
isError
public boolean isError()Check if the type code of the status is ERROR.- Returns:
- true if the type code is ERROR.
- See Also:
-
isNotRun
public boolean isNotRun()Check if the type code of the status is NOT_RUN.- Returns:
- true if the type code is ERROR.
- See Also:
-
getType
public int getType()Get the type code indicating the type of this Status object.- Returns:
- the type code indicating the type of this Status object.
- See Also:
-
getReason
Get the message given when the status was created.- Returns:
- the string given when this Status object was created.
-
augment
Return a new Status object with a possibly augmented reason field.- Parameters:
aux- if not null and not empty, it will be combined with the original reason.- Returns:
- if aux is null or empty, the result will be the same as this object; otherwise, it will be a new object combining the original status reason and the additional information in aux.
-
augment
Return a new Status object with a possibly augmented reason field.- Parameters:
aux- a Status to combine with this object- Returns:
- if aux is null, the result will be the same as this object; otherwise, it will be a new object combining the original status reason and the additional information in aux.
-
toString
-
exit
public void exit()Convenience exit() function for the main() of tests to exit in such a way that the status passes up across process boundaries without losing information (ie exit codes don't give the associated text of the status and return codes when exceptions are thrown could cause unintended results).An identifying marker is written to the error stream, which the script running the test watches for as the last output before returning, followed by the type and reason
The method does not return. It calls System.exit with a value dependent on the type.
-