com.sun.javatest
Class Status

java.lang.Object
  extended by com.sun.javatest.Status

public class Status
extends java.lang.Object

A class to embody the result of a test: a status-code and a related message.


Field Summary
static int ERROR
          A return code indicating that the test was not run because some error occurred before the test could even be attempted.
static java.lang.String EXIT_PREFIX
          A string used to prefix the status when it is written to System.err by exit().
static int[] exitCodes
          Exit codes used by Status.exit corresponding to PASSED, FAILED, ERROR, NOT_RUN.
static int FAILED
          A return code indicating that the test was executed but the test reported that it failed.
static int NOT_RUN
          A return code indicating that the test has not yet been run in this context.
static int NUM_STATES
          Number of states which are predefined as "constants".
static int PASSED
          A return code indicating that the test was executed and was successful.
 
Constructor Summary
Status(int type, java.lang.String reason)
          Create a Status object.
 
Method Summary
 Status augment(Status aux)
          Return a new Status object with a possibly augmented reason field.
 Status augment(java.lang.String aux)
          Return a new Status object with a possibly augmented reason field.
static java.lang.String decode(java.lang.String str)
          Decodes string encoded by encode(String) method.
static java.lang.String encode(java.lang.String str)
          Encodes strings containing non-ascii characters, where all characters are replaced with with their Unicode code.
static Status error(java.lang.String reason)
          Create a Status to indicate that an error occurred while trying to run a test: i.e.
 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).
static Status failed(java.lang.String reason)
          Create a Status to indicate the unsuccessful outcome of a test: i.e.
 java.lang.String getReason()
          Get the message given when the status was created.
 int getType()
          Get the type code indicating the type of this Status object.
 boolean isError()
          Check if the type code of the status is ERROR.
 boolean isFailed()
          Check if the type code of the status is FAILED.
 boolean isNotRun()
          Check if the type code of the status is NOT_RUN.
 boolean isPassed()
          Check if the type code of the status is PASSED.
static Status notApplicable(java.lang.String reason)
          Deprecated.  
static Status parse(java.lang.String s)
          Parse a string-form of a Status.
static Status passed(java.lang.String reason)
          Create a Status to indicate the successful outcome of a test.
 java.lang.String toString()
          Convert a Status to a string.
static java.lang.String typeToString(int typeNum)
          Translate the type number to a descriptive string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PASSED

public static final int PASSED
A return code indicating that the test was executed and was successful.

See Also:
passed(java.lang.String), getType(), Constant Field Values

FAILED

public static final int FAILED
A return code indicating that the test was executed but the test reported that it failed.

See Also:
failed(java.lang.String), getType(), Constant Field Values

ERROR

public static final int ERROR
A 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:
getType(), Constant Field Values

NOT_RUN

public static final int NOT_RUN
A 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:
getType(), Constant Field Values

NUM_STATES

public static final int NUM_STATES
Number of states which are predefined as "constants".

See Also:
Constant Field Values

EXIT_PREFIX

public static final java.lang.String EXIT_PREFIX
A string used to prefix the status when it is written to System.err by exit().

See Also:
Constant Field Values

exitCodes

public static final int[] exitCodes
Exit 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 Detail

Status

public Status(int type,
              java.lang.String reason)
       throws java.lang.IllegalArgumentException
Create a Status object. See passed(java.lang.String), failed(java.lang.String), error(java.lang.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.
Throws:
java.lang.IllegalArgumentException - if the specified type is invalid.
Method Detail

passed

public static Status passed(java.lang.String reason)
Create a Status to indicate the successful outcome of a test.

Parameters:
reason - A short string describing why the test passed.
Returns:
a Status to indicate the successful outcome of a test.

failed

public static Status failed(java.lang.String reason)
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

public static Status error(java.lang.String reason)
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

public static Status notApplicable(java.lang.String reason)
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

isPassed

public boolean isPassed()
Check if the type code of the status is PASSED.

Returns:
true if the type code is PASSED.
See Also:
passed(java.lang.String), getType(), PASSED

isFailed

public boolean isFailed()
Check if the type code of the status is FAILED.

Returns:
true if the type code is FAILED.
See Also:
failed(java.lang.String), getType(), FAILED

isError

public boolean isError()
Check if the type code of the status is ERROR.

Returns:
true if the type code is ERROR.
See Also:
error(java.lang.String), getType(), ERROR

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(), NOT_RUN

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:
PASSED, FAILED, ERROR

getReason

public java.lang.String getReason()
Get the message given when the status was created.

Returns:
the string given when this Status object was created.

augment

public Status augment(java.lang.String aux)
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

public Status augment(Status aux)
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.

parse

public static Status parse(java.lang.String s)
Parse a string-form of a Status.

Parameters:
s - a string containing the string form of a Status as generated by toString()
Returns:
the corresponding Status, or null if it could not be parsed successfully
See Also:
exit()

toString

public java.lang.String toString()
Convert a Status to a string.

Overrides:
toString in class java.lang.Object
See Also:
parse(java.lang.String)

typeToString

public static java.lang.String typeToString(int typeNum)
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.

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.


encode

public static java.lang.String encode(java.lang.String str)
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 ?")); //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(java.lang.String)

decode

public static java.lang.String decode(java.lang.String str)
Decodes string encoded by encode(String) method.

Parameters:
str - - string to decode
Returns:
Decoded string or the same string if encoded prefix/suffix were found
See Also:
encode(java.lang.String)


Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.