/******************************************************************************
 * 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 oct_to_OK {

type component PDTestComponent {};

/*--- OCT2BIT --------------------------------------------------*/

modulepar bitstring o2bpar := oct2bit(''O)

modulepar bitstring o2bpar1 := oct2bit('000000'O & ''O & '111111'O)
modulepar bitstring o2bpar2 := oct2bit(substr('000000111111'O,0,3) & ''O & substr('000000111111'O,3,3))
modulepar bitstring o2bpar3 := oct2bit(('000000'O <@ 3) & ''O & ('111111'O @> 3))
modulepar bitstring o2bpar4 := oct2bit((not4b 'FFFFFF'O) & '111111'O)
modulepar bitstring o2bpar5 := oct2bit('000000111111'O and4b '000000111111'O)
modulepar bitstring o2bpar6 := oct2bit('000000000000'O or4b  '000000111111'O)
modulepar bitstring o2bpar7 := oct2bit('000000000000'O xor4b '000000111111'O)

const bitstring o2bparb := '000000000000000000000000000100010001000100010001'B

testcase oct_to_bit() runs on PDTestComponent{

	if ((o2bpar == oct2bit(''O))
	and (o2bpar == ''B))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2bpar1 == oct2bit('000000'O & ''O & '111111'O))
	and (o2bpar1 == o2bparb))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2bpar2 == oct2bit(substr('000000111111'O,0,3) & ''O & substr('000000111111'O,3,3)))
	and (o2bpar2 == o2bparb))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2bpar3 == oct2bit(('000000'O <@ 3) & ''O & ('111111'O @> 3)))
	and (o2bpar3 == o2bparb))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2bpar4 == oct2bit((not4b 'FFFFFF'O) & '111111'O))
	and (o2bpar4 == o2bparb))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2bpar5 == oct2bit('000000111111'O and4b '000000111111'O))
	and (o2bpar5 == o2bparb))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2bpar6 == oct2bit('000000000000'O or4b  '000000111111'O))
	and (o2bpar6 == o2bparb))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2bpar7 == oct2bit('000000000000'O xor4b '000000111111'O))
	and (o2bpar7 == o2bparb))
	     {setverdict(pass);}
	else {setverdict(fail);}

}

/*--- OCT2CHAR --------------------------------------------------*/


modulepar charstring o2cpar1 :=  oct2char(''O)
modulepar charstring o2cpar2 :=  oct2char('41'O)
modulepar charstring o2cpar3 :=  oct2char(''O & '41'O)
modulepar charstring o2cpar4 :=  oct2char('4142434445464748494A4B4C4D4E4F505152535455565758595A'O)

testcase oct_to_char() runs on PDTestComponent{

	if ((o2cpar1 == oct2char(''O))
	and (o2cpar1 == ""))
	     {setverdict(pass);}
	else {setverdict(fail);}
	if ((o2cpar2 == oct2char('41'O))
	and (o2cpar2 == "A"))
	     {setverdict(pass);}
	else {setverdict(fail);}
	if ((o2cpar3 == oct2char(''O & '41'O))
	and (o2cpar3 == "A"))
	     {setverdict(pass);}
	else {setverdict(fail);}
	if ((o2cpar4 == oct2char('4142434445464748494A4B4C4D4E4F505152535455565758595A'O))
	and (o2cpar4 == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
	     {setverdict(pass);}
	else {setverdict(fail);}

}


/*--- OCT2HEX --------------------------------------------------*/

modulepar hexstring o2hpar := oct2hex(''O)
modulepar hexstring o2hpar1 := oct2hex('000000'O & ''O & '111111'O)
modulepar hexstring o2hpar2 := oct2hex(substr('000000111111'O,0,3) & ''O & substr('000000111111'O,3,3))
modulepar hexstring o2hpar3 := oct2hex(('000000'O <@ 3) & ''O & ('111111'O @> 3))
modulepar hexstring o2hpar4 := oct2hex((not4b 'FFFFFF'O) & '111111'O)
modulepar hexstring o2hpar5 := oct2hex('000000111111'O and4b '000000111111'O)
modulepar hexstring o2hpar6 := oct2hex('000000000000'O or4b  '000000111111'O)
modulepar hexstring o2hpar7 := oct2hex('000000000000'O xor4b '000000111111'O)

modulepar hexstring o2hparh := '000000111111'H

testcase oct_to_hex() runs on PDTestComponent{


	if ((o2hpar == oct2hex(''O))
	and (o2hpar == ''H))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2hpar1 == oct2hex('000000'O & ''O & '111111'O))
	and (o2hpar1 == o2hparh))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2hpar2 == oct2hex(substr('000000111111'O,0,3) & ''O & substr('000000111111'O,3,3)))
	and (o2hpar2 == o2hparh))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2hpar3 == oct2hex(('000000'O <@ 3) & ''O & ('111111'O @> 3)))
	and (o2hpar3 == o2hparh))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2hpar4 == oct2hex((not4b 'FFFFFF'O) & '111111'O))
	and (o2hpar4 == o2hparh))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2hpar5 == oct2hex('000000111111'O and4b '000000111111'O))
	and (o2hpar5 == o2hparh))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2hpar6 == oct2hex('000000000000'O or4b  '000000111111'O))
	and (o2hpar6 == o2hparh))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2hpar7 == oct2hex('000000000000'O xor4b '000000111111'O))
	and (o2hpar7 == o2hparh))
	     {setverdict(pass);}
	else {setverdict(fail);}

}

