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


Change subject: Add test to ensure parsing works
......................................................................

Add test to ensure parsing works

Related: SYS#5423
Change-Id: I475afbb6145404934b0838f9b418c105bf65dca0
---
M Makefile.am
M configure.ac
A tests/Makefile.am
A tests/parse/Makefile.am
A tests/parse/tcap_parse_test.c
A tests/parse/tcap_parse_test.ok
A tests/testsuite.at
7 files changed, 135 insertions(+), 1 deletion(-)



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

diff --git a/Makefile.am b/Makefile.am
index 9e311a6..c165099 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,7 +8,7 @@
        echo $(VERSION) > $(distdir)/.tarball-version

 INCLUDES = $(all_includes) -I$(top_srcdir)/include/osmocom/tcap
-SUBDIRS = src include
+SUBDIRS = src tests include

 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libosmo-asn1-tcap.pc
diff --git a/configure.ac b/configure.ac
index 8e18a0f..5d66205 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,6 +5,7 @@
 AC_CONFIG_AUX_DIR([.])

 AM_INIT_AUTOMAKE([dist-bzip2 subdir-objects])
+AC_CONFIG_TESTDIR(tests)

 dnl kernel style compile messages
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -66,6 +67,8 @@
 AC_OUTPUT(
         libosmo-asn1-tcap.pc
         src/Makefile
+        tests/Makefile
+        tests/parse/Makefile
         include/Makefile
         include/osmocom/Makefile
         include/osmocom/tcap/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..ce671d7
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,40 @@
+SUBDIRS = parse
+
+# The `:;' works around a Bash 3.2 bug when the output is not writeable.
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+       :;{ \
+               echo '# Signature of the current package.' && \
+               echo 'm4_define([AT_PACKAGE_NAME],' && \
+               echo '  [$(PACKAGE_NAME)])' && \
+               echo 'm4_define([AT_PACKAGE_TARNAME],' && \
+               echo '  [$(PACKAGE_TARNAME)])' && \
+               echo 'm4_define([AT_PACKAGE_VERSION],' && \
+               echo '  [$(PACKAGE_VERSION)])' && \
+               echo 'm4_define([AT_PACKAGE_STRING],' && \
+               echo '  [$(PACKAGE_STRING)])' && \
+               echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \
+               echo '  [$(PACKAGE_BUGREPORT)])'; \
+               echo 'm4_define([AT_PACKAGE_URL],' && \
+               echo '  [$(PACKAGE_URL)])'; \
+             } >'$(srcdir)/package.m4'
+
+EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE)
+TESTSUITE = $(srcdir)/testsuite
+DISTCLEANFILES = atconfig
+
+check-local: atconfig $(TESTSUITE)
+       $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
+
+installcheck-local: atconfig $(TESTSUITE)
+       $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \
+               $(TESTSUITEFLAGS)
+
+clean-local:
+       test ! -f '$(TESTSUITE)' || \
+               $(SHELL) '$(TESTSUITE)' --clean
+
+AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te
+AUTOTEST = $(AUTOM4TE) --language=autotest
+$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
+       $(AUTOTEST) -I '$(srcdir)' -o [email protected] [email protected]
+       mv [email protected] $@
diff --git a/tests/parse/Makefile.am b/tests/parse/Makefile.am
new file mode 100644
index 0000000..d464e2a
--- /dev/null
+++ b/tests/parse/Makefile.am
@@ -0,0 +1,15 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_srcdir)/src
+AM_CFLAGS = -Wall
+AM_LDFLAGS = -static -no-install
+
+LDADD = $(top_builddir)/src/libosmo-asn1-tcap.la
+
+check_PROGRAMS = \
+       tcap_parse_test \
+       $(NULL)
+
+EXTRA_DIST = \
+       tcap_parse_test.ok \
+       $(NULL)
+
+tcap_parse_test_SOURCES = tcap_parse_test.c
diff --git a/tests/parse/tcap_parse_test.c b/tests/parse/tcap_parse_test.c
new file mode 100644
index 0000000..9e70bac
--- /dev/null
+++ b/tests/parse/tcap_parse_test.c
@@ -0,0 +1,60 @@
+/* TCAP parsing tests */
+#include <complex.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <osmocom/tcap/asn_codecs.h>
+#include <osmocom/tcap/constr_TYPE.h>
+#include <osmocom/tcap/OCTET_STRING.h>
+#include <osmocom/tcap/ber_decoder.h>
+
+#include <osmocom/tcap/asn_internal.h>
+#include <osmocom/tcap/TCAP_TCMessage.h>
+#include <osmocom/tcap/TCAP_OrigTransactionID.h>
+#include <stdlib.h>
+
+
+static const unsigned char pkt1[] = {0x62, 0x06, 0x48, 0x04, 0x00, 0x01, 0x02, 
0x03};
+
+static int write_stream(const void *buffer, size_t size, void *key) {
+       uint8_t *buf = (uint8_t *)buffer;
+       for (int i = 0; i < size; i++)
+               printf("%02X ", buf[i]);
+       printf("\n");
+       return 0;
+}
+
+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");
+
+       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);
+       }
+       asn_fprint(stdout, &asn_DEF_TCAP_TCMessage, tcapmsg);
+       ASN_STRUCT_FREE(asn_DEF_TCAP_TCMessage, tcapmsg);
+
+
+       uint8_t buf[] = {0x00, 0x01, 0x02, 0x03};
+
+       struct TCAP_TCMessage msg = {
+               .present = TCAP_TCMessage_PR_begin,
+               .choice.begin = {
+                       .otid = {
+                               .buf = buf,
+                               .size = 4,
+                       },
+               },
+       };
+
+       der_encode(&asn_DEF_TCAP_TCMessage, &msg, write_stream, NULL);
+
+       printf("All tests passed.\n");
+       return 0;
+}
diff --git a/tests/parse/tcap_parse_test.ok b/tests/parse/tcap_parse_test.ok
new file mode 100644
index 0000000..6c44530
--- /dev/null
+++ b/tests/parse/tcap_parse_test.ok
@@ -0,0 +1,8 @@
+Basic TCAP decode testing.
+Begin ::= {
+    otid: 00 01 02 03
+}
+62 06
+48 04
+00 01 02 03
+All tests passed.
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..8c9ce79
--- /dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,8 @@
+AT_INIT
+AT_BANNER([Regression tests.])
+
+AT_SETUP([parse])
+AT_KEYWORDS([parse])
+cat $abs_srcdir/parse/tcap_parse_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/parse/tcap_parse_test], [], [expout], 
[ignore])
+AT_CLEANUP

--
To view, visit https://gerrit.osmocom.org/c/libosmo-asn1-tcap/+/41394?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: I475afbb6145404934b0838f9b418c105bf65dca0
Gerrit-Change-Number: 41394
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <[email protected]>

Reply via email to