/******************************************************************************
 * 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
 *
 ******************************************************************************/
module AttribPathTest
{
modulepar boolean AttribPathTest_verbose := false;
#define verbose AttribPathTest_verbose

#include "../macros.ttcnin"

import from AttribPath all;
import from Flattener { function all }

type component Broadway {}

DECLARE_EXER_ENCODERS(pozicio, pos);
DECLARE_XER_ENCODERS (pozicio, pos);

const pozicio prima := { 2.0, 3.0, 5.0 }

// pozicio is inside a group with "name as uppercased"
// and x,y,z all have "name as" attributes 
const universal charstring etalon_ext :=
"<POZICIO>\n" &
"\t<width>2.000000</width>\n" &
"\t<depth>3.000000</depth>\n" &
"\t<height>5.000000</height>\n" &
"</POZICIO>\n\n"
;

// Basic XER ignores encoding instructions
const universal charstring etalon_basic :=
"<pozicio>\n" &
"\t<x>2.000000</x>\n" &
"\t<y>3.000000</y>\n" &
"\t<z>5.000000</z>\n" &
"</pozicio>\n\n"
;

testcase enc_upcase() runs on Broadway
{
    CHECK_METHOD(exer_enc_pos, prima, etalon_ext)
    CHECK_METHOD(bxer_enc_pos, prima, etalon_basic);
}

testcase dec_upcase() runs on Broadway
{
    CHECK_DECODE(exer_dec_pos, etalon_ext           , pozicio, prima);
    CHECK_DECODE(exer_dec_pos, flatten(etalon_ext)  , pozicio, prima);
    CHECK_DECODE(bxer_dec_pos, etalon_basic         , pozicio, prima);
}
/************************************************************************/

DECLARE_EXER_ENCODERS(LOWpoz, lopoz);
DECLARE_XER_ENCODERS (LOWpoz, lopoz);

const LOWpoz loworugo := { 6.0, 6.6, 6.66 }

// LOWpoz is in a group with "name as lowercased" 
const universal charstring etalon_low :=
"<lowpoz>\n" &
"\t<width>6.000000</width>\n" &
"\t<depth>6.600000</depth>\n" &
"\t<height>6.660000</height>\n" &
"</lowpoz>\n\n"
;

// Basic XER for lowpoz
const universal charstring etalon_low_basic :=
"<LOWpoz>\n" &
"\t<x>6.000000</x>\n" &
"\t<y>6.600000</y>\n" &
"\t<z>6.660000</z>\n" &
"</LOWpoz>\n\n"
;

testcase enc_locase() runs on Broadway
{
    CHECK_METHOD(exer_enc_lopoz, loworugo, etalon_low);
    CHECK_METHOD(bxer_enc_lopoz, loworugo, etalon_low_basic);
}

testcase dec_locase() runs on Broadway
{
    CHECK_DECODE(exer_dec_lopoz, etalon_low         , LOWpoz, loworugo);
    CHECK_DECODE(exer_dec_lopoz, flatten(etalon_low), LOWpoz, loworugo);
    CHECK_DECODE(bxer_dec_lopoz, etalon_low_basic   , LOWpoz, loworugo);
}

/************************************************************************/

DECLARE_EXER_ENCODERS(bigpoz, bp);
DECLARE_XER_ENCODERS (bigpoz, bp);

const bigpoz bp := { 1.2, 3.4, 5.6 }

// bigpoz 
const universal charstring etalon_big :=
"<Bigpoz>\n" &
"\t<width>1.200000</width>\n" &
"\t<depth>3.400000</depth>\n" &
"\t<height>5.600000</height>\n" &
"</Bigpoz>\n\n"
;

// Basic XER for bigpoz
const universal charstring etalon_big_basic :=
"<bigpoz>\n" &
"\t<x>1.200000</x>\n" &
"\t<y>3.400000</y>\n" &
"\t<z>5.600000</z>\n" &
"</bigpoz>\n\n"
;

testcase enc_capital() runs on Broadway
{
    CHECK_METHOD(exer_enc_bp, bp, etalon_big);
    CHECK_METHOD(bxer_enc_bp, bp, etalon_big_basic);
}

testcase dec_capital() runs on Broadway
{
    CHECK_DECODE(exer_dec_bp, etalon_big         , bigpoz, bp);
    CHECK_DECODE(exer_dec_bp, flatten(etalon_big), bigpoz, bp);
    CHECK_DECODE(bxer_dec_bp, etalon_big_basic   , bigpoz, bp);
}

/************************************************************************/

DECLARE_EXER_ENCODERS(SMallpoz, spoz);
DECLARE_XER_ENCODERS (SMallpoz, spoz);

const SMallpoz sp := { 1.2, 3.4, 5.6 }
    
// smallpoz 
const universal charstring etalon_small :=
"<sMallpoz>\n" &
"\t<width>1.200000</width>\n" &
"\t<depth>3.400000</depth>\n" &
"\t<height>5.600000</height>\n" &
"</sMallpoz>\n\n"
;

// Basic XER for smallpoz
const universal charstring etalon_small_basic :=
"<SMallpoz>\n" &
"\t<x>1.200000</x>\n" &
"\t<y>3.400000</y>\n" &
"\t<z>5.600000</z>\n" &
"</SMallpoz>\n\n"
;

testcase enc_uncapital() runs on Broadway
{
    CHECK_METHOD(exer_enc_spoz, sp, etalon_small);
    CHECK_METHOD(bxer_enc_spoz, sp, etalon_small_basic);
}

testcase dec_uncapital() runs on Broadway
{
    CHECK_DECODE(exer_dec_spoz, etalon_small         , SMallpoz, sp);
    CHECK_DECODE(exer_dec_spoz, flatten(etalon_small), SMallpoz, sp);
    CHECK_DECODE(bxer_dec_spoz, etalon_small_basic   , SMallpoz, sp);
}

/************************************************************************/

// vector is a record-of float with LIST
DECLARE_EXER_ENCODERS(vector, vec);
DECLARE_XER_ENCODERS(vector, vec);

const universal charstring vecstr0 := "<VECTOR>0.000000 0.000000 0.000000</VECTOR>\n\n";
const universal charstring vecstr1 := "<VECTOR>0.200000 0.300000 0.500000</VECTOR>\n\n";
const universal charstring vecstr3 := "<VECTOR>1.280000 2.560000 5.120000</VECTOR>\n\n";

const vector v0 := { 0.0, 0.0, 0.0 };
const vector v1 := { 0.2, 0.3, 0.5 };
const vector v3 := { 1.28, 2.56, 5.12 }; 

testcase enc_vector() runs on Broadway
{

    CHECK_METHOD(exer_enc_vec, v0, vecstr0);
    CHECK_METHOD(exer_enc_vec, v1, vecstr1);
    CHECK_METHOD(exer_enc_vec, v3, vecstr3);
}

testcase dec_vector() runs on Broadway
{
    CHECK_DECODE(exer_dec_vec, vecstr0, vector, v0);
    CHECK_DECODE(exer_dec_vec, vecstr1, vector, v1);
    CHECK_DECODE(exer_dec_vec, vecstr3, vector, v3);
}

/************************************************************************/

DECLARE_XER_ENCODERS(stringlist, sl);
DECLARE_EXER_ENCODERS(stringlist, sl);
DECLARE_XER_ENCODERS(ustringlist, usl);
DECLARE_EXER_ENCODERS(ustringlist, usl);

const stringlist three_strings := { "foo", "bar", "baz" }
const ustringlist three_ustrings := { "foo", "bar", "baz" }

const universal charstring s3_e :=
"<stringlist>foo bar baz</stringlist>\n\n";

const universal charstring us3_e :=
"<ustringlist>foo bar baz</ustringlist>\n\n";

const universal charstring s3_b :=
"<stringlist>\n" &
"\t<CHARSTRING>foo</CHARSTRING>\n" &
"\t<CHARSTRING>bar</CHARSTRING>\n" &
"\t<CHARSTRING>baz</CHARSTRING>\n" &
"</stringlist>\n\n";

const universal charstring us3_b :=
"<ustringlist>\n" &
"\t<UNIVERSAL_CHARSTRING>foo</UNIVERSAL_CHARSTRING>\n" &
"\t<UNIVERSAL_CHARSTRING>bar</UNIVERSAL_CHARSTRING>\n" &
"\t<UNIVERSAL_CHARSTRING>baz</UNIVERSAL_CHARSTRING>\n" &
"</ustringlist>\n\n";

testcase enc_stringlist() runs on Broadway
{
    CHECK_METHOD(exer_enc_sl, three_strings, s3_e);
    CHECK_METHOD(bxer_enc_sl, three_strings, s3_b);

    CHECK_METHOD(exer_enc_usl, three_ustrings, us3_e);
    CHECK_METHOD(bxer_enc_usl, three_ustrings, us3_b);
}

testcase dec_stringlist() runs on Broadway
{
    CHECK_DECODE(bxer_dec_usl, us3_b, ustringlist, three_ustrings);
    CHECK_DECODE(exer_dec_usl, us3_e, ustringlist, three_ustrings);

    CHECK_DECODE(bxer_dec_sl, s3_b, stringlist, three_strings);
    CHECK_DECODE(exer_dec_sl, s3_e, stringlist, three_strings);
}

/************************************************************************/

control {
    execute( enc_upcase() );
    execute( enc_locase() );
    execute( enc_capital() );
    execute( enc_uncapital() );

    execute( dec_upcase() );
    execute( dec_locase() );
    execute( dec_capital() );
    execute( dec_uncapital() );
    
    execute( enc_vector() );
    execute( dec_vector() );

    execute( enc_stringlist() );
    execute( dec_stringlist() );
}

}