/*--- OCT2INT --------------------------------------------------*/

modulepar integer o2ipar := oct2int(''O)
modulepar integer o2ipar1 := oct2int('FF'O & 'FFFF'O)
modulepar integer o2ipar2 := oct2int((not4b 'FF'O) & 'FFFF'O)
modulepar integer o2ipar3 := oct2int(('FF'O and4b '00'O) & 'FFFF'O)
modulepar integer o2ipar4 := oct2int(('00'O or4b '00'O) & 'FFFF'O)
modulepar integer o2ipar5 := oct2int(('0F'O xor4b '0F'O) & 'FFFF'O)

testcase oct_to_int() runs on PDTestComponent{
	var integer b;
	var integer i1 := 12345678910111213141516
	var octetstring os1 := '00000000000000000000000000000000000000000000029D42B65689328BBE0C'O
	if ((o2ipar == oct2int(''O))
	and (o2ipar == 0))
	     {setverdict(pass);}
	else {setverdict(fail);}
	if ((o2ipar1 == oct2int('FF'O & 'FFFF'O))
	and (o2ipar1 == 16777215))
	     {setverdict(pass);}
	else {setverdict(fail);}
	b := oct2int((not4b 'FF'O) & 'FFFF'O)
	if ((o2ipar2 == b)
	and (o2ipar2 == 65535))
	     {setverdict(pass);}
	else {setverdict(fail);}
	b := oct2int(('FF'O and4b '00'O) & 'FFFF'O)
	if ((o2ipar3 == b)
	and (o2ipar3 == 65535))
	     {setverdict(pass);}
	else {setverdict(fail);}
	b := oct2int(('00'O or4b '00'O) & 'FFFF'O)
	if ((o2ipar4 == b)
	and (o2ipar4 == 65535))
	     {setverdict(pass);}
	else {setverdict(fail);}
	b := oct2int(('0F'O xor4b '0F'O) & 'FFFF'O)
	if ((o2ipar5 == b)
	and (o2ipar5 == 65535))
	     {setverdict(pass);}
	else {setverdict(fail);}
	var integer j
	for (j:=0; j<256; j:=j+1) {
		if (oct2int(int2oct(j,1)) == j)
	     {setverdict(pass);}
	else {setverdict(fail);}
	}
	if (oct2int(os1) == i1) { setverdict(pass) } else { setverdict(fail) }
	//compile-time: if (oct2int('00000000000000000000000000000000000000000000029D42B65689328BBE0C'O) == 12345678910111213141516) { setverdict(pass) } else { setverdict(fail) }
	if (oct2int('00000000000000000000000000000000000000000000029D42B65689328BBE0C'O) == i1) { setverdict(pass) } else { setverdict(fail) }
	if (oct2int('029D42B65689328BBE0C'O) == i1) { setverdict(pass) } else { setverdict(fail) }
}

/*--- OCT2STR --------------------------------------------------*/

modulepar charstring o2spar := oct2str(''O)
modulepar charstring o2spar1 := oct2str('000000'O & ''O & '111111'O)
modulepar charstring o2spar2 := oct2str(substr('000000111111'O,0,3) & ''O & substr('000000111111'O,3,3))
modulepar charstring o2spar3 := oct2str(('000000'O <@ 3) & ''O & ('111111'O @> 3))
modulepar charstring o2spar4 := oct2str((not4b 'FFFFFF'O) & '111111'O)
modulepar charstring o2spar5 := oct2str('000000111111'O and4b '000000111111'O)
modulepar charstring o2spar6 := oct2str('000000000000'O or4b  '000000111111'O)
modulepar charstring o2spar7 := oct2str('000000000000'O xor4b '000000111111'O)

modulepar charstring o2spars := "000000111111"

testcase oct_to_str() runs on PDTestComponent{


	if ((o2spar == oct2str(''O))
	and (o2spar == ""))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2spar1 == oct2str('000000'O & ''O & '111111'O))
	and (o2spar1 == o2spars))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2spar2 == oct2str(substr('000000111111'O,0,3) & ''O & substr('000000111111'O,3,3)))
	and (o2spar2 == o2spars))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2spar3 == oct2str(('000000'O <@ 3) & ''O & ('111111'O @> 3)))
	and (o2spar3 == o2spars))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2spar4 == oct2str((not4b 'FFFFFF'O) & '111111'O))
	and (o2spar4 == o2spars))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2spar5 == oct2str('000000111111'O and4b '000000111111'O))
	and (o2spar5 == o2spars))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2spar6 == oct2str('000000000000'O or4b  '000000111111'O))
	and (o2spar6 == o2spars))
	     {setverdict(pass);}
	else {setverdict(fail);}

	if ((o2spar7 == oct2str('000000000000'O xor4b '000000111111'O))
	and (o2spar7 == o2spars))
	     {setverdict(pass);}
	else {setverdict(fail);}

}


control {
	execute (oct_to_bit());
	execute (oct_to_char());
	execute (oct_to_hex());
	execute (oct_to_int());
	execute (oct_to_str());
}


}
