Skip to content
Snippets Groups Projects
Commit 1d0599f0 authored by ebensza's avatar ebensza
Browse files

added encvalue_unichar and decvalue_unichar built in functions (artf725502)


Signed-off-by: default avatarebensza <bence.janos.szabo@ericsson.com>
parent 1076e2d0
No related branches found
No related tags found
1 merge request!47added encvalue_unichar and decvalue_unichar built in functions (artf7…
This diff is collapsed.
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* Kovacs, Ferenc * Kovacs, Ferenc
* Raduly, Csaba * Raduly, Csaba
* Szabados, Kristof * Szabados, Kristof
* Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation * Szabo, Janos Zoltan – initial implementation
* Tatarka, Gabor * Tatarka, Gabor
* Zalanyi, Balazs Andor * Zalanyi, Balazs Andor
...@@ -259,6 +260,9 @@ namespace Common { ...@@ -259,6 +260,9 @@ namespace Common {
OPTYPE_LOG2STR, // logagrs OPTYPE_LOG2STR, // logagrs
OPTYPE_PROF_RUNNING, // - 99 OPTYPE_PROF_RUNNING, // - 99
OPTYPE_ENCVALUE_UNICHAR, // ti1 [v2]
OPTYPE_DECVALUE_UNICHAR, // r1 r2 [v3]
NUMBER_OF_OPTYPES // must be last NUMBER_OF_OPTYPES // must be last
}; };
...@@ -414,6 +418,8 @@ namespace Common { ...@@ -414,6 +418,8 @@ namespace Common {
Value(operationtype_t p_optype, Value *p_v1, Value *p_v2); Value(operationtype_t p_optype, Value *p_v1, Value *p_v2);
/** Constructor used by V_EXPR "v1 v2 v3" */ /** Constructor used by V_EXPR "v1 v2 v3" */
Value(operationtype_t p_optype, Value *p_v1, Value *p_v2, Value *p_v3); Value(operationtype_t p_optype, Value *p_v1, Value *p_v2, Value *p_v3);
/** Constructor used by encvalue_unichar "ti1 [v2]" */
Value(operationtype_t p_optype, TemplateInstance *p_ti1, Value *p_v2);
/** Constructor used by V_EXPR "ti1 v2 v3" */ /** Constructor used by V_EXPR "ti1 v2 v3" */
Value(operationtype_t p_optype, TemplateInstance *p_ti1, Value *p_v2, Value *p_v3); Value(operationtype_t p_optype, TemplateInstance *p_ti1, Value *p_v2, Value *p_v3);
/** Constructor used by V_EXPR "ti1 t2 v3" */ /** Constructor used by V_EXPR "ti1 t2 v3" */
...@@ -435,6 +441,8 @@ namespace Common { ...@@ -435,6 +441,8 @@ namespace Common {
Value(valuetype_t p_vt, verdict_t p_verdict); Value(valuetype_t p_vt, verdict_t p_verdict);
/** Constructor used by decode */ /** Constructor used by decode */
Value(operationtype_t p_optype, Ttcn::Ref_base *p_r1, Ttcn::Ref_base *p_r2); Value(operationtype_t p_optype, Ttcn::Ref_base *p_r1, Ttcn::Ref_base *p_r2);
/** Constructor used by decvalue_unichar*/
Value(operationtype_t p_optype, Ttcn::Ref_base *p_r1, Ttcn::Ref_base *p_r2, Value *p_v3);
virtual ~Value(); virtual ~Value();
virtual Value* clone() const; virtual Value* clone() const;
valuetype_t get_valuetype() const {return valuetype;} valuetype_t get_valuetype() const {return valuetype;}
...@@ -628,7 +636,8 @@ namespace Common { ...@@ -628,7 +636,8 @@ namespace Common {
Type::expected_value_t exp_val); Type::expected_value_t exp_val);
void chk_expr_operand_encode(ReferenceChain *refch, void chk_expr_operand_encode(ReferenceChain *refch,
Type::expected_value_t exp_val); Type::expected_value_t exp_val);
void chk_expr_operands_decode(); /** \a has two possible value: OPTYPE_DECODE | OPTYPE_DECVALUE_UNICHAR */
void chk_expr_operands_decode(operationtype_t p_optype);
/** Checks whether \a this can be compared with omit value (i.e. \a this /** Checks whether \a this can be compared with omit value (i.e. \a this
* should be a referenced value pointing to a optional record/set field. */ * should be a referenced value pointing to a optional record/set field. */
void chk_expr_omit_comparison(Type::expected_value_t exp_val); void chk_expr_omit_comparison(Type::expected_value_t exp_val);
...@@ -907,6 +916,12 @@ namespace Common { ...@@ -907,6 +916,12 @@ namespace Common {
void generate_code_expr_encode(expression_struct *expr); void generate_code_expr_encode(expression_struct *expr);
void generate_code_expr_decode(expression_struct *expr); void generate_code_expr_decode(expression_struct *expr);
void generate_code_expr_encvalue_unichar(expression_struct *expr);
void generate_code_expr_decvalue_unichar(expression_struct *expr);
char* generate_code_char_coding_check(expression_struct *expr, Value *v, const char *name);
/** Helper function for \a generate_code_init(). It handles the /** Helper function for \a generate_code_init(). It handles the
* union (CHOICE) values. */ * union (CHOICE) values. */
......
...@@ -585,6 +585,8 @@ remove_bom RETURN(remove_bomKeyWord); ...@@ -585,6 +585,8 @@ remove_bom RETURN(remove_bomKeyWord);
get_stringencoding RETURN(get_stringencodingKeyWord); get_stringencoding RETURN(get_stringencodingKeyWord);
encode_base64 RETURN(encode_base64KeyWord); encode_base64 RETURN(encode_base64KeyWord);
decode_base64 RETURN(decode_base64KeyWord); decode_base64 RETURN(decode_base64KeyWord);
encvalue_unichar RETURN(encvalue_unicharKeyWord);
decvalue_unichar RETURN(decvalue_unicharKeyWord);
/* Values */ /* Values */
......
...@@ -832,6 +832,8 @@ static const string anyname("anytype"); ...@@ -832,6 +832,8 @@ static const string anyname("anytype");
%token get_stringencodingKeyWord %token get_stringencodingKeyWord
%token encode_base64KeyWord %token encode_base64KeyWord
%token decode_base64KeyWord %token decode_base64KeyWord
%token encvalue_unicharKeyWord
%token decvalue_unicharKeyWord
/* Multi-character operators */ /* Multi-character operators */
...@@ -8739,6 +8741,43 @@ PredefinedOps: ...@@ -8739,6 +8741,43 @@ PredefinedOps:
$$ = new Value(Value::V_ERROR); $$ = new Value(Value::V_ERROR);
$$->set_location(infile, @$); $$->set_location(infile, @$);
} }
| encvalue_unicharKeyWord '(' optError TemplateInstance optError ',' optError
Expression optError ')'
{
$$ = new Value(Value::OPTYPE_ENCVALUE_UNICHAR, $4, $8);
$$->set_location(infile, @$);
}
| encvalue_unicharKeyWord '(' optError TemplateInstance optError ')'
{
$$ = new Value(Value::OPTYPE_ENCVALUE_UNICHAR, $4);
$$->set_location(infile, @$);
}
| encvalue_unicharKeyWord '(' error ')'
{
Template *t1 = new Template(Template::TEMPLATE_ERROR);
t1->set_location(infile, @3);
TemplateInstance *ti1 = new TemplateInstance(0, 0, t1);
ti1->set_location(infile, @3);
$$ = new Value(Value::OPTYPE_ENCVALUE_UNICHAR, ti1);
$$->set_location(infile, @$);
}
| decvalue_unicharKeyWord '(' optError DecValueArg optError ',' optError
DecValueArg optError ')'
{
$$ = new Value(Value::OPTYPE_DECVALUE_UNICHAR, $4, $8);
$$->set_location(infile, @$);
}
| decvalue_unicharKeyWord '(' optError DecValueArg optError ',' optError
DecValueArg optError ',' optError Expression optError ')'
{
$$ = new Value(Value::OPTYPE_DECVALUE_UNICHAR, $4, $8, $12);
$$->set_location(infile, @$);
}
| decvalue_unicharKeyWord '(' error ')'
{
$$ = new Value(Value::V_ERROR);
$$->set_location(infile, @$);
}
; ;
DecValueArg: DecValueArg:
......
/******************************************************************************
* Copyright (c) 2000-2016 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
*
* Contributors:
* Szabo, Bence Janos
*
******************************************************************************/
module EncDecvalueUnichar {
type integer Byte (-128 .. 127) with { variant "8 bit" };
type bitstring BStr16 with { variant "16 bit" };
type hexstring HStr;
type octetstring OStr;
type charstring CStr;
type universal charstring UStr;
// Component type
type component CT {}
// Test cases
testcase tc_byte() runs on CT
{
var Byte x := 30;
var universal charstring enc := encvalue_unichar(x, "UTF-8");
var Byte x_exp;
var integer res := decvalue_unichar(enc, x_exp, "UTF-8");
if (match(x_exp, x) and res == 0 and match(lengthof(enc),0)) {
setverdict(pass);
}
else {
setverdict(fail);
}
}
testcase tc_bstr() runs on CT
{
var BStr16 x := '0100010101110011'B;
var universal charstring enc := encvalue_unichar(x, "UTF-8");
var BStr16 x_exp;
var integer res := decvalue_unichar(enc, x_exp, "UTF-8");
if (match(x_exp, x) and res == 0 and match(lengthof(enc),0)) {
setverdict(pass);
}
else {
setverdict(fail);
}
// with default UTF-8 coding
x := '0100010101110011'B;
enc := encvalue_unichar(x);
res := decvalue_unichar(enc, x_exp);
if (match(x_exp, x) and res == 0 and match(lengthof(enc),0)) {
setverdict(pass);
}
else {
setverdict(fail);
}
}
testcase tc_hstr() runs on CT
{
var HStr x := '44'H;
var universal charstring enc := encvalue_unichar(x, "UTF-8");
var HStr x_exp;
var integer res := decvalue_unichar(enc, x_exp, "UTF-8");
if (match(x_exp, x) and res == 0 and match(lengthof(enc),0)) {
setverdict(pass);
}
else {
setverdict(fail);
}
}
testcase tc_ostr() runs on CT
{
var OStr x := '1255'O;
var universal charstring enc := encvalue_unichar(x, "UTF-8");
var OStr x_exp;
var integer res := decvalue_unichar(enc, x_exp, "UTF-8");
if (match(x_exp, x) and res == 0 and match(lengthof(enc),0)) {
setverdict(pass);
}
else {
setverdict(fail);
}
}
testcase tc_cstr() runs on CT
{
var CStr x := "CdVsBgAa";
var universal charstring enc := encvalue_unichar(x, "UTF-8");
var CStr x_exp;
var integer res := decvalue_unichar(enc, x_exp, "UTF-8");
if (match(x_exp, x) and res == 0 and match(lengthof(enc),0)) {
setverdict(pass);
}
else {
setverdict(fail);
}
}
testcase tc_ustr() runs on CT
{
var UStr x := "CdVsBgAa";
var universal charstring enc := encvalue_unichar(x, "UTF-8");
var UStr x_exp;
var integer res := decvalue_unichar(enc, x_exp, "UTF-8");
if (match(x_exp, x) and res == 0 and match(lengthof(enc),0)) {
setverdict(pass);
}
else {
setverdict(fail);
}
}
// Control part
control {
execute(tc_byte());
execute(tc_bstr());
execute(tc_hstr());
execute(tc_ostr());
execute(tc_cstr());
execute(tc_ustr());
}
}
with {
encode "RAW";
}
...@@ -20,7 +20,7 @@ include $(TOPDIR)/Makefile.regression ...@@ -20,7 +20,7 @@ include $(TOPDIR)/Makefile.regression
TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX) TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
TTCN3_MODULES = TucharstrOper.ttcn cstr_content.ttcn Common.ttcn UTF8Testcases.ttcn UTF16Testcases.ttcn UTF32Testcases.ttcn Base64Testcases.ttcn TTCN3_MODULES = TucharstrOper.ttcn cstr_content.ttcn Common.ttcn UTF8Testcases.ttcn UTF16Testcases.ttcn UTF32Testcases.ttcn Base64Testcases.ttcn EncDecvalueUnichar.ttcn
GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc) GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc)
GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh) GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
......
...@@ -30,3 +30,4 @@ UTF8Testcases.control ...@@ -30,3 +30,4 @@ UTF8Testcases.control
UTF16Testcases.control UTF16Testcases.control
UTF32Testcases.control UTF32Testcases.control
Base64Testcases.control Base64Testcases.control
EncDecvalueUnichar.control
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment