How can I use serialization functions to test messages with complex types?
Sample model: Samples/CppSamples/TestConductor/TestingCookbook/CppListUsage
To be able to drive messages the string representation of an argument value in the test specification must be unserialized to be assigned to the concrete data type of the argument.
For simple types like int or bool serialization or unserialization can be done automatically (or Rhapsody can automatically provide such functions, for example for enum types) while for complex types like struct the user must provide (un-)serialization functions. In the sample model, a type mylist is defined based on std::list<int*>, representing a list of integer values. The class class_0 in the model provides two operations to sort such a list: Each operation receives a list of integer values and returns a sorted list.
To be able to test these operations in sequence diagram test cases, two functions have been created in the Package:
- mylist_ser has an in argument of type mylist and the return value is of type char*. mylist_ser is used to provide the string representation of a list (see implementation of this function).
- mylist_unser has an in argument of type char* (and another, not used argument
of type mylist) and the return value is of type mylist. mylist_unser is used to create a list from
it's string representation (see implementation of this function).
Please note: Functions used for (un-)serialization must not be animated, so for both functions the properties CG::Operation::Animate and CG::Operation::AnimateArguments must be switched off.
In order to use these two functions for automatic (un-)serialization of return values or arguments of type mylist, enter the name of the serialization function in property CPP_CG::Type::AnimSerializeOperation and enter the name of the unserialization function in property CPP_CG::Type::AnimUnserializeOperation (or the corresponding properties in the C_CG subject when using C). TestConductor automatically uses these functions to serialize or unserialize values of type mylist. Also, Rhapsody uses these functions when drawing animated sequence diagrams during execution.
For more details on serialization, see Rhapsody documentation of the properties CPP_CG::Type::AnimSerializeOperation and CPP_CG::Type::AnimUnserializeOperation (or corresponding properties for other languages).
Now sequence diagram based test cases can be used to test operations or events with arguments of type mylist.
Additional examples for using of (un)serialization functions in test cases can be found in the Testing Cookbook sample model CppFractionsPrivateOperations respectively CFractionsPrivateOperations.