/******************************************************************************
 * Copyright (c) 2000-2021 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Balasko, Jeno
 *   Ormandi, Matyas
 *
 ******************************************************************************/
module HR49727 {

import from http_jabber_org_protocol_pubsub         all;
import from http_jabber_org_protocol_pubsub_event   all;


//http_jabber_org_protocol_pubsub
external function enc_Pubsub(in http_jabber_org_protocol_pubsub.Pubsub pdu) return octetstring
with { extension "prototype (convert) encode(XER:XER_EXTENDED)" };
external function dec_Pubsub(in octetstring stream) return http_jabber_org_protocol_pubsub.Pubsub
with { extension "prototype (convert) decode(XER:XER_EXTENDED)" } ;

//http_jabber_org_protocol_pubsub_event
external function enc_Pubsub_Event(in http_jabber_org_protocol_pubsub_event.Event pdu) return octetstring
with { extension "prototype (convert) encode(XER:XER_EXTENDED)" };
external function dec_Pubsub_Event(in octetstring stream) return http_jabber_org_protocol_pubsub_event.Event
with {
  extension "prototype (convert) decode(XER:XER_EXTENDED)" 
  extension "errorbehavior(ALL:ERROR)"  
} ;


type component szappan {}

const charstring s1 := "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">
          <items node=\"toaster@esekilxxen1845.rnd.ericsson.se/1\">
          <item id=\"toaster@esekilxxen1845.rnd.ericsson.se/1#always_on\">
          <entry xmlns=\"http://ntaforum.org/2011/registry\">
          <toolType>http://Example.org/tools/ttcn/titan</toolType>
          <version>1.2.3.4567</version>
          <published>2013-03-11T11:30:02-08:00</published>
          <harness xmlns=\"http://ntaforum.org/2011/harness\" name=\"http://Example.org/ttcn/titan\">
          <supportedMode>invisible_and_automated</supportedMode>
          <supportedMode>visible_and_interactive</supportedMode>
          </harness>
<documentation xml:lang=\"en\">
<vendor>TTCNTestTools</vendor>
<name>TCC</name>
<description>Automated Toaster</description>
</documentation>
<location>
<workspaceID>0d9374c4-aa1e-47f5-8b61-98bae0ad8ca1</workspaceID>
<ipv4>127.0.0.1</ipv4>
<hostname>localhost</hostname>
<description>1stfloor,bldg.A,BudapestHQ</description>
</location>
</entry></item></items></pubsub>"

const http_jabber_org_protocol_pubsub.Pubsub v_Pubsub:=   { choice := 
     { choice_list := 
       { { items := 
           { max_items := omit, 
             node := "toaster@esekilxxen1845.rnd.ericsson.se/1", 
             subid := omit, 
             item_list := { { 
                 id := "toaster@esekilxxen1845.rnd.ericsson.se/1#always_on", 
                 sequence := {elem:="<entry xmlns=\"http://ntaforum.org/2011/registry\">
          <toolType>http://Example.org/tools/ttcn/titan</toolType>
          <version>1.2.3.4567</version>
          <published>2013-03-11T11:30:02-08:00</published>
          <harness xmlns=\"http://ntaforum.org/2011/harness\" name=\"http://Example.org/ttcn/titan\">
          <supportedMode>invisible_and_automated</supportedMode>
          <supportedMode>visible_and_interactive</supportedMode>
          </harness>
<documentation xml:lang=\"en\">
<vendor>TTCNTestTools</vendor>
<name>TCC</name>
<description>Automated Toaster</description>
</documentation>
<location>
<workspaceID>0d9374c4-aa1e-47f5-8b61-98bae0ad8ca1</workspaceID>
<ipv4>127.0.0.1</ipv4>
<hostname>localhost</hostname>
<description>1stfloor,bldg.A,BudapestHQ</description>
</location>
</entry>" }}
             }

           }
         } }
     } 
   }

const http_jabber_org_protocol_pubsub_event.Event v_Event:=
{ choice := { items := { node := "toaster@esekilxxen1843.rnd.ericsson.se/1", choice := { item_list := { { id := "toaster@esekilxxen1843.rnd.ericsson.se/1#always_on", node := omit, publisher := omit, choice := { elem := "<tq0002:ele xmlns:tq0002=\"http://anything\"><a/></tq0002:ele>" } } } } } } }

testcase decode() runs on szappan
{
  log("\nxml to decode:\n",s1);
  var http_jabber_org_protocol_pubsub.Pubsub result := dec_Pubsub(char2oct(s1));
  log("\ndecoded:\n",result);
  if ( match(result,v_Pubsub) ) { setverdict(pass); } else { setverdict(fail, match(result,v_Pubsub)); }
}

testcase encode_decode() runs on szappan
{
  log("\nvar to encode:\n", v_Pubsub);
  var octetstring encoded := enc_Pubsub(v_Pubsub);
  log("\nencoded:\n", oct2char(encoded));
  var http_jabber_org_protocol_pubsub.Pubsub decoded := dec_Pubsub(encoded);
  log ("\nre-decoded\n", decoded);
  if ( match(decoded,v_Pubsub) ) { setverdict(pass); } else { setverdict(fail, match(decoded,v_Pubsub)); }
}


testcase decode_untagged_empty() runs on szappan
{
  var charstring s2:="<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">\n<retract node=\"acme_proxy@mycorp.com/2\">\n<item id=\"acme_proxy@mycorp.com/2#sleeper1\"/>\n</retract>\n</pubsub>"
  var Pubsub dec_s2_exp := { choice := { choice_list := { { retract := { node := "acme_proxy@mycorp.com/2", notify := omit, item_list := { { id := "acme_proxy@mycorp.com/2#sleeper1", sequence := omit } } } } } } }
  var Pubsub decoded := dec_Pubsub(char2oct(s2));
  log("\nxml to be decoded:\n", s2,"\nDecoded Pubsub: ", dec_Pubsub(char2oct(s2)));
  if ( match(decoded,dec_s2_exp) ) { setverdict(pass); } else { setverdict(fail, match(decoded,dec_s2_exp)); }
}

testcase decode_encoded_union() runs on szappan
{
  var charstring s := "<tq0001:event xmlns:tq0001='http://jabber.org/protocol/pubsub#event'>\n\t<tq0001:items node='toaster@esekilxxen1843.rnd.ericsson.se/1'>\n\t\t<tq0001:item id='toaster@esekilxxen1843.rnd.ericsson.se/1#always_on'>\n\t\t\t<tq0002:ele xmlns:tq0002='http://anything'><a></a></tq0002:ele>\n\t\t</tq0001:item>\n\t</tq0001:items>\n</tq0001:event>\n\n"
  var http_jabber_org_protocol_pubsub_event.Event dec := dec_Pubsub_Event(char2oct(s))
  log("\n Event:\n",s, "\ndecoded:\n", dec, "\n")
  if ( match(dec,v_Event) ) { setverdict(pass); } else { setverdict(fail, match(dec,v_Event)); }
}

control{
  execute(decode());
  execute(encode_decode());
  execute(decode_untagged_empty());
  execute(decode_encoded_union());
}

}
