lynxis lazus has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-asn1-tcap/+/42744?usp=email )


Change subject: tests: split tests into own functions
......................................................................

tests: split tests into own functions

To improve overview.

Change-Id: If9db94d17e288875fdaed52ec95b3785a78d5fa6
---
M tests/parse/tcap_parse_test.c
M tests/parse/tcap_parse_test.ok
2 files changed, 40 insertions(+), 20 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-asn1-tcap 
refs/changes/44/42744/1

diff --git a/tests/parse/tcap_parse_test.c b/tests/parse/tcap_parse_test.c
index 540621b..a927b39 100644
--- a/tests/parse/tcap_parse_test.c
+++ b/tests/parse/tcap_parse_test.c
@@ -38,29 +38,12 @@
        { .name = "Begin", .vector = pkt_begin, .vector_len = sizeof(pkt_begin) 
},
 };

-int main(int argc, char **argv)
+static int encode_tests(void)
 {
-       asn_dec_rval_t rc;
-
-       printf("Basic TCAP decode testing.\n");
-       struct TCAP_TCMessage _tcapmsg = {};
-
-       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);
-
-               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};

+       printf("Basic TCAP encode testing.\n");
+
        struct TCAP_TCMessage msg = {
                .present = TCAP_TCMessage_PR_begin,
                .choice.begin = {
@@ -72,6 +55,42 @@
        };

        der_encode(&asn_DEF_TCAP_TCMessage, &msg, write_stream, NULL);
+       return 0;
+}
+
+static int decode_tests(void)
+{
+       int ret = 0;
+       asn_dec_rval_t rc;
+
+       printf("Basic TCAP decode testing.\n");
+       struct TCAP_TCMessage _tcapmsg = {};
+
+       for (int i = 0; i < ARRAY_SIZE(testvectors); i++) {
+               printf("Decoding testvector no %i - %s\n", i, 
testvectors[i].name);
+               struct TCAP_TCMessage *tcapmsg = &_tcapmsg;
+
+               memset(tcapmsg, 0, sizeof(*tcapmsg));
+               rc = ber_decode(0, &asn_DEF_TCAP_TCMessage, (void **)&tcapmsg, 
testvectors[i].vector, testvectors[i].vector_len);
+               if (rc.code != RC_OK) {
+                       ret = 1;
+                       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);
+       }
+
+       return ret;
+}
+
+int main(int argc, char **argv)
+{
+       if (decode_tests())
+               return 1;
+
+       if (encode_tests())
+               return 1;

        printf("All tests passed.\n");
        return 0;
diff --git a/tests/parse/tcap_parse_test.ok b/tests/parse/tcap_parse_test.ok
index 1061d2e..ed3eac1 100644
--- a/tests/parse/tcap_parse_test.ok
+++ b/tests/parse/tcap_parse_test.ok
@@ -3,6 +3,7 @@
 Begin ::= {
     otid: 00 01 02 03
 }
+Basic TCAP encode testing.
 62 06
 48 04
 00 01 02 03

--
To view, visit https://gerrit.osmocom.org/c/libosmo-asn1-tcap/+/42744?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: libosmo-asn1-tcap
Gerrit-Branch: master
Gerrit-Change-Id: If9db94d17e288875fdaed52ec95b3785a78d5fa6
Gerrit-Change-Number: 42744
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <[email protected]>

Reply via email to