/****************************************************************************** * Copyright (c) 2000-2014 Ericsson Telecom AB * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ // This module tests the following functions for UTF-8: // oct2unichar // unichar2oct // get_stringencoding module UTF8Testcases { import from Common all; const octetstring c_BOM_UTF8 :='EFBBBF'O //type component MTC {} //One letter tests //00-0F UTF-8 decoding octetstring to unicode //decoding is UTF-8 as default encoding testcase tc_UTF8_encodeDecode_BMP1_implicit() runs on MTC { var octetstring o:=''O; var octetstring o_expected:=''O; var universal charstring u1 := char(0,0,0,0); var universal charstring u2 := char(0,0,0,0); //converted for(var integer i:=0;i<128;i:=i+1) { u1 := int2unichar(i); o_expected := int2oct(i,1); log(o_expected); o:=unichar2oct(u1); if(o==o_expected) { setverdict(pass,"unichar2oct(",u1,") encoding ok"); } else { setverdict(fail,"unichar2oct(",u1,") encoding nok, expected: ",o_expected," received: ", o); } u2:= oct2unichar(o) log(u2); if(match(u2,u1)) { setverdict(pass,"matched :", match(u2,u1)); } else { setverdict(fail,"unmatched :", match(u2,u1)); } if( get_stringencoding(o) == "ASCII" ) { setverdict(pass,"encoding type ok"); } else { setverdict(fail,"encoding type nok, expected: UTF-8, received ", get_stringencoding(o) ); } } } //00-0F UTF-8 encoding octetstring to unicode testcase tc_UTF8_encodeDecode_BMP1_explicit() runs on MTC { var octetstring o:=''O; var octetstring o_expected:=''O; var universal charstring u1 := char(0,0,0,0); //expected var universal charstring u2 := char(0,0,0,0); //converted for(var integer i:=0;i<128;i:=i+1) { //unichar2oct, UTF-8 no bom u1 := int2unichar(i); o_expected := int2oct(i,1); log(o_expected); o:=unichar2oct(u1,"UTF-8"); //no BOM if(o==o_expected) { setverdict(pass,"unichar2oct(",u1,",\"UTF-8\") encoding is ok"); } else { setverdict(fail,"unichar2oct(",u1,"\"UTF-8\") encoding is nok"); } log(o); u2 := oct2unichar(o); //default:UTF-8 no bom log(u2); if(match(u2,u1)) { setverdict(pass); } else { setverdict(fail,"unmatched :", match(u2,u1)); } u2 := oct2unichar(o,"UTF-8"); // log(u2); if(match(u2,u1)) { setverdict(pass); } else { setverdict(fail,"unmatched :", match(u2,u1)); } //unichar2oct, UTF-8 BOM o_expected := c_BOM_UTF8 & o_expected; //bom o:=unichar2oct(u1,"UTF-8 BOM") if(o==o_expected) { setverdict(pass,"unichar2oct(",u1,") encoding ok"); } else { setverdict(fail,"unichar2oct(",u1,") encoding nok, expected ", o_expected,"received ",o ); } log(o); u2 := oct2unichar(o,"UTF-8"); log(u2); if(match(u2,u1)) { setverdict(pass); } else { setverdict(fail,"unmatched :", match(u2,u1)); } if( get_stringencoding(o) == "UTF-8" ) { setverdict(pass,"encoding type ok"); } else { setverdict(fail,"encoding type nok"); } if( unichar2oct(u2, "UTF-8 BOM") == o){ setverdict(pass, "converting back to octetstring is ok") } else { setverdict(fail,"converting back to octetstring is nok, expected: ",o , " received:",unichar2oct(u2) ); } } } //0080-0800 UTF-8 encoding octetstring to unicode // UTF-8, 2 bytes long testcase tc_UTF8_encodeDecode_BMP2_implicit() runs on MTC { var octetstring o:=''O; var octetstring o_expected:=''O; var universal charstring u1 := char(0,0,0,0); var universal charstring u2 := char(0,0,0,0); const integer L := oct2int('0080'O); const integer N := oct2int('0800'O); var bitstring bs :=''B; for( var integer i:=L; i