7.14 Defining the Validation method for usecase scripts

The method defined using the $Validation$ tag names a method in the usecase script which provides validation for the usecase.

The validation method takes a single parameter, called options, which can be used to access the options supplied to the script.
The example shows a validation method called myValidation in the usecase definition block. The validation method is used to validate the set of options supplied to the usecase script.

Example 7-12 Examples

...
$Validation$ myValidation
...
def myValidation(options):
    # Get the options which define the start and end of a trace range
    # These options have been defined in the function defined in the $Options$ tag
    start = options.getOptionValue("options.traceRange.start")    
    end = options.getOptionValue("options.traceRange.end")    
    # Conditional check for validation    
    if(start >= end):
         # Report a specific error in the usecase script if the validation check fails
         UseCaseScript.error("The trace range start must be before the end")
It is important that the function that supplies the validation takes a single parameter, which is the usecase script object, used to access the options defined for use in the script.
If the $Validation$ tag is defined, and the method referred to in this tag is not present in the script or the validation function takes the wrong number of arguments, an error occurs when running the script.

Error reporting

This validation example throws an error specific to usecase scripts. If validation is not successful, for example start >= end, in our script, the DS-5 command-line displays:
UseCaseError: The trace range start must be before the end
It is possible not to use the built-in usecase error reporting and throw a standard Jython or Java error such as:
raise RuntimeError("Validation was unsuccessful")
This displays an error in the DS-5 command-line:
RuntimeError: Validation was unsuccessful
However, it is recommended to use the built-in usecase script error reporting so that a clear user-defined error is raised that originates from the usecase script.
Non-ConfidentialPDF file icon PDF versionARM DUI0446W
Copyright © 2010-2015 ARM. All rights reserved.