lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-asn1-tcap/+/42743?usp=email )
Change subject: tests: improve test infrastructure to support multiple test vectors ......................................................................
tests: improve test infrastructure to support multiple test vectors
Change-Id: I4a69167647dd0a8eb650b4c7cc47fd97928ebf5d --- M tests/parse/tcap_parse_test.c M tests/parse/tcap_parse_test.ok 2 files changed, 28 insertions(+), 10 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-asn1-tcap refs/changes/43/42743/1
diff --git a/tests/parse/tcap_parse_test.c b/tests/parse/tcap_parse_test.c index 0f44963..540621b 100644 --- a/tests/parse/tcap_parse_test.c +++ b/tests/parse/tcap_parse_test.c @@ -14,8 +14,9 @@ #include <osmocom/tcap/TCAP_OrigTransactionID.h> #include <stdlib.h>
- -static const unsigned char pkt1[] = {0x62, 0x06, 0x48, 0x04, 0x00, 0x01, 0x02, 0x03}; +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif /* ARRAY_SIZE */
static int write_stream(const void *buffer, size_t size, void *key) { @@ -26,21 +27,37 @@ return 0; }
+static const unsigned char pkt_begin[] = {0x62, 0x06, 0x48, 0x04, 0x00, 0x01, 0x02, 0x03}; + +struct testvector { + const char *name; + const unsigned char *vector; + size_t vector_len; +}; +static struct testvector testvectors[] = { + { .name = "Begin", .vector = pkt_begin, .vector_len = sizeof(pkt_begin) }, +}; + int main(int argc, char **argv) { asn_dec_rval_t rc; - struct TCAP_TCMessage *tcapmsg; - tcapmsg = CALLOC(1, sizeof(*tcapmsg));
printf("Basic TCAP decode testing.\n"); + struct TCAP_TCMessage _tcapmsg = {};
- rc = ber_decode(0, &asn_DEF_TCAP_TCMessage, (void **)&tcapmsg, pkt1, sizeof(pkt1)); - if (rc.code != RC_OK) - printf("Broken encoding %u at byte %lu\n", rc.code, rc.consumed); + for (int i = 0; i < ARRAY_SIZE(testvectors); i++) { + struct TCAP_TCMessage *tcapmsg = &_tcapmsg; + memset(tcapmsg, 0, sizeof(*tcapmsg)); + printf("Decoding testvector no %i - %s\n", i, testvectors[i].name);
- asn_fprint(stdout, &asn_DEF_TCAP_TCMessage, tcapmsg); - ASN_STRUCT_FREE(asn_DEF_TCAP_TCMessage, tcapmsg); - + rc = ber_decode(0, &asn_DEF_TCAP_TCMessage, (void **)&tcapmsg, testvectors[i].vector, testvectors[i].vector_len); + if (rc.code != RC_OK) { + printf("Broken encoding %u at byte %lu\n", rc.code, rc.consumed); + } else { + asn_fprint(stdout, &asn_DEF_TCAP_TCMessage, tcapmsg); + } + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_TCAP_TCMessage, tcapmsg); + }
uint8_t buf[] = {0x00, 0x01, 0x02, 0x03};
diff --git a/tests/parse/tcap_parse_test.ok b/tests/parse/tcap_parse_test.ok index 6c44530..1061d2e 100644 --- a/tests/parse/tcap_parse_test.ok +++ b/tests/parse/tcap_parse_test.ok @@ -1,4 +1,5 @@ Basic TCAP decode testing. +Decoding testvector no 0 - Begin Begin ::= { otid: 00 01 02 03 }