
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. The main purpose is to provide a code template to users for writing code to populate variables. This is quite useful to users because generated data types can become very complex as the ASN.1 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 simply has to be modified to accomplish the population of a data variable with any type of data.
<asn1ModuleName>Test.casn1Test_[<prefix>]<prodName>where <prodName> is the name of the ASN.1 production for which the function is being generated and <prefix> is an optional prefix that can be set via a configuration file setting. The configuration setting used to set the prefix is the <typePrefix> element. This element specifies a prefix that will be applied to all generated typedef names and function names for the production.
<typeName>* pvalue = <testFunc> (OSCTXT* pctxt)The pctxt argument 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 have been previously initialized using the rtInitContext run-time function.
The pvalue argument is a pointer to hold the populated data variable. This variable is of the type generated for the ASN.1 production. 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.
In the case of C++, a method is added to the generated control class for test code generation. The name of this method is genTestInstance. The prototype is as follows:
<typeName>* pvalue = <object>.genTestInstance();where <typeName> is the ASN1T_<name> type name of the generated type and <object> is an instance of the ASN1C_<name> generated control class.
A new command-line option added in ASN1C version 6.0 is -domtest. This is similar to -gentest excpet that data for the test variables is not random, it is extracted from an XML Document Object Model (DOM) tree at run-time. In order to use this capability, it is necessary to have the libxml2 (http://xmlsoft.org) XML parser installed on your system. Call are then made to parse a given XML document and create a DOM tree. Data from the DOM tree will then be transfered to data varaibles of generated structures.
In addition to test functions, it is possible to generate writer and reader sample programs. These programs contain sample code to populate and encode an instance of ASN.1 data and then read and decode this data respectively. These programs are generated using the -genwriter and -genreader command-line switches.
Objective Systems, Inc.55 Dowlin Forge RoadExton, Pennsylvania 19341 http://www.obj-sys.com Phone: (484) 875-9841 Toll-free: (877) 307-6855 (US only) Fax: (484) 875-9830 info@obj-sys.com |