summaryrefslogtreecommitdiffstats
path: root/openbsc/tests/smpp
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-07-13 17:09:56 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-07-27 20:03:10 +0200
commita7328a5642566bf7b07c6d0e58dfe5da018873a5 (patch)
tree7242bc7481b70b956a7e7b373b4d285226afe2a3 /openbsc/tests/smpp
parent5ecbc93656edf49c8042b269299e31e157763511 (diff)
smpp: Move the coding/mode detection into a utils file
Make sure to not ever have issues with this code again, move the utility code to a new file and create a basic testcase. The method currently has 100% line and branch coverage. My initial patched missed the smpp_utils.c file and I re-did the copying (and verifying the branch coverage)
Diffstat (limited to 'openbsc/tests/smpp')
-rw-r--r--openbsc/tests/smpp/Makefile.am12
-rw-r--r--openbsc/tests/smpp/smpp_test.c73
-rw-r--r--openbsc/tests/smpp/smpp_test.err2
-rw-r--r--openbsc/tests/smpp/smpp_test.ok1
4 files changed, 88 insertions, 0 deletions
diff --git a/openbsc/tests/smpp/Makefile.am b/openbsc/tests/smpp/Makefile.am
new file mode 100644
index 000000000..eb259656b
--- /dev/null
+++ b/openbsc/tests/smpp/Makefile.am
@@ -0,0 +1,12 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_srcdir)/src/libmsc
+AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOSCCP_CFLAGS) $(LIBOSMOABIS_CFLAGS) $(COVERAGE_CFLAGS)
+AM_LDFLAGS = $(COVERAGE_LDFLAGS)
+
+EXTRA_DIST = smpp_test.ok smpp_test.err
+
+noinst_PROGRAMS = smpp_test
+
+smpp_test_SOURCES = smpp_test.c \
+ $(top_srcdir)/src/libmsc/smpp_utils.c
+smpp_test_LDADD = $(LIBOSMOCORE_LIBS) \
+ $(top_srcdir)/src/libcommon/libcommon.a
diff --git a/openbsc/tests/smpp/smpp_test.c b/openbsc/tests/smpp/smpp_test.c
new file mode 100644
index 000000000..62fa9d2e9
--- /dev/null
+++ b/openbsc/tests/smpp/smpp_test.c
@@ -0,0 +1,73 @@
+/*
+ * (C) 2013 by Holger Hans Peter Freyther
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <openbsc/debug.h>
+
+#include <osmocom/core/application.h>
+#include <osmocom/core/backtrace.h>
+
+#include "smpp_smsc.h"
+
+struct coding_test {
+ uint8_t dcs;
+ uint8_t coding;
+ int mode;
+ int res;
+};
+
+static struct coding_test codecs[] = {
+ { .dcs = 0xf6 , .coding = 0x02, .mode = MODE_8BIT, .res = 0 },
+ { .dcs = 0xf2 , .coding = 0x01, .mode = MODE_7BIT, .res = 0 },
+ { .dcs = 0x02 , .coding = 0x01, .mode = MODE_7BIT, .res = 0 },
+ { .dcs = 0x06 , .coding = 0x02, .mode = MODE_8BIT, .res = 0 },
+ { .dcs = 0x0A , .coding = 0x08, .mode = MODE_8BIT, .res = 0 },
+ { .dcs = 0x0E , .coding = 0xFF, .mode = 0xFF, .res = -1 },
+ { .dcs = 0xE0 , .coding = 0xFF, .mode = 0xFF, .res = -1 },
+};
+
+static void test_coding_scheme(void)
+{
+ int i;
+ printf("Testing coding scheme support\n");
+
+ for (i = 0; i < ARRAY_SIZE(codecs); ++i) {
+ uint8_t coding;
+ int mode, res;
+
+ res = smpp_determine_scheme(codecs[i].dcs, &coding, &mode);
+ OSMO_ASSERT(res == codecs[i].res);
+ if (res != -1) {
+ OSMO_ASSERT(mode == codecs[i].mode);
+ OSMO_ASSERT(coding == codecs[i].coding);
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ osmo_init_logging(&log_info);
+ log_set_use_color(osmo_stderr_target, 0);
+ log_set_print_filename(osmo_stderr_target, 0);
+
+ test_coding_scheme();
+ return EXIT_SUCCESS;
+}
diff --git a/openbsc/tests/smpp/smpp_test.err b/openbsc/tests/smpp/smpp_test.err
new file mode 100644
index 000000000..ec966ba47
--- /dev/null
+++ b/openbsc/tests/smpp/smpp_test.err
@@ -0,0 +1,2 @@
+SMPP MO Unknown Data Coding 0x0e
+SMPP MO Unknown Data Coding 0xe0
diff --git a/openbsc/tests/smpp/smpp_test.ok b/openbsc/tests/smpp/smpp_test.ok
new file mode 100644
index 000000000..fd44804d1
--- /dev/null
+++ b/openbsc/tests/smpp/smpp_test.ok
@@ -0,0 +1 @@
+Testing coding scheme support