TOP

Test Functions

Applies to: ASN.1/C++ 6.5

For each value reference defined with a PDU type, the -test compiler option instructs the compiler to generate a main() routine for

  • ossTestCPP(), when neither -enablePartialDecode nor -partialDecodeOnly is enabled.
  • ossTestCPP() and ossTestCPPPD(), when -enablePartialDecode is enabled and -partialDecodeOnly is not.
  • ossTestCPPPD(), when -partialDecodeOnly is enabled and -enablePartialDecode is not.

ossTestCPP()

The ossTestCPP() function is used for encoding, decoding, printing, copying, comparing, and freeing a sample PDU. This function is useful for

  • Beginners learning how to use the OSS ASN.1/C++ Tools.
  • More advanced users who want to view a particular data structure in encoded and decoded form without writing a lengthy test program.

The ossTestCPP() function has the following prototype:

int ossTestCPP(OssControl &ctl, PDU &pdu, PDU &tmp, PDU &tmp2, long run);
ctl is a pointer to an OssControl object.
pdu is an input data PDU object.
tmp is a PDU object of the same type that will be used in the test procedure.
tmp2 is another PDU object of the same type that will also be used in the test procedure.
run is how many times ossTestCPP() will run.

The function returns a zero integer when successful and a non-zero value otherwise.

Example

ASN.1 syntax (subscriber.asn):

M DEFINITIONS AUTOMATIC TAGS ::= BEGIN
Subscriber ::= SEQUENCE {
    name VisibleString,
    company Company,
    homeAddress Address
}

Company ::= SEQUENCE {
    name VisibleString,
    address Address
}

Address ::= SEQUENCE {
    zipcode   NumericString,
    addressline  VisibleString(SIZE (1..64))
}

value Subscriber ::=
{
  name "AGI",
  company
  {
    name "OSS Nokalva, Inc.",
    address
    {
      zipcode "08873",
      addressline "300 Atrium Drive, Suite 402 Somerse ..."
    }
  },

  homeAddress
  {
    zipcode "08880",
    addressline "203 Main St South Bound Brook"
  }
}
END 

When subscriber.asn is compiled with the -test option, the following code is produced:

...
subscriber_Control ctl;
...
Subscriber_PDU Subscribervalue_pdu, Subscribervalue_tmp, Subscribervalue_tmp2;
Subscribervalue_pdu.set_data(*Subscribervalue_copy);
if (ossTestCPP(ctl, Subscribervalue_pdu, Subscribervalue_tmp, Subscribervalue_tmp2, 1)) {
    ctl.print("Testing failed for the value \"value\".\n");
    subscriber_error_count++;
}
...

ossTestCPPPD()

The ossTestCPPPD() function is similar to ossTestCPP(); however, during decoding, it internally calls ConcretePDU::partialDecode() instead of ConcretePDU::decode().

The ossTestCPPPD() function has the following prototype:

int ossTestCPPPD(OssControl &ctl, PDU &pdu, ConcretePDU &tmp, long run, OssCallback &callback);
ctl is a pointer to an OssControl object.
pdu is an input data PDU object.
tmp is a PDU object of the same type that will be used in the test procedure.
run is how many times ossTestCPP() will run.
callback is a reference to the OssCallback object.

Note that the first four parameters have the same meaning as those of ossTestCPP(). The function returns a zero integer when successful and a non-zero value otherwise.

When the -test option is specified with -enablePartialDecode or -partialDecodeOnly, the compiler generates code that implements the compiler-generated callback virtual member functions. The generated callback method prints diagnostics and values of the callback method parameters.

The compiler-generated callback method for the virtual tests (-test/-debug) assumes that OssCallback::userVar stores a pointer to the encoded data (EncodedBuffer::get_data()). The ossTestCPPPD() function sets the value of OssCallback::userVar automatically. To use the compiler-generated code for the callback methods with ConcretePDU::partialDecode(), manually set the value of OssCallback::userVar.

When using ossTestCPPPD(), you cannot use the existing OssCallback::userVar to pass data between the application and the callback methods or between callback method calls. Instead, when deriving the compiler generated <module_name>_Callback class, you can create the userVar members.

Example

When subscriber.asn from the ossTestCPP() example above is compiled with the -test and -enablePartialDecode options the following code is produced:

...
subscriber_Control ctl;
...
Subscriber_PDU Subscribervalue_pdu, Subscribervalue_tmp;
Subscribervalue_pdu.set_data(*Subscribervalue_copy);
...
{
    subscriber_CallbackTest cback_test;
    if (ossTestCPPPD(ctl, Subscribervalue_pdu, Subscribervalue_tmp, 1, cback_test)) {
        ctl.print("Testing failed for the value \"value\".\n");
        subscriber_error_count++;
    }
...

Where subscriber_CallbackTest is a generated subclass of the OssCallback class.

See Also


This documentation applies to release 6.5 and later of the OSS® ASN.1 Tools for C++.

Copyright © 2017 OSS Nokalva, Inc. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic, mechanical, photocopying, recording or otherwise, without the prior permission of OSS Nokalva, Inc.
Every distributed copy of the OSS® ASN.1 Tools for C++ is associated with a specific license and related unique license number. That license determines, among other things, what functions of the OSS ASN.1 Tools for C++ are available to you.