Function Syntax - WinRunner

A user-defined function has the following structure:
[class] function name ([mode] parameter...)
{
declarations;
statements;
}

Class

The class of a function can be either static or public. A static function is available only to the test or module within which the function was defined.

Once you execute a public function, it is available to all tests, for as long as the test containing the function remains open. This is convenient when you want the function to be accessible from called tests. However, if you want to create a function that will be available to many tests, you should place it in a compiled module. The functions in a compiled module are available for the duration of the testing session.

If no class is explicitly declared, the function is assigned the default class, public.

Parameters

Parameters need not be explicitly declared. They can be of mode in,out, or inout. For all non-array parameters, the default mode is in. For array parameters, the default is inout. The significance of each of these parameter types is as follows:

in: A parameter that is assigned a value from outside the function.

out: A parameter that is assigned a value from inside the function.

inout: A parameter that can be assigned a value from outside or inside the function.

A parameter designated as out or inout must be a variable name, not an expression. When you call a function containing an out or an inout parameter, the argument corresponding to that parameter must be a variable, and not an expression. For example, consider a user-defined function with the following syntax:

function get_date (out todays_date) { ... }

Proper usage of the function call would be:

get_date (todays_date);

Illegal usage of the function call would be:

get_date (date[i]); or get_date ("Today’s date is"& todays_date);

because both contain expressions.

Array parameters are designated by square brackets. For example, the following parameter list in a user-defined function indicates that variable a is an array:

function my_func (a[], b, c){ ... }

Array parameters can be either mode out or inout. If no class is specified, the default mode inout is assumed.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

WinRunner Topics