diff --git a/tests/tests-skeletons/check-OCTET_STRING.c b/tests/tests-skeletons/check-OCTET_STRING.c index 2581cdc68..84ee7335d 100644 --- a/tests/tests-skeletons/check-OCTET_STRING.c +++ b/tests/tests-skeletons/check-OCTET_STRING.c @@ -7,33 +7,58 @@ #include 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 -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 verlen = verify ? strlen(verify) : 0; asn_TYPE_descriptor_t *td = &asn_DEF_OCTET_STRING; OCTET_STRING_t *st = 0; OCTET_STRING_t **stp = &st; asn_dec_rval_t rc; - xer_type_decoder_f *decoder = 0; - - switch(type) { - case HEX: - decoder = OCTET_STRING_decode_xer_hex; - break; - case BINARY: - td = &asn_DEF_BIT_STRING; - decoder = OCTET_STRING_decode_xer_binary; - break; - case UTF8: - decoder = OCTET_STRING_decode_xer_utf8; - break; - } - - rc = decoder(0, td, (void **)stp, tagname, xmlbuf, xmllen); + switch(rules) { + case XER: + ; + xer_type_decoder_f *xer_decoder = 0; + + switch(type) { + case HEX: + xer_decoder = OCTET_STRING_decode_xer_hex; + break; + case BINARY: + td = &asn_DEF_BIT_STRING; + xer_decoder = OCTET_STRING_decode_xer_binary; + break; + case UTF8: + xer_decoder = OCTET_STRING_decode_xer_utf8; + break; + } + + 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", lineno, xmlbuf, st ? (const char *)st->buf : "", st ? st->size : 0, @@ -86,62 +111,62 @@ encode(char *orig, char *encoded) { int main() { - check(HEX, 0, "41424", + check_xer(HEX, 0, "41424", "AB@"); - check(HEX, 0, "\n" + check_xer(HEX, 0, "\n" "41424", "AB@"); - check(HEX, 0, " 4 1 4 2 4 5 44 ", + check_xer(HEX, 0, " 4 1 4 2 4 5 44 ", "ABED"); /* Some hard cases */ - check(HEX, "z", "40", "@"); - check(HEX, "z", "40", "@"); - check(HEX, "z", ">40", 0); - check(HEX, "z", "40", "@"); - check(HEX, "z", ">40", 0); + check_xer(HEX, "z", "40", "@"); + check_xer(HEX, "z", "40", "@"); + check_xer(HEX, "z", ">40", 0); + check_xer(HEX, "z", "40", "@"); + check_xer(HEX, "z", ">40", 0); - check(HEX, "z", "ignored40stuff", "@"); + check_xer(HEX, "z", "ignored40stuff", "@"); - check(HEX, "tag", "4", "@"); - check(HEX, "a-z", "7 375 73 6c6 96 b", "suslik"); + check_xer(HEX, "tag", "4", "@"); + check_xer(HEX, "a-z", "7 375 73 6c6 96 b", "suslik"); /* This one has a comment in a not-yet-supported place */ /* check(HEX, "a-z", "73 75 73 6c 69 6b", "suslik"); */ - check(BINARY, "tag", "", ""); - check(BINARY, "tag", "blah", 0); - check(BINARY, "tag", "01000001", "A"); - check(BINARY, "tag", "01000 00 101 00001", "AB"); + check_xer(BINARY, "tag", "", ""); + check_xer(BINARY, "tag", "blah", 0); + check_xer(BINARY, "tag", "01000001", "A"); + check_xer(BINARY, "tag", "01000 00 101 00001", "AB"); - check(UTF8, 0, "one, two, three", + check_xer(UTF8, 0, "one, two, three", "one, two, three"); - check(UTF8, "z", "", ""); - check(UTF8, "z", "<&>", "<&>"); - check(UTF8, "z", "a<b&c>d", "ad"); - check(UTF8, "z", "a<", "a<"); - check(UTF8, "z", "a&sdfsdfsdf;b", "a&sdfsdfsdf;b"); - check(UTF8, "z", "a b", "a b"); - check(UTF8, "z", "a b", "a b"); - check(UTF8, "z", "a繃b", "a\347\271\203b"); - check(UTF8, "z", "a俄|", "a\xe4\xbf\x84|"); + check_xer(UTF8, "z", "", ""); + check_xer(UTF8, "z", "<&>", "<&>"); + check_xer(UTF8, "z", "a<b&c>d", "ad"); + check_xer(UTF8, "z", "a<", "a<"); + check_xer(UTF8, "z", "a&sdfsdfsdf;b", "a&sdfsdfsdf;b"); + check_xer(UTF8, "z", "a b", "a b"); + check_xer(UTF8, "z", "a b", "a b"); + check_xer(UTF8, "z", "a繃b", "a\347\271\203b"); + check_xer(UTF8, "z", "a俄|", "a\xe4\xbf\x84|"); /* Last unicode point */ - check(UTF8, "z", "a􏿿|", "a\xf4\x8f\xbf\xbf|"); - check(UTF8, "z", "a􏿿|", "a\xf4\x8f\xbf\xbf|"); + check_xer(UTF8, "z", "a􏿿|", "a\xf4\x8f\xbf\xbf|"); + check_xer(UTF8, "z", "a􏿿|", "a\xf4\x8f\xbf\xbf|"); /* One past the last unicode point */ - check(UTF8, "z", "a�|", "a�|"); - check(UTF8, "z", "a�|", "a�|"); - check(UTF8, "z", "a�b", "a�b"); - check(UTF8, "z", "a�b", "a�b"); - check(UTF8, "z", "", "aĬ"); - check(UTF8, "z", "a&#-300;", "a&#-300;"); - check(UTF8, "z", "ab", "a\014b"); - check(UTF8, "z", "ab", "a\001b"); - check(UTF8, "z", "a", "a\007"); + check_xer(UTF8, "z", "a�|", "a�|"); + check_xer(UTF8, "z", "a�|", "a�|"); + check_xer(UTF8, "z", "a�b", "a�b"); + check_xer(UTF8, "z", "a�b", "a�b"); + check_xer(UTF8, "z", "", "aĬ"); + check_xer(UTF8, "z", "a&#-300;", "a&#-300;"); + check_xer(UTF8, "z", "ab", "a\014b"); + check_xer(UTF8, "z", "ab", "a\001b"); + check_xer(UTF8, "z", "a", "a\007"); encode("", ""); encode("a", "a"); @@ -149,6 +174,18 @@ main() { encode("a\bc", "ac"); encode("ab\01c\ndef\r\n", "abc\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; }