-- TTCN3 module extracted from ITU-T Z.168 (05/2012)

module ttcnExample { import from IDLaux all; // ******************************** // Mapping of the IDL Specification // ******************************** // ********************** // Mapping of Basic Types // ********************** const long number := oct2int(''17''O) ; const long size := oct2int(int2oct(oct2int(int2oct(number,4)<<3) mod hex2int(''1F''H),4) and4b ''0123''O); const IEEE754float decimal := 15.7; type universal charstring uchar length(1); type uchar iso8859char (char ( 0,0,0,0 ) .. char ( 0,0,0,255)) with { variant "8 bit" }; const iso8859char letter := "A"; const uchar wideLetter := "A"; const boolean isValid := true; const octetstring anOctet := hex2oct(''55''H); const iso8859string myName := "my name"; const universal charstring wideMyName := "my name"; type iso8859string MyString; // ***************** // Constructed Types // ***************** // ****** // Struct // ****** type record NameComponent { MyString id, MyString kind }; // ***** // Union // ***** type union MyUnion { boolean b, iso8859char c, octetstring o, short s }; // *********** // Enumeration // *********** type enumerated NotFoundReason { missing_node, not_context, not_object } // ******** // Sequence // ******** type record of NameComponent Name; type record of NameComponent Key; //****** // Fixed // ***** // see also using of fixed in testcase below template IDLfixed fixTemplate := { 12, 7, ? }; // ****************** // Complex Declarator // ****************** type long numberList[100]; // see using of native in testcase below // ******************** // Valuetype Definition // ******************** type iso8859string StringValue; type record EmployeeRecord { iso8859string name, iso8859string email, iso8859string SSN }; // ******************** // Interface Definition // ******************** type record IDLContextElement { iso8859string name, iso8859string value_ } type record of IDLContextElement IDLContext; group NamingContextInterface { type charstring NamingContextObject; type NamingContextObject address; // attribute object_type signature NamingContext__object_typeGet () return iso8859string exception ( SYSTEM_EXCEPTION ); signature NamingContext__object_typeSet ( in iso8859string NamingContext__object_type ) exception ( SYSTEM_EXCEPTION ); template NamingContext__object_typeSet ObjectTypeSetSignatureTemplate := { object_type := "my object type" } // // attribute external_from_id // signature NamingContext__external_form_idGet() return Key exception ( SYSTEM_EXCEPTION ); // exception notFoundException type record NamingContext__NotFoundException { NotFoundReason why, Name rest_of_name } template NamingContext__NotFoundException NamingContext__NotFoundExceptionTemplate ( NotFoundReason reason, Name name ) := { why := reason, rest_of_name := name } // // bind procedure // signature NamingContext__BindSignature ( in Name n, inout address obj, inout address myObj, in IDLContext context ) return MyString exception( NamingContext__NotFoundException, SYSTEM_EXCEPTION ); template NamingContext__BindSignature NamingContext__BindTemplate ( charstring object, IDLContext con ) := { n := { {"name", ""} }, obj := object, myObj := ?, context := con } // // rebind procedure // signature NamingContext__RebindSignature( in Name n, in address obj ) exception ( SYSTEM_EXCEPTION ) with { variant "IDL:oneway FORMAL/01-12-01 v.2.6" }; template NamingContext__RebindSignature NamingContext__RebindTemplate ( address object ) := { n := { {"name", ""} }, obj := object } type port NamingContext procedure { out NamingContext__object_typeGet; out NamingContext__object_typeSet; out NamingContext__external_form_idGet; out NamingContext__BindSignature; } } // component is necessary for test case type component CorbaSystemInterface { port NamingContext PCO; } // somewhere has main test component MyMTC to be defined type component MyMTC { port NamingContext NamingContextPCO; } // ******************* // Testcase Definition // ******************* testcase MyNamingServiceTestCase() runs on MyMTC system CorbaSystemInterface { // examples to show how above definitions can be used inside a // testcase definition var CorbaSystemInterface myCorbaSystem := CorbaSystemInterface.create; connect( self:NamingContextPCO, myCorbaSystem:PCO ); myCorbaSystem.start; // // Fixed Type // var IDLfixed fix := { 12, 7, "12345.1234567" }; // // Native // var address MyNativeVariable; // // Procedure Calls // var MyString myResult1; var Key myResult2; var MyString myResult3; var address object, myObject, resultObject, resultMyObject; var IDLContextElement contextElement := { name := "Hostname", value_ := "disen" } var IDLContext contextParameter := { contextElement }; // // procedure get object_type // NamingContextPCO.call( ObjectTypeGetSignature ) { [] NamingContextPCO.getreply( ObjectTypeGetSignature value * ) -> value myResult1 {} } // // procedure set object_type // NamingContextPCO.call( ObjectTypeSetSignatureTemplate ); // // procedure get external_from_id // NamingContextPCO.call( ExternalFormIdGetSignature ) { [] NamingContextPCO.getreply( ExternalFormIdGetSignature value * ) -> value MyResult2 {} } // // procedure bind (with template) // NamingContextPCO.call( BindTemplate( object, contextParameter ) ) { [] NamingContextPCO.getreply( BindTemplate( * ) value * ) -> value myResult3 param( resultObject, resultMYObject ) sender mySender {} [] NamingContextPCO.catch( BindSignature, NamingContext__NotFoundExceptionTemplate ) { setverdict( fail ); stop; } } // // procedure bind (without template) // NamingContextPCO.call( BindSignature:{ myName, object, myObject, contextParameter } ) { [] NamingContextPCO.getreply( BindSignature:{ -, *, myObject } value * ) -> value myResult3 param( resultObject, resultMYObject ) sender mySender {} } // // procedure rebind // NamingContextPCO.call( RebindSignature:{ myName, object} ); // or use a template // // raising an exception // // this would be used to raise an exception inside of procedure bind // if defined by TTCN-3 (if used on server side). var NamingContext__NotFoundException myNotFoundException := { why := missing_node, rest_of_name := "noname" } NamingContextPCO.raise( BindSignature, myNotFoundException ); } // end of testcase MyNamingServiceTestCase }