Generated Test Functions

The -genTest option causes test functions to be generated. These functions can be used to populate variables of generated types with random test data or data from an existing XML instance. They have two main purposes:

  1. To allow testing of the application code with a wide-variety of test data, and

  2. To provide a code template for users to use to write code to populate variables

The second item is quite useful to users because generated data types can become very complex as the schemas become more complex. It is sometimes difficult to figure out how to navigate all of the lists and pointers. Using -genTest can provide code that may be modified to accomplish the population of a data variable with any type of data.

The generated test functions are written to a .c file with a name of the following format:

   <xsdFileName>Test.c

where <xsdFileName> is the base name of the XSD file being parsed. For example, if code is being generated for file x.xsd and -test is specified, test functions will be written to xTest.c . If the file being processed is a WSDL file, the suffix would be WSDLTest.c (for example, x.wsdl would produce xWSDLTest.c ).

The format of the name of each generated test function is as follows:

   [<ns>]Test_<elemName>

where <elemName>is the name of the XSD global element for which the function is being generated and <ns>is an optional namespace setting that can be used to disambiguate names from multiple sources (note: this should not be confused with XML namespaces which are different). Note that test routines are generated only for global elements within a specification.

The calling sequence for each generated test function is as follows:

   <typeName>* pvalue = <testFunc> (OSCTXT* pctxt)

In this definition, <testFunc> denotes the formatted function name defined above.

The pctxtargument is used to hold a context pointer to keep track of dynamic memory allocation parameters. This is a basic "handle" variable that is used to make the function reentrant so that it can be used in an asynchronous or threaded application. The user is required to supply a pointer to a variable of this type declared somewhere in his or her program. The variable must be initialized using either the rtxInitContext or rtXmlInitContext run-time function before use.

The pvalueargument is a pointer to hold the populated data variable. This variable is of the type generated for the XSD type of the global element. The test function will automatically allocate dynamic memory using the run-time memory management for the main variable as well as variable length fields within the structure. This memory is tracked within the context structure and is released when the context structure is freed.