aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-09-17 08:35:32 +0200
committerlaforge <laforge@osmocom.org>2021-09-21 19:57:56 +0000
commit292f9e7014056125f9abadd8df1b2850141bc6c0 (patch)
tree7b6e407d2c015b60deace051baa4b55dddbf9cc8 /tests
parentc757239fd371727ad085d25032038306d8d57726 (diff)
base64: Migrate over to osmocom
This containts the osmocom changes to the mbedtls base64 code merged in the previous commit. Change-Id: I82c1bf5f827c8def370dbcb80b146e9e4184c4a3
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/base64/base64_test.c57
-rw-r--r--tests/base64/base64_test.ok3
-rw-r--r--tests/testsuite.at6
4 files changed, 70 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5c6f30c5..22591fb9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -43,6 +43,7 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
bssmap_le/bssmap_le_test \
it_q/it_q_test \
gsm48/rest_octets_test \
+ base64/base64_test \
$(NULL)
if ENABLE_MSGFILE
@@ -79,6 +80,8 @@ if ENABLE_GB
check_PROGRAMS += gb/bssgp_fc_test gb/gprs_bssgp_test gb/gprs_bssgp_rim_test gb/gprs_ns_test gb/gprs_ns2_test fr/fr_test
endif
+base64_base64_test_SOURCES = base64/base64_test.c
+
utils_utils_test_SOURCES = utils/utils_test.c
utils_utils_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la
@@ -405,6 +408,7 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
bssmap_le/bssmap_le_test.ok \
it_q/it_q_test.ok \
gsm48/rest_octets_test.ok \
+ base64/base64_test.ok \
$(NULL)
if ENABLE_LIBSCTP
diff --git a/tests/base64/base64_test.c b/tests/base64/base64_test.c
new file mode 100644
index 00000000..e85f6490
--- /dev/null
+++ b/tests/base64/base64_test.c
@@ -0,0 +1,57 @@
+#include <osmocom/core/base64.h>
+#include <stdio.h>
+#include <string.h>
+
+static const unsigned char base64_test_dec[64] =
+{
+ 0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
+ 0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01,
+ 0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09,
+ 0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13,
+ 0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31,
+ 0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38,
+ 0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B,
+ 0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97
+};
+
+static const unsigned char base64_test_enc[] =
+ "JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK"
+ "swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw==";
+
+/*
+ * Checkup routine
+ */
+int main(int argc, char **argv)
+{
+ size_t len;
+ const unsigned char *src;
+ unsigned char buffer[128];
+
+ printf( " Base64 encoding test: " );
+
+ src = base64_test_dec;
+
+ if( osmo_base64_encode( buffer, sizeof( buffer ), &len, src, 64 ) != 0 ||
+ memcmp( base64_test_enc, buffer, 88 ) != 0 )
+ {
+ printf( "failed\n" );
+
+ return( 1 );
+ }
+
+ printf( "passed\n Base64 decoding test: " );
+
+ src = base64_test_enc;
+
+ if( osmo_base64_decode( buffer, sizeof( buffer ), &len, src, 88 ) != 0 ||
+ memcmp( base64_test_dec, buffer, 64 ) != 0 )
+ {
+ printf( "failed\n" );
+
+ return( 1 );
+ }
+
+ printf( "passed\n\n" );
+
+ return( 0 );
+}
diff --git a/tests/base64/base64_test.ok b/tests/base64/base64_test.ok
new file mode 100644
index 00000000..ff187d9c
--- /dev/null
+++ b/tests/base64/base64_test.ok
@@ -0,0 +1,3 @@
+ Base64 encoding test: passed
+ Base64 decoding test: passed
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index cb842294..6ac59709 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -446,3 +446,9 @@ AT_KEYWORDS([it_q])
cat $abs_srcdir/it_q/it_q_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/it_q/it_q_test], [0], [expout], [ignore])
AT_CLEANUP
+
+AT_SETUP([base64])
+AT_KEYWORDS([base64])
+cat $abs_srcdir/base64/base64_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/base64/base64_test], [0], [expout], [ignore])
+AT_CLEANUP