/******************************************************************************
 * 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
 *   Raduly, Csaba
 *   Szabo, Bence Janos
 *
 ******************************************************************************/
module POtest {
modulepar boolean verbose := false;
#include "../macros.ttcnin"

import from www_example_com_POQ all;
import from www_example_com_POU all;
import from www_example_com_POQAQ all;
import from www_example_com_POUAQ all;

type component POX {}

DECLARE_EXER_ENCODERS(www_example_com_POQ.PurchaseOrder3, poq);
DECLARE_EXER_ENCODERS(www_example_com_POU.PurchaseOrder4, pou);
DECLARE_EXER_ENCODERS(www_example_com_POQAQ.PurchaseOrder2, poqaq);
DECLARE_EXER_ENCODERS(www_example_com_POUAQ.PurchaseOrder1, pouaq);

const universal charstring str_qual :=
"<q:purchaseOrder3 xmlns:q='http://www.example.com/POQ' orderDate='1999-10-20'>\n" &
"\t<q:shipTo country='US'>\n" &
"\t\t<q:name>Alice Smith</q:name>\n" &
"\t\t<q:street>123 Maple Street</q:street>\n" &
"\t</q:shipTo>\n" &
"\t<q:billTo country='US'>\n" &
"\t\t<q:name>Robert Smith</q:name>\n" &
"\t\t<q:street>8 Oak Avenue</q:street>\n" &
"\t</q:billTo>\n" &
"\t<q:comment3>Hurry, my lawn is going wild!</q:comment3>\n" &
"</q:purchaseOrder3>\n\n";

const universal charstring str_unqual :=
"<u:purchaseOrder4 xmlns:u='http://www.example.com/POU' orderDate='1999-10-20'>\n" &
"\t<shipTo country='US'>\n" &
"\t\t<name>Alice Smith</name>\n" &
"\t\t<street>123 Maple Street</street>\n" &
"\t</shipTo>\n" &
"\t<billTo country='US'>\n" &
"\t\t<name>Robert Smith</name>\n" &
"\t\t<street>8 Oak Avenue</street>\n" &
"\t</billTo>\n" &
"\t<u:comment4>Hurry, my lawn is going wild!</u:comment4>\n" &
"</u:purchaseOrder4>\n\n";

const universal charstring str_both := // both qualified
"<qq:purchaseOrder2 xmlns:qq='http://www.example.com/POQAQ' qq:orderDate='1999-10-20'>\n" &
"\t<qq:shipTo qq:country='US'>\n" &
"\t\t<qq:name>Alice Smith</qq:name>\n" &
"\t\t<qq:street>123 Maple Street</qq:street>\n" &
"\t</qq:shipTo>\n" &
"\t<qq:billTo qq:country='US'>\n" &
"\t\t<qq:name>Robert Smith</qq:name>\n" &
"\t\t<qq:street>8 Oak Avenue</qq:street>\n" &
"\t</qq:billTo>\n" &
"\t<qq:comment2>Hurry, my lawn is going wild!</qq:comment2>\n" &
"</qq:purchaseOrder2>\n\n";

const universal charstring str_aqual := // attributes qualified
"<aq:purchaseOrder1 xmlns:aq='http://www.example.com/POUAQ' aq:orderDate='1999-10-20'>\n" &
"\t<shipTo aq:country='US'>\n" &
"\t\t<name>Alice Smith</name>\n" &
"\t\t<street>123 Maple Street</street>\n" &
"\t</shipTo>\n" &
"\t<billTo aq:country='US'>\n" &
"\t\t<name>Robert Smith</name>\n" &
"\t\t<street>8 Oak Avenue</street>\n" &
"\t</billTo>\n" &
"\t<aq:comment1>Hurry, my lawn is going wild!</aq:comment1>\n" &
"</aq:purchaseOrder1>\n\n";


testcase tc_qual() runs on POX // element qualified
{
  var www_example_com_POQ.PurchaseOrder3 poq := {
    orderDate := "1999-10-20",
    shipTo    := { country := "US", name := "Alice Smith" , street := "123 Maple Street" },
    billTo    := { country := "US", name := "Robert Smith", street := "8 Oak Avenue" },
    comment3  := "Hurry, my lawn is going wild!"
  };

  CHECK_METHOD(exer_enc_poq, poq, str_qual);
}

testcase tc_unqual() runs on POX // none qualified
{
  var www_example_com_POU.PurchaseOrder4 pou := {
    orderDate := "1999-10-20",
    shipTo    := { country := "US", name := "Alice Smith" , street := "123 Maple Street" },
    billTo    := { country := "US", name := "Robert Smith", street := "8 Oak Avenue" },
    comment4  := "Hurry, my lawn is going wild!"
  };

  CHECK_METHOD(exer_enc_pou, pou, str_unqual);
}

testcase tc_aqual() runs on POX // attribute qualified
{
  var www_example_com_POUAQ.PurchaseOrder1 pouaq := {
    orderDate := "1999-10-20",
    shipTo    := { country := "US", name := "Alice Smith" , street := "123 Maple Street" },
    billTo    := { country := "US", name := "Robert Smith", street := "8 Oak Avenue" },
    comment1  := "Hurry, my lawn is going wild!"
  };

  CHECK_METHOD(exer_enc_pouaq, pouaq, str_aqual);
}

testcase tc_both() runs on POX // everything qualified
{
  var www_example_com_POQAQ.PurchaseOrder2 poqaq := {
    orderDate := "1999-10-20",
    shipTo    := { country := "US", name := "Alice Smith" , street := "123 Maple Street" },
    billTo    := { country := "US", name := "Robert Smith", street := "8 Oak Avenue" },
    comment2  := "Hurry, my lawn is going wild!"
  };

  CHECK_METHOD(exer_enc_poqaq, poqaq, str_both);
}

import from www_example_org_all all;

DECLARE_XER_ENCODERS(E29aAndAttributes, E29aaa);
DECLARE_EXER_ENCODERS(E29aAndAttributes, E29aaa);

const E29aAndAttributes e29aa := {
  order := { foo, bar, ding }, // 0-length should be flagged as error if none optional!
  attrGlobal := "globatr",
  attrInGroup1 := omit,
  attrInGroup2 := "grp-atr",
  attrLocal := 17,
  foo := 1,
  bar := 2.0,
  ding := "three"
}

const universal charstring bstr_e29aa :=
"<E29aAndAttributes>\n" &
// order
"\t<order>\n" &
"\t\t<foo/><bar/><ding/>\n" &
"\t</order>\n" &
// attributes
"\t<attrGlobal>globatr</attrGlobal>\n" &
"\t<attrInGroup2>grp-atr</attrInGroup2>\n" &
"\t<attrLocal>17</attrLocal>\n" &
// elements
"\t<foo>1</foo>\n" &
"\t<bar>2.000000</bar>\n" &
"\t<ding>three</ding>\n" &
"</E29aAndAttributes>\n\n";

const universal charstring estr_e29aa :=
"<ns:e29aAndAttributes xmlns:ns='www.example.org/all' ns:attrGlobal='globatr' attrInGroup2='grp-atr' attrLocal='17'>\n" &
"\t<foo>1</foo>\n" &
"\t<bar>2.000000</bar>\n" &
"\t<ding>three</ding>\n" &
"</ns:e29aAndAttributes>\n\n";

testcase tc_all() runs on POX
{
  CHECK_METHOD(bxer_enc_E29aaa, e29aa, bstr_e29aa);
  CHECK_METHOD(exer_enc_E29aaa, e29aa, estr_e29aa);
}

control {
  execute(tc_qual());
  execute(tc_unqual());
  execute(tc_aqual());
  execute(tc_both());
  execute(tc_all())
}

  
}


