summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/smscb/gsm0341_test.c62
2 files changed, 67 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b7ae6070..2c800634 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,7 +8,8 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
gb/bssgp_fc_test gb/gprs_bssgp_test gb/gprs_ns_test \
kasumi/kasumi_test logging/logging_test fr/fr_test \
loggingrb/loggingrb_test strrb/strrb_test \
- vty/vty_test comp128/comp128_test utils/utils_test
+ vty/vty_test comp128/comp128_test utils/utils_test \
+ smscb/gsm0341_test
if ENABLE_MSGFILE
check_PROGRAMS += msgfile/msgfile_test
@@ -50,6 +51,9 @@ msgfile_msgfile_test_LDADD = $(top_builddir)/src/libosmocore.la
smscb_smscb_test_SOURCES = smscb/smscb_test.c
smscb_smscb_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
+smscb_gsm0341_test_SOURCES = smscb/gsm0341_test.c
+smscb_gsm0341_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
+
sms_sms_test_SOURCES = sms/sms_test.c
sms_sms_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
diff --git a/tests/smscb/gsm0341_test.c b/tests/smscb/gsm0341_test.c
new file mode 100644
index 00000000..5b728899
--- /dev/null
+++ b/tests/smscb/gsm0341_test.c
@@ -0,0 +1,62 @@
+/*
+ * (C) 2014 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <osmocom/gsm/protocol/gsm_03_41.h>
+#include <osmocom/gsm/gsm0341.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/msgb.h>
+
+struct gsm341_ms_message *gen_msg_from_text(uint16_t msg_id, const char *text)
+{
+ struct gsm341_ms_message *cbmsg;
+ int text_len = strlen(text);
+ /* assuming default GSM alphabet, the encoded payload cannot be
+ * longer than the input text */
+ uint8_t payload[text_len];
+ int payload_octets;
+
+ gsm_7bit_encode_n(payload, sizeof(payload), text, &payload_octets);
+ cbmsg = gsm0341_build_msg(NULL, 0, 23, 0, msg_id, 0xf0, 1, 1, payload, payload_octets);
+
+ printf("%s\n", osmo_hexdump_nospc((uint8_t *)cbmsg, sizeof(*cbmsg)+payload_octets));
+
+ return cbmsg;
+}
+
+int main(int argc, char **argv)
+{
+ uint16_t msg_id = GSM341_MSGID_ETWS_CMAS_MONTHLY_TEST;
+ char *text = "Mahlzeit!";
+
+ if (argc > 1)
+ msg_id = atoi(argv[1]);
+
+ if (argc > 2)
+ text = argv[2];
+
+ gen_msg_from_text(msg_id, text);
+
+ return EXIT_SUCCESS;
+}