From ab0736ad7609bee92d2b7191d4278f24b57c8552 Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Thu, 26 Oct 2017 09:38:00 +0200
Subject: [PATCH] OER coding fixes

Change-Id: I52fff0a33732784caf38e86115e515181e303e5d
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 compiler2/Type_chk.cc         |  8 +-------
 compiler2/record.c            |  2 +-
 compiler2/record_of.c         |  4 ++--
 core/Basetype.hh              |  2 +-
 core/OER.cc                   |  2 +-
 core2/Basetype2.cc            |  2 +-
 regression_test/OER/OER.ttcn  | 33 +++++++++++++++++++++++++++++++++
 regression_test/OER/Types.asn | 35 +++++++++++++++++++++++++++++++++++
 8 files changed, 75 insertions(+), 13 deletions(-)

diff --git a/compiler2/Type_chk.cc b/compiler2/Type_chk.cc
index 0bad3de58..5b7c9ee32 100644
--- a/compiler2/Type_chk.cc
+++ b/compiler2/Type_chk.cc
@@ -3084,14 +3084,8 @@ void Type::chk_oer() {
       if (t->get_sub_type()) {
         oerattrib->extendable = t->get_sub_type()->is_extendable();
       }
-      for (size_t i = 0; i < t->get_nof_comps(); i++) {
-        t->get_comp_byIndex(i)->get_type()->chk();
-      }
       break; }
-    case T_SEQOF: {
-      t->get_ofType()->chk();
-      break;
-    }
+    case T_SEQOF:
     case T_BOOL:
     case T_ENUM_A:
     case T_UTF8STRING:
diff --git a/compiler2/record.c b/compiler2/record.c
index d15ddc100..11f21314c 100644
--- a/compiler2/record.c
+++ b/compiler2/record.c
@@ -4746,7 +4746,7 @@ void defRecordClass1(const struct_def *sdef, output_struct *output)
           , sdef->elements[i].typedescrname);
       }
     }
-    if (sdef->has_opentypes) {
+    if (sdef->opentype_outermost) {
       src = mputstr(src,
         "  TTCN_EncDec_ErrorContext ec_1(\"While decoding opentypes: \");"
         "  TTCN_Type_list p_typelist;\n"
diff --git a/compiler2/record_of.c b/compiler2/record_of.c
index ef490901a..561784f0c 100644
--- a/compiler2/record_of.c
+++ b/compiler2/record_of.c
@@ -1680,9 +1680,9 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
          "  p_typelist.push(this);\n"
          "  TTCN_EncDec_ErrorContext ec_0(\"Component #\");\n"
          "  TTCN_EncDec_ErrorContext ec_1;\n"
-         "  for(int elem_i=0; elem_i<n_elements; elem_i++) {\n"
+         "  for(int elem_i=0; elem_i<val_ptr->n_elements; elem_i++) {\n"
          "    ec_1.set_msg(\"%%d: \", elem_i);\n"
-         "    value_elements[elem_i].OER_decode_opentypes(p_typelist,"
+         "    (*this)[elem_i].OER_decode_opentypes(p_typelist,"
          " p_buf, p_oer);\n"
          "  }\n"
          "  p_typelist.pop();\n"
diff --git a/core/Basetype.hh b/core/Basetype.hh
index 204027954..cf22a7ef5 100644
--- a/core/Basetype.hh
+++ b/core/Basetype.hh
@@ -397,7 +397,7 @@ public:
   virtual int encode_raw(TTCN_Buffer& p_buf) const;
   virtual int RAW_encode_negtest_raw(RAW_enc_tree& p_myleaf) const;
   virtual int JSON_encode_negtest_raw(JSON_Tokenizer&) const;
-  virtual int OER_encode_negtest_raw(JSON_Tokenizer&) const; //TODO
+  virtual int OER_encode_negtest_raw(TTCN_Buffer&) const; //TODO
 #endif
 
   /** Examines whether this message corresponds the tags in the
diff --git a/core/OER.cc b/core/OER.cc
index 927ef94c5..009f71853 100644
--- a/core/OER.cc
+++ b/core/OER.cc
@@ -22,7 +22,7 @@ void encode_oer_length(size_t num_bytes, TTCN_Buffer& buf, boolean seof) {
     buf.put_c(num_bytes);
   } else {
     size_t bytes = num_bytes;
-    // Encode length in maybe more than 1 bytes
+    // Encode length in maybe more than 1 byte
     size_t needed_bytes = 0;
     while (bytes != 0) {
       bytes >>= 8;
diff --git a/core2/Basetype2.cc b/core2/Basetype2.cc
index 47d760eeb..ad9641990 100644
--- a/core2/Basetype2.cc
+++ b/core2/Basetype2.cc
@@ -197,7 +197,7 @@ int Base_Type::JSON_encode_negtest_raw(JSON_Tokenizer&) const
   return 0;
 }
 
-int Base_Type::OER_encode_negtest_raw(JSON_Tokenizer&) const
+int Base_Type::OER_encode_negtest_raw(TTCN_Buffer&) const
 {
   TTCN_error("A value of type %s cannot be used as erroneous raw value for OER encoding.",
              get_descriptor()->name);
diff --git a/regression_test/OER/OER.ttcn b/regression_test/OER/OER.ttcn
index f8b4c8b38..94be9cbf6 100644
--- a/regression_test/OER/OER.ttcn
+++ b/regression_test/OER/OER.ttcn
@@ -2753,6 +2753,12 @@
      with { extension "prototype (convert) encode(OER)" }
   
     external function dec_Item(in octetstring stream) return Item
+     with { extension "prototype (convert) decode(OER)" }
+
+    external function enc_ErrorReturn(in ErrorReturn pdu) return octetstring
+     with { extension "prototype (convert) encode(OER)" }
+  
+    external function dec_ErrorReturn(in octetstring stream) return ErrorReturn
      with { extension "prototype (convert) decode(OER)" }
 
  	testcase tc_opentype() runs on EmptyCT {
@@ -2775,6 +2781,33 @@
  			setverdict(fail, "tc_opentype: ", match(pf, pfres));
  		}
 
+
+ 		var ErrorReturn er, erres;
+
+ 		er := {
+ 			errorCategory := "A",
+ 			errors := {
+ 				{
+ 					errorCode := 1,
+ 					errorInfo := {errorSet_1_Type := 365}
+ 				},
+ 				{
+ 					errorCode := 2,
+ 					errorInfo := {errorSet_2_Type := "If U can decode this, U can be happy. Smile! :-)"}
+ 				}
+ 			}
+ 		}
+
+ 		os := enc_ErrorReturn(er);
+ 		if (os != 'C041010201010302016D01023130496620552063616E206465636F646520746869732C20552063616E2062652068617070792E20536D696C6521203A2D29'O) {
+ 			setverdict(fail, "tc_opentype: ", match('C041010201010302016D01023130496620552063616E206465636F646520746869732C20552063616E2062652068617070792E20536D696C6521203A2D29'O, os));
+ 		}
+
+ 		erres := dec_ErrorReturn(os);
+ 		if (er != erres) {
+ 			setverdict(fail, "tc_opentype: ", match(er, erres));
+ 		}
+
  		setverdict(pass);
  	}
 
diff --git a/regression_test/OER/Types.asn b/regression_test/OER/Types.asn
index 21b63c4ce..e191a110f 100644
--- a/regression_test/OER/Types.asn
+++ b/regression_test/OER/Types.asn
@@ -371,4 +371,39 @@ dateOfBirth "19571111"},
 dateOfBirth "19590717"}}}
 
 
+
+ERROR-CLASS ::= CLASS
+{
+  &category	PrintableString(SIZE(1)),
+  &code		INTEGER,
+  &Type	DEFAULT INTEGER
+}
+WITH SYNTAX {&category &code [&Type]}
+
+ErrorSet ERROR-CLASS ::=
+{
+  {"A" 1 [1] INTEGER} |
+  {"A" 2 [1] VisibleString} |
+  {"B" 1 [1] PrintableString} |
+  {"B" 2 [1] BOOLEAN} |
+  oneErrorObject
+}
+
+oneErrorObject ERROR-CLASS ::= { "C" 3 ENUMERATED{foobar} }
+
+ErrorReturn ::= SEQUENCE
+{
+  errorCategory	ERROR-CLASS.&category ({ErrorSet}) OPTIONAL,
+  errors	SEQUENCE OF SEQUENCE
+  {
+    errorCode	ERROR-CLASS.&code({ErrorSet}{@errorCategory}),
+    errorInfo	[99] ERROR-CLASS.&Type({ErrorSet}{@errorCategory,@.errorCode})
+  } OPTIONAL
+}
+
+
+
+
+
+
 END
\ No newline at end of file
-- 
GitLab