Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » XML encoding in TTCN-3 and Titan part II: example
XML encoding in TTCN-3 and Titan part II: example [message #1732425] Tue, 17 May 2016 08:07 Go to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 754
Registered: January 2015
Senior Member
Dear all,


the reference guide contains details of the XML to TTCN-3 conversion as below:

par. 4.25 XML Encoder and Decoder
ch. 9 XSD to TTCN-3 Converter
par. 11.5 Workflow for Native XML Support

And now let's look into a potentially relevant example:

From http://onem2m.org/technical/xml-schemas

I have downloaded
http://onem2m.org/xml/protocols/XSDbundle-v1_6_0.zip


and I looked into xsd_v1_6_0_long

which contains the following schemas;

esekilxxen1845 [9:03] [oneM2M/XSDBundle-v1_6_0/xsd_v1_6_0_long] -> ll *.xsd                                                                                                     
-rw------- 1 ethlel rnd  5580 Feb  5 12:40 CDT-AE-v1_6_0.xsd                                                                                                                    
-rw------- 1 ethlel rnd  5563 Feb  5 12:40 CDT-CSEBase-v1_6_0.xsd                                                                                                               
-rw------- 1 ethlel rnd  9678 Feb  5 12:40 CDT-accessControlPolicy-v1_6_0.xsd                                                                                                   
-rw------- 1 ethlel rnd  2642 Feb  5 12:40 CDT-activeCmdhPolicy-v1_6_0.xsd                                                                                                      
-rw------- 1 ethlel rnd  4510 Feb  5 12:40 CDT-areaNwkDeviceInfo-v1_6_0.xsd                                                                                                     
-rw------- 1 ethlel rnd  3770 Feb  5 12:40 CDT-areaNwkInfo-v1_6_0.xsd
-rw------- 1 ethlel rnd  3797 Feb  5 12:40 CDT-battery-v1_6_0.xsd
-rw------- 1 ethlel rnd  3029 Feb  5 12:40 CDT-cmdhBuffer-v1_6_0.xsd
-rw------- 1 ethlel rnd  3018 Feb  5 12:40 CDT-cmdhDefEcValue-v1_6_0.xsd
-rw------- 1 ethlel rnd  3203 Feb  5 12:40 CDT-cmdhDefaults-v1_6_0.xsd
-rw------- 1 ethlel rnd  3136 Feb  5 12:40 CDT-cmdhEcDefParamValues-v1_6_0.xsd
-rw------- 1 ethlel rnd  4087 Feb  5 12:40 CDT-cmdhLimits-v1_6_0.xsd
-rw------- 1 ethlel rnd  2997 Feb  5 12:40 CDT-cmdhNetworkAccessRules-v1_6_0.xsd
-rw------- 1 ethlel rnd  3404 Feb  5 12:40 CDT-cmdhNwAccessRule-v1_6_0.xsd
-rw------- 1 ethlel rnd  3250 Feb  5 12:40 CDT-cmdhPolicy-v1_6_0.xsd
-rw------- 1 ethlel rnd 24409 Feb  5 12:40 CDT-commonTypes-v1_6_0.xsd
-rw------- 1 ethlel rnd  5400 Feb  5 12:40 CDT-container-v1_6_0.xsd
-rw------- 1 ethlel rnd  3792 Feb  5 12:40 CDT-contentInstance-v1_6_0.xsd
-rw------- 1 ethlel rnd  3444 Feb  5 12:40 CDT-delivery-v1_6_0.xsd
-rw------- 1 ethlel rnd  4318 Feb  5 12:40 CDT-deviceCapability-v1_6_0.xsd
-rw------- 1 ethlel rnd  4359 Feb  5 12:40 CDT-deviceInfo-v1_6_0.xsd
-rw------- 1 ethlel rnd 33369 Feb  5 14:16 CDT-enumerationTypes-v1_6_0.xsd
-rw------- 1 ethlel rnd  3382 Feb  5 12:40 CDT-eventConfig-v1_6_0.xsd
-rw------- 1 ethlel rnd  4137 Feb  5 12:40 CDT-eventLog-v1_6_0.xsd
-rw------- 1 ethlel rnd  3485 Feb  5 12:40 CDT-execInstance-v1_6_0.xsd
-rw------- 1 ethlel rnd  4132 Feb  5 12:40 CDT-firmware-v1_6_0.xsd
-rw------- 1 ethlel rnd  4975 Feb  5 12:40 CDT-group-v1_6_0.xsd
-rw------- 1 ethlel rnd  4425 Feb  5 12:40 CDT-locationPolicy-v1_6_0.xsd
-rw------- 1 ethlel rnd  3201 Feb  5 12:40 CDT-m2mServiceSubscriptionProfile-v1_6_0.xsd
-rw------- 1 ethlel rnd  3743 Feb  5 12:40 CDT-memory-v1_6_0.xsd
-rw------- 1 ethlel rnd  3629 Feb  5 12:40 CDT-mgmtCmd-v1_6_0.xsd
-rw------- 1 ethlel rnd  6145 Feb  5 13:51 CDT-node-v1_6_0.xsd
-rw------- 1 ethlel rnd  4198 Feb  5 12:40 CDT-notification-v1_6_0.xsd
-rw------- 1 ethlel rnd  2667 Feb  5 12:40 CDT-pollingChannel-v1_6_0.xsd
-rw------- 1 ethlel rnd  3752 Feb  5 12:40 CDT-reboot-v1_6_0.xsd
-rw------- 1 ethlel rnd  6403 Feb  5 12:40 CDT-remoteCSE-v1_6_0.xsd
-rw------- 1 ethlel rnd  3587 Feb  5 12:40 CDT-request-v1_6_0.xsd
-rw------- 1 ethlel rnd  4925 Feb  5 12:40 CDT-requestPrimitive-v1_6_0.xsd
-rw------- 1 ethlel rnd  9075 May  6 09:02 CDT-responsePrimitive-v1_6_0.xsd
-rw------- 1 ethlel rnd  3340 Feb  5 12:40 CDT-schedule-v1_6_0.xsd
-rw------- 1 ethlel rnd  3072 Feb  5 12:40 CDT-serviceSubscribedAppRule-v1_6_0.xsd
-rw------- 1 ethlel rnd  3211 Feb  5 12:40 CDT-serviceSubscribedNode-v1_6_0.xsd
-rw------- 1 ethlel rnd  4706 Feb  5 12:40 CDT-software-v1_6_0.xsd
-rw------- 1 ethlel rnd  3411 Feb  5 12:40 CDT-statsCollect-v1_6_0.xsd
-rw------- 1 ethlel rnd  3045 Feb  5 12:40 CDT-statsConfig-v1_6_0.xsd
-rw------- 1 ethlel rnd  5605 Feb  5 12:40 CDT-subscription-v1_6_0.xsd


My first conversion attempt
xsd2ttcn -h *.xsd 

terminated in error:

ERROR:
CDT-responsePrimitive-v1_6_0.xsd (in line 69): Element '{http://www.w3.org/2001/XMLSchema}include': The schema document 'CDT-responsePrimitive-v1_6_0.xsd' cannot include itself..


Indeed,

CDT-responsePrimitive-v1_6_0.xsd

tries to include itself, so I commented out the line

<!-- xs:include schemaLocation="CDT-responsePrimitive-v1_6_0.xsd" / -->


Now,

  xsd2ttcn -h *.xsd


is successful, and

http_www_onem2m_org_xml_protocols.ttcn
is generated, together with

XSD.ttcn and UsefulTtcn3Types.ttcn

(which are generated every time).


I have added a simple XMLDemo.ttcn:
module XMLDemo

{


import from http_www_onem2m_org_xml_protocols  all;
import from XSD all;
import from UsefulTtcn3Types  all;


type component MTC {}

external function enc_AccessControlPolicy(in AccessControlPolicy pdu) return octetstring
with { extension "prototype (convert) encode(XER:XER_EXTENDED)" }

external function dec_AccessControlPolicy(in octetstring stream) return AccessControlPolicy
with { extension "prototype (convert) decode(XER:XER_EXTENDED)" }



template  AccessControlPolicy t_AccessControlPolicy :=
{
	resourceName:="somename",
	resourceType:=int1,
	resourceID:="someURI",
	parentID:="someURI",
	creationTime:="04.04.2016",
	lastModifiedTime:="05.04.2016",
	labels:= omit,
	expirationTime:="04.04.2019",
	announceTo:= omit,
	announcedAttribute:={"someAttribute"},
	privileges:={accessControlRule_list:={}},
	selfPrivileges:={accessControlRule_list:={}},
	choice:= omit
}


testcase testcase1()  runs on  MTC {

log(enc_AccessControlPolicy(valueof(t_AccessControlPolicy)))

var universal charstring v_char:= "<m2m:accessControlPolicy xmlns:m2m=\'http://www.onem2m.org/xml/protocols\' resourceName=\'somename\'>
        <resourceType>1</resourceType>
        <resourceID>someURI</resourceID>
        <parentID>someURI</parentID>
        <creationTime>04.04.2016</creationTime>
        <lastModifiedTime>05.04.2016</lastModifiedTime>
        <expirationTime>04.04.2019</expirationTime>
        <announcedAttribute>someAttribute</announcedAttribute>
        <privileges/>
        <selfPrivileges/>
</m2m:accessControlPolicy>"

log(dec_AccessControlPolicy(unichar2oct(v_char)))




if ( match(dec_AccessControlPolicy(unichar2oct(v_char)),t_AccessControlPolicy ))
{setverdict(pass)}
else {setverdict(fail)}




}

control
{

execute(testcase1())



}



}//endmodule






and generated the makefile

 makefilegen *.ttcn


then compiled:

 make


and run

 ttcn3_start XMLDemo


then formatted the logfile:

 logformat XMLDemo.esekilxxen1845-mtc.log > formatted.log



10:53:05.383690 TTCN-3 Main Test Component started on esekilxxen1845. Version: CRL 113 200/5 R5A.
10:53:05.383908 TTCN Logger v2.2 options: TimeStampFormat:=Time; LogEntityName:=No; LogEventTypes:=No; SourceInfoFormat:=None; *.FileMask:=LOG_ALL; *.ConsoleMask:=ACTION | ERROR | TESTCASE | STATISTICS | WARNING; LogFileSize:=0; LogFileNumber:=1; DiskFullAction:=Error
10:53:05.384011 Connected to MC.
10:53:05.388329 Executing control part of module XMLDemo.
10:53:05.388376 Execution of control part in module XMLDemo started.
10:53:05.388430 Test case testcase1 started.
10:53:05.388472 Initializing variables, timers and ports of component type XMLDemo.MTC inside testcase testcase1.
10:53:05.388508 Component type XMLDemo.MTC was initialized.
10:53:05.388524 '3C6D326D3A616363657373436F6E74726F6C506F6C69637920786D6C6E733A6D326D3D27687474703A2F2F7777772E6F6E656D326D2E6F72672F786D6C2F70726F746F636F6C7327207265736F757263654E616D653D27736F6D656E616D65273E0A093C7265736F75726365547970653E313C2F7265736F75726365547970653E0A093C7265736F7572636549443E736F6D655552493C2F7265736F7572636549443E0A093C706172656E7449443E736F6D655552493C2F706172656E7449443E0A093C6372656174696F6E54696D653E30342E30342E323031363C2F6372656174696F6E54696D653E0A093C6C6173744D6F64696669656454696D653E30352E30342E323031363C2F6C6173744D6F64696669656454696D653E0A093C65787069726174696F6E54696D653E30342E30342E323031393C2F65787069726174696F6E54696D653E0A093C616E6E6F756E6365644174747269627574653E736F6D654174747269627574653C2F616E6E6F756E6365644174747269627574653E0A093C70726976696C656765732F3E0A093C73656C6650726976696C656765732F3E0A3C2F6D326D3A616363657373436F6E74726F6C506F6C6963793E0A0A'O ("<m2m:accessControlPolicy xmlns:m2m='http://www.onem2m.org/xml/protocols' resourceName='somename'>
	<resourceType>1</resourceType>
	<resourceID>someURI</resourceID>
	<parentID>someURI</parentID>
	<creationTime>04.04.2016</creationTime>
	<lastModifiedTime>05.04.2016</lastModifiedTime>
	<expirationTime>04.04.2019</expirationTime>
	<announcedAttribute>someAttribute</announcedAttribute>
	<privileges/>
	<selfPrivileges/>
</m2m:accessControlPolicy>

")
10:53:05.409832 {
    resourceName := "somename",
    resourceType := int1 (1),
    resourceID := "someURI",
    parentID := "someURI",
    creationTime := "04.04.2016",
    lastModifiedTime := "05.04.2016",
    labels := omit,
    expirationTime := "04.04.2019",
    announceTo := omit,
    announcedAttribute := {
        "someAttribute"
    },
    privileges := {
        accessControlRule_list := { }
    },
    selfPrivileges := {
        accessControlRule_list := { }
    },
    choice := omit
}
10:53:05.417859 setverdict(pass): none -> pass
10:53:05.417899 Terminating component type XMLDemo.MTC.
10:53:05.417920 Component type XMLDemo.MTC was shut down inside testcase testcase1.
10:53:05.417942 Waiting for PTCs to finish.
10:53:05.418084 Setting final verdict of the test case.
10:53:05.418141 Local verdict of MTC: pass
10:53:05.418167 No PTCs were created.
10:53:05.418190 Test case testcase1 finished. Verdict: pass
10:53:05.418220 Execution of control part in module XMLDemo finished.
10:53:05.425855 Verdict statistics: 0 none (0.00 %), 1 pass (100.00 %), 0 inconc (0.00 %), 0 fail (0.00 %), 0 error (0.00 %).
10:53:05.425944 Test execution summary: 1 test case was executed. Overall verdict: pass
10:53:05.425985 Exit was requested from MC. Terminating MTC.



Now , this XML can be passed to a transport layer, e.g. made the body of an HTTP message.



I hope you will find this example useful.


Best regards
Elemer

Re: XML encoding in TTCN-3 and Titan part II: example [message #1732440 is a reply to message #1732425] Tue, 17 May 2016 11:31 Go to previous messageGo to next message
Gustavo Gonnet is currently offline Gustavo GonnetFriend
Messages: 34
Registered: October 2015
Location: Montreal, Quebec, Canada
Member
it is useful, thank you
Re: XML encoding in TTCN-3 and Titan part II: example [message #1732447 is a reply to message #1732440] Tue, 17 May 2016 11:54 Go to previous message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 754
Registered: January 2015
Senior Member
Thank you, Gustavo
Previous Topic:Test and Validation
Next Topic:Module parameters in Eclipse Titan
Goto Forum:
  


Current Time: Tue Jun 19 03:30:08 GMT 2018

Powered by FUDForum. Page generated in 0.02222 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top