Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
9ac139f0
Commit
9ac139f0
authored
Jun 20, 2024
by
v0-e
Committed by
Mouse
Jun 21, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jer: Add OCTET STRING JER tests
parent
96ea3a13
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
54 deletions
+91
-54
tests/tests-skeletons/check-OCTET_STRING.c
tests/tests-skeletons/check-OCTET_STRING.c
+91
-54
No files found.
tests/tests-skeletons/check-OCTET_STRING.c
View file @
9ac139f0
...
@@ -7,33 +7,58 @@
...
@@ -7,33 +7,58 @@
#include <BIT_STRING.h>
#include <BIT_STRING.h>
enum
encoding_type
{
HEX
,
BINARY
,
UTF8
};
enum
encoding_type
{
HEX
,
BINARY
,
UTF8
};
enum
encoding_rules
{
XER
,
JER
};
#define check(t, tag, buf, verify) check_impl(__LINE__, t, tag, buf, verify)
#define check_xer(t, tag, buf, verify) check_impl(__LINE__, XER, t, tag, buf, verify)
#define check_jer(t, buf, verify) check_impl(__LINE__, JER, t, NULL, buf, verify)
static
void
static
void
check_impl
(
int
lineno
,
enum
encoding_type
type
,
char
*
tagname
,
char
*
xmlbuf
,
char
*
verify
)
{
check_impl
(
int
lineno
,
enum
encoding_
rules
rules
,
enum
encoding_
type
type
,
char
*
tagname
,
char
*
xmlbuf
,
char
*
verify
)
{
size_t
xmllen
=
strlen
(
xmlbuf
);
size_t
xmllen
=
strlen
(
xmlbuf
);
size_t
verlen
=
verify
?
strlen
(
verify
)
:
0
;
size_t
verlen
=
verify
?
strlen
(
verify
)
:
0
;
asn_TYPE_descriptor_t
*
td
=
&
asn_DEF_OCTET_STRING
;
asn_TYPE_descriptor_t
*
td
=
&
asn_DEF_OCTET_STRING
;
OCTET_STRING_t
*
st
=
0
;
OCTET_STRING_t
*
st
=
0
;
OCTET_STRING_t
**
stp
=
&
st
;
OCTET_STRING_t
**
stp
=
&
st
;
asn_dec_rval_t
rc
;
asn_dec_rval_t
rc
;
xer_type_decoder_f
*
decoder
=
0
;
switch
(
rules
)
{
case
XER
:
;
xer_type_decoder_f
*
xer_decoder
=
0
;
switch
(
type
)
{
switch
(
type
)
{
case
HEX
:
case
HEX
:
decoder
=
OCTET_STRING_decode_xer_hex
;
xer_
decoder
=
OCTET_STRING_decode_xer_hex
;
break
;
break
;
case
BINARY
:
case
BINARY
:
td
=
&
asn_DEF_BIT_STRING
;
td
=
&
asn_DEF_BIT_STRING
;
decoder
=
OCTET_STRING_decode_xer_binary
;
xer_
decoder
=
OCTET_STRING_decode_xer_binary
;
break
;
break
;
case
UTF8
:
case
UTF8
:
decoder
=
OCTET_STRING_decode_xer_utf8
;
xer_
decoder
=
OCTET_STRING_decode_xer_utf8
;
break
;
break
;
}
}
rc
=
decoder
(
0
,
td
,
(
void
**
)
stp
,
tagname
,
xmlbuf
,
xmllen
);
rc
=
xer_decoder
(
0
,
td
,
(
void
**
)
stp
,
tagname
,
xmlbuf
,
xmllen
);
break
;
case
JER
:
;
jer_type_decoder_f
*
jer_decoder
=
0
;
switch
(
type
)
{
case
HEX
:
jer_decoder
=
OCTET_STRING_decode_jer_hex
;
break
;
case
UTF8
:
jer_decoder
=
OCTET_STRING_decode_jer_utf8
;
break
;
default:
/* Not supported */
assert
(
0
);
}
rc
=
jer_decoder
(
0
,
td
,
NULL
,
(
void
**
)
stp
,
xmlbuf
,
xmllen
);
break
;
}
printf
(
"%03d: [%s] => [%s]:%zu vs [%s]:%zu, code %d
\n
"
,
printf
(
"%03d: [%s] => [%s]:%zu vs [%s]:%zu, code %d
\n
"
,
lineno
,
xmlbuf
,
lineno
,
xmlbuf
,
st
?
(
const
char
*
)
st
->
buf
:
""
,
st
?
st
->
size
:
0
,
st
?
(
const
char
*
)
st
->
buf
:
""
,
st
?
st
->
size
:
0
,
...
@@ -86,62 +111,62 @@ encode(char *orig, char *encoded) {
...
@@ -86,62 +111,62 @@ encode(char *orig, char *encoded) {
int
int
main
()
{
main
()
{
check
(
HEX
,
0
,
"<OCTET_STRING>41424</OCTET_STRING>"
,
check
_xer
(
HEX
,
0
,
"<OCTET_STRING>41424</OCTET_STRING>"
,
"AB@"
);
"AB@"
);
check
(
HEX
,
0
,
"<!--comment--><OCTET_STRING>
\n
"
check
_xer
(
HEX
,
0
,
"<!--comment--><OCTET_STRING>
\n
"
"<!--comment-->41424</OCTET_STRING>"
,
"<!--comment-->41424</OCTET_STRING>"
,
"AB@"
);
"AB@"
);
check
(
HEX
,
0
,
"<OCTET_STRING blah blah> 4 1 4 2 4 5 44 </OCTET_STRING>"
,
check
_xer
(
HEX
,
0
,
"<OCTET_STRING blah blah> 4 1 4 2 4 5 44 </OCTET_STRING>"
,
"ABED"
);
"ABED"
);
/* Some hard cases */
/* Some hard cases */
check
(
HEX
,
"z"
,
"<z><!-- < -->40</z>"
,
"@"
);
check
_xer
(
HEX
,
"z"
,
"<z><!-- < -->40</z>"
,
"@"
);
check
(
HEX
,
"z"
,
"<z><!-- <-->40</z>"
,
"@"
);
check
_xer
(
HEX
,
"z"
,
"<z><!-- <-->40</z>"
,
"@"
);
check
(
HEX
,
"z"
,
"<z><!-- -->>40</z>"
,
0
);
check
_xer
(
HEX
,
"z"
,
"<z><!-- -->>40</z>"
,
0
);
check
(
HEX
,
"z"
,
"<z><!-- <some <sometag>-->40</z>"
,
"@"
);
check
_xer
(
HEX
,
"z"
,
"<z><!-- <some <sometag>-->40</z>"
,
"@"
);
check
(
HEX
,
"z"
,
"<z><!-- <some <sometag-->>40</z>"
,
0
);
check
_xer
(
HEX
,
"z"
,
"<z><!-- <some <sometag-->>40</z>"
,
0
);
check
(
HEX
,
"z"
,
"ignored<z>40</z>stuff"
,
"@"
);
check
_xer
(
HEX
,
"z"
,
"ignored<z>40</z>stuff"
,
"@"
);
check
(
HEX
,
"tag"
,
"<tag>4</tag>"
,
"@"
);
check
_xer
(
HEX
,
"tag"
,
"<tag>4</tag>"
,
"@"
);
check
(
HEX
,
"a-z"
,
"<a-z>7 375 73 6c6 9<!--/-->6 b</a-z>"
,
"suslik"
);
check
_xer
(
HEX
,
"a-z"
,
"<a-z>7 375 73 6c6 9<!--/-->6 b</a-z>"
,
"suslik"
);
/* This one has a comment in a not-yet-supported place */
/* This one has a comment in a not-yet-supported place */
/* check(HEX, "a-z", "<a-z>73 75 73 6c 6<!--/-->9 6b</a-z>",
/* check(HEX, "a-z", "<a-z>73 75 73 6c 6<!--/-->9 6b</a-z>",
"suslik"); */
"suslik"); */
check
(
BINARY
,
"tag"
,
"<tag/>"
,
""
);
check
_xer
(
BINARY
,
"tag"
,
"<tag/>"
,
""
);
check
(
BINARY
,
"tag"
,
"<tag>blah</tag>"
,
0
);
check
_xer
(
BINARY
,
"tag"
,
"<tag>blah</tag>"
,
0
);
check
(
BINARY
,
"tag"
,
"<tag>01000001</tag>"
,
"A"
);
check
_xer
(
BINARY
,
"tag"
,
"<tag>01000001</tag>"
,
"A"
);
check
(
BINARY
,
"tag"
,
"<tag>01000<!--blah--> 00 101 00001</tag>"
,
"AB"
);
check
_xer
(
BINARY
,
"tag"
,
"<tag>01000<!--blah--> 00 101 00001</tag>"
,
"AB"
);
check
(
UTF8
,
0
,
"<OCTET_STRING>one, two, three</OCTET_STRING>"
,
check
_xer
(
UTF8
,
0
,
"<OCTET_STRING>one, two, three</OCTET_STRING>"
,
"one, two, three"
);
"one, two, three"
);
check
(
UTF8
,
"z"
,
"<z></z>"
,
""
);
check
_xer
(
UTF8
,
"z"
,
"<z></z>"
,
""
);
check
(
UTF8
,
"z"
,
"<z z z><&></z z z>"
,
"<&>"
);
check
_xer
(
UTF8
,
"z"
,
"<z z z><&></z z z>"
,
"<&>"
);
check
(
UTF8
,
"z"
,
"<z z z>a<b&c>d</z z z>"
,
"a<b&c>d"
);
check
_xer
(
UTF8
,
"z"
,
"<z z z>a<b&c>d</z z z>"
,
"a<b&c>d"
);
check
(
UTF8
,
"z"
,
"<z z z>a<</z z z>"
,
"a<"
);
check
_xer
(
UTF8
,
"z"
,
"<z z z>a<</z z z>"
,
"a<"
);
check
(
UTF8
,
"z"
,
"<z z z>a&sdfsdfsdf;b</z z z>"
,
"a&sdfsdfsdf;b"
);
check
_xer
(
UTF8
,
"z"
,
"<z z z>a&sdfsdfsdf;b</z z z>"
,
"a&sdfsdfsdf;b"
);
check
(
UTF8
,
"z"
,
"<z z z>a b</z z z>"
,
"a b"
);
check
_xer
(
UTF8
,
"z"
,
"<z z z>a b</z z z>"
,
"a b"
);
check
(
UTF8
,
"z"
,
"<z z z>a b</z z z>"
,
"a b"
);
check
_xer
(
UTF8
,
"z"
,
"<z z z>a b</z z z>"
,
"a b"
);
check
(
UTF8
,
"z"
,
"<z>a繃b</z>"
,
"a
\347\271\203
b"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a繃b</z>"
,
"a
\347\271\203
b"
);
check
(
UTF8
,
"z"
,
"<z>a俄|</z>"
,
"a
\xe4\xbf\x84
|"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a俄|</z>"
,
"a
\xe4\xbf\x84
|"
);
/* Last unicode point */
/* Last unicode point */
check
(
UTF8
,
"z"
,
"<z>a|</z>"
,
"a
\xf4\x8f\xbf\xbf
|"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a|</z>"
,
"a
\xf4\x8f\xbf\xbf
|"
);
check
(
UTF8
,
"z"
,
"<z>a|</z>"
,
"a
\xf4\x8f\xbf\xbf
|"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a|</z>"
,
"a
\xf4\x8f\xbf\xbf
|"
);
/* One past the last unicode point */
/* One past the last unicode point */
check
(
UTF8
,
"z"
,
"<z>a�|</z>"
,
"a�|"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a�|</z>"
,
"a�|"
);
check
(
UTF8
,
"z"
,
"<z>a�|</z>"
,
"a�|"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a�|</z>"
,
"a�|"
);
check
(
UTF8
,
"z"
,
"<z>a�b</z>"
,
"a�b"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a�b</z>"
,
"a�b"
);
check
(
UTF8
,
"z"
,
"<z>a�b</z>"
,
"a�b"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a�b</z>"
,
"a�b"
);
check
(
UTF8
,
"z"
,
"<z>aĬ</z>"
,
"aĬ"
);
check
_xer
(
UTF8
,
"z"
,
"<z>aĬ</z>"
,
"aĬ"
);
check
(
UTF8
,
"z"
,
"<z>a&#-300;</z>"
,
"a&#-300;"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a&#-300;</z>"
,
"a&#-300;"
);
check
(
UTF8
,
"z"
,
"<z>a<ff/>b</z>"
,
"a
\014
b"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a<ff/>b</z>"
,
"a
\014
b"
);
check
(
UTF8
,
"z"
,
"<z>a<soh/>b</z>"
,
"a
\001
b"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a<soh/>b</z>"
,
"a
\001
b"
);
check
(
UTF8
,
"z"
,
"<z>a<bel/></z>"
,
"a
\007
"
);
check
_xer
(
UTF8
,
"z"
,
"<z>a<bel/></z>"
,
"a
\007
"
);
encode
(
""
,
""
);
encode
(
""
,
""
);
encode
(
"a"
,
"a"
);
encode
(
"a"
,
"a"
);
...
@@ -149,6 +174,18 @@ main() {
...
@@ -149,6 +174,18 @@ main() {
encode
(
"a
\b
c"
,
"a<bs/>c"
);
encode
(
"a
\b
c"
,
"a<bs/>c"
);
encode
(
"ab
\01
c
\n
def
\r\n
"
,
"ab<soh/>c
\n
def
\r\n
"
);
encode
(
"ab
\01
c
\n
def
\r\n
"
,
"ab<soh/>c
\n
def
\r\n
"
);
check_jer
(
HEX
,
"
\"\"
"
,
""
);
check_jer
(
HEX
,
"
\"
"
,
0
);
check_jer
(
HEX
,
""
,
0
);
check_jer
(
HEX
,
"
\"
6869
\"
"
,
"hi"
);
check_jer
(
HEX
,
"
\"
68 69
\"
"
,
0
);
check_jer
(
UTF8
,
"
\"\"
"
,
""
);
check_jer
(
UTF8
,
"
\"
"
,
0
);
check_jer
(
UTF8
,
""
,
0
);
check_jer
(
UTF8
,
"
\"
hi
\"
"
,
"hi"
);
check_jer
(
UTF8
,
"
\"
h i
\"
"
,
"h i"
);
return
0
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment