Commit 9ac139f0 authored by v0-e's avatar v0-e Committed by Mouse

jer: Add OCTET STRING JER tests

parent 96ea3a13
...@@ -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>&lt;&amp;&gt;</z z z>", "<&>"); check_xer(UTF8, "z", "<z z z>&lt;&amp;&gt;</z z z>", "<&>");
check(UTF8, "z", "<z z z>a&lt;b&amp;c&gt;d</z z z>", "a<b&c>d"); check_xer(UTF8, "z", "<z z z>a&lt;b&amp;c&gt;d</z z z>", "a<b&c>d");
check(UTF8, "z", "<z z z>a&lt</z z z>", "a&lt"); check_xer(UTF8, "z", "<z z z>a&lt</z z z>", "a&lt");
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&#x20;b</z z z>", "a b"); check_xer(UTF8, "z", "<z z z>a&#x20;b</z z z>", "a b");
check(UTF8, "z", "<z z z>a&#32;b</z z z>", "a b"); check_xer(UTF8, "z", "<z z z>a&#32;b</z z z>", "a b");
check(UTF8, "z", "<z>a&#32323;b</z>", "a\347\271\203b"); check_xer(UTF8, "z", "<z>a&#32323;b</z>", "a\347\271\203b");
check(UTF8, "z", "<z>a&#x4fc4;|</z>", "a\xe4\xbf\x84|"); check_xer(UTF8, "z", "<z>a&#x4fc4;|</z>", "a\xe4\xbf\x84|");
/* Last unicode point */ /* Last unicode point */
check(UTF8, "z", "<z>a&#x10ffff;|</z>", "a\xf4\x8f\xbf\xbf|"); check_xer(UTF8, "z", "<z>a&#x10ffff;|</z>", "a\xf4\x8f\xbf\xbf|");
check(UTF8, "z", "<z>a&#1114111;|</z>", "a\xf4\x8f\xbf\xbf|"); check_xer(UTF8, "z", "<z>a&#1114111;|</z>", "a\xf4\x8f\xbf\xbf|");
/* One past the last unicode point */ /* One past the last unicode point */
check(UTF8, "z", "<z>a&#x110000;|</z>", "a&#x110000;|"); check_xer(UTF8, "z", "<z>a&#x110000;|</z>", "a&#x110000;|");
check(UTF8, "z", "<z>a&#1114112;|</z>", "a&#1114112;|"); check_xer(UTF8, "z", "<z>a&#1114112;|</z>", "a&#1114112;|");
check(UTF8, "z", "<z>a&#3000000000;b</z>", "a&#3000000000;b"); check_xer(UTF8, "z", "<z>a&#3000000000;b</z>", "a&#3000000000;b");
check(UTF8, "z", "<z>a&#5000000000;b</z>", "a&#5000000000;b"); check_xer(UTF8, "z", "<z>a&#5000000000;b</z>", "a&#5000000000;b");
check(UTF8, "z", "<z>a&#300</z>", "a&#300"); check_xer(UTF8, "z", "<z>a&#300</z>", "a&#300");
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\014b"); check_xer(UTF8, "z", "<z>a<ff/>b</z>", "a\014b");
check(UTF8, "z", "<z>a<soh/>b</z>", "a\001b"); check_xer(UTF8, "z", "<z>a<soh/>b</z>", "a\001b");
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\bc", "a<bs/>c"); encode("a\bc", "a<bs/>c");
encode("ab\01c\ndef\r\n", "ab<soh/>c\ndef\r\n"); encode("ab\01c\ndef\r\n", "ab<soh/>c\ndef\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;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment