File 0620-Add-test-for-DEFAULT-used-with-OCTET-STRING.patch of Package erlang

From d3efb32359e59b2996cde916436ffa56aa2ffb19 Mon Sep 17 00:00:00 2001
From: Simon Cornish <zl9d97p02@sneakemail.com>
Date: Fri, 22 Feb 2019 16:20:12 -0800
Subject: [PATCH 1/6] Add test for DEFAULT used with OCTET STRING

---
 lib/asn1/test/Makefile                             |  1 +
 lib/asn1/test/asn1_SUITE.erl                       |  6 ++++
 .../test/asn1_SUITE_data/DefaultOctetString.asn    | 15 ++++++++++
 lib/asn1/test/testDefaultOctetString.erl           | 34 ++++++++++++++++++++++
 4 files changed, 56 insertions(+)
 create mode 100644 lib/asn1/test/asn1_SUITE_data/DefaultOctetString.asn
 create mode 100644 lib/asn1/test/testDefaultOctetString.erl

diff --git a/lib/asn1/test/Makefile b/lib/asn1/test/Makefile
index c38d1c6ebd..accc773951 100644
--- a/lib/asn1/test/Makefile
+++ b/lib/asn1/test/Makefile
@@ -72,6 +72,7 @@ MODULES= \
 	testSetTypeRefPrim \
 	testSetTypeRefSeq \
 	testSetTypeRefSet \
+	testDefaultOctetString \
 	testChoiceIndefinite \
 	testSetOf \
 	testSetOfCho \
diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl
index ab78678110..329115be08 100644
--- a/lib/asn1/test/asn1_SUITE.erl
+++ b/lib/asn1/test/asn1_SUITE.erl
@@ -99,6 +99,7 @@ groups() ->
        testChoTypeRefPrim,
        testChoTypeRefSeq,
        testChoTypeRefSet,
+       testDefaultOctetString,
        testMultipleLevels,
        testOpt,
        testSeqDefault,
@@ -430,6 +431,11 @@ testChoTypeRefSet(Config, Rule, Opts) ->
     asn1_test_lib:compile("ChoTypeRefSet", Config, [Rule|Opts]),
     testChoTypeRefSet:set(Rule).
 
+testDefaultOctetString(Config) -> test(Config, fun testDefaultOctetString/3).
+testDefaultOctetString(Config, Rule, Opts) ->
+    asn1_test_lib:compile("DefaultOctetString", Config, [Rule|Opts]),
+    testDefaultOctetString:dos(Rule).
+
 testMultipleLevels(Config) -> test(Config, fun testMultipleLevels/3).
 testMultipleLevels(Config, Rule, Opts) ->
     asn1_test_lib:compile("MultipleLevels", Config, [Rule|Opts]),
diff --git a/lib/asn1/test/asn1_SUITE_data/DefaultOctetString.asn b/lib/asn1/test/asn1_SUITE_data/DefaultOctetString.asn
new file mode 100644
index 0000000000..076e965d58
--- /dev/null
+++ b/lib/asn1/test/asn1_SUITE_data/DefaultOctetString.asn
@@ -0,0 +1,15 @@
+DefaultOctetString
+DEFINITIONS
+AUTOMATIC TAGS
+ ::=
+BEGIN
+Dos ::= SEQUENCE {
+	opt [2] OCTET STRING (SIZE(2..4)) OPTIONAL,
+	def [10] OCTET STRING (SIZE (1)) DEFAULT '05'H
+}
+
+dos Dos ::= {
+	opt '1234'H
+}
+
+END
diff --git a/lib/asn1/test/testDefaultOctetString.erl b/lib/asn1/test/testDefaultOctetString.erl
new file mode 100644
index 0000000000..82cd5810e5
--- /dev/null
+++ b/lib/asn1/test/testDefaultOctetString.erl
@@ -0,0 +1,34 @@
+-module(testDefaultOctetString).
+
+-export([dos/1]).
+
+-include_lib("common_test/include/ct.hrl").
+
+-record('Dos', {
+  opt = asn1_NOVALUE,
+  def = asn1_DEFAULT
+}).
+
+-define(def_DEFAULT, <<5>>).
+
+dos(Rules) ->
+    %% test roundtrip default
+    E1 = roundtrip(#'Dos'{}, #'Dos'{def = ?def_DEFAULT}),
+    %% test the value dos defined in the .asn file
+    E2 = roundtrip('DefaultOctetString':dos()),
+    %% sanity test a fully specified SEQUENCE
+    E3 = roundtrip(#'Dos'{opt = <<1,2,3>>, def = <<6>>}),
+    %% test def is/isn't encoded according to the value
+    if Rules == ber ->
+            <<48, 0>> = E1,
+            <<48, 4, 16#82, 2, 16#12, 16#34>> = E2,
+            <<48, 8, 16#82, 3, 1, 2, 3, 16#8A, 1, 6>> = E3;
+       true ->
+            ignore
+    end,
+    ok.
+
+roundtrip(Value) ->
+    roundtrip(Value, Value).
+roundtrip(Value, Exp) ->
+    asn1_test_lib:roundtrip('DefaultOctetString', 'Dos', Value, Exp).
-- 
2.16.4