aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/test_sms.c
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2016-07-04 19:52:00 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2016-07-09 15:16:16 +0200
commite7fa08b6dfdfb607264179b457276d18c24da269 (patch)
tree1f51334dfeccb6cda2dd0671b53d648418e88b8a /src/test/test_sms.c
parent64c829909bc5b73a7765272ad07cf6465762aeac (diff)
NMT / SMS: Short Message Service support
Diffstat (limited to 'src/test/test_sms.c')
-rw-r--r--src/test/test_sms.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/test/test_sms.c b/src/test/test_sms.c
new file mode 100644
index 0000000..917f10e
--- /dev/null
+++ b/src/test/test_sms.c
@@ -0,0 +1,120 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <unistd.h>
+#include "../common/debug.h"
+#include "../common/timer.h"
+#include "../nmt/nmt.h"
+
+static const uint8_t test_mo_sms_data[] = {
+ 0x00, 0x00, 0x00, 0xa1, 0x41, 0x0f, 0x11,
+ 0x00, 0x04, 0xa1, 0x8a, 0x51,
+ 0x00, 0x00, 0xff, 0x05, 0xc8, 0x20, 0x93,
+ 0xf9, 0x7c,
+};
+
+static const char *test_mo_sms_text = "HALLO";
+
+static const char *test_mt_sms_text = "Moin Moin";
+static const char *test_mt_sms_tel = "4948416068";
+static time_t test_mt_sms_time = 851430904;
+
+static const uint8_t test_mt_sms_data[] = {
+ 0x01, 0x18, 0x53, 0x4d, 0x53, 0x48, 0x18, 0x41, 0x42, 0x43, 0x02,
+ 0x01,
+ 0x01,
+ 0x41,
+ 0x1a,
+ 0x04,
+ 0x0a, 0x91, 0x94, 0x84, 0x14, 0xa6, 0x86,
+ 0x00,
+ 0x00,
+ 0x69, 0x21, 0x42, 0x31, 0x53, 0x4a, 0x48,
+ 0x09, 0xcd, 0x77, 0xda, 0x0d, 0x6a, 0xbe, 0xd3, 0x6e,
+};
+
+static void assert(int condition, char *why)
+{
+ printf("%s = %s\n", why, (condition) ? "TRUE" : "FALSE");
+
+ if (!condition) {
+ printf("\n******************** FAILED ********************\n\n");
+ exit(-1);
+ }
+}
+
+void ok(void)
+{
+ printf("\n OK ;->\n\n");
+ sleep(1);
+}
+
+static uint8_t dms_buffer[256];
+static int dms_buffer_count;
+void dms_send(nmt_t *nmt, const uint8_t *data, int length, int eight_bits)
+{
+ memcpy(dms_buffer, data, length);
+ dms_buffer_count = length;
+// int i;
+
+ assert(length == sizeof(test_mt_sms_data), "Expecting SMS binary data length to match");
+ assert(!memcmp(data, test_mt_sms_data, length), "Expecting SMS binary data to match");
+// for (i = 0; i < length; i++) {
+// printf("(0x%02x)\n", data[i]);
+// }
+}
+
+void sms_release(nmt_t *nmt)
+{
+ printf("(got release from SMS layer)\n");
+}
+
+void sms_submit(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t orig_type, uint8_t orig_plan, int msg_ref, const char *dest_address, uint8_t dest_type, uint8_t dest_plan, const char *message)
+{
+ strcpy((char *)dms_buffer, message);
+ dms_buffer_count = strlen(message);
+}
+
+void sms_deliver_report(nmt_t *nmt, uint8_t ref, int error, uint8_t cause)
+{
+ printf("(got deliver report from SMS layer)\n");
+}
+
+
+int main(void)
+{
+ nmt_t *nmt;
+ int i;
+ int rc;
+
+ debuglevel = DEBUG_DEBUG;
+
+ nmt = calloc(sizeof(*nmt), 1);
+ sms_reset(nmt);
+
+ /* deliver */
+ printf("(delivering SMS)\n");
+ rc = sms_deliver(nmt, 1, test_mt_sms_tel, SMS_TYPE_INTERNATIONAL, SMS_PLAN_ISDN_TEL, test_mt_sms_time, test_mt_sms_text);
+ assert(rc == 0, "Expecting sms_deliver() to return 0");
+
+ ok();
+
+ free(nmt);
+ nmt = calloc(sizeof(*nmt), 1);
+ sms_reset(nmt);
+
+ printf("(submitting SMS)\n");
+ dms_buffer_count = 0;
+ for (i = 0; i < sizeof(test_mo_sms_data); i++)
+ dms_receive(nmt, test_mo_sms_data + i, 1, 1);
+
+ assert(dms_buffer_count == strlen(test_mo_sms_text), "Expecting SMS text length to match");
+ assert(!memcmp(dms_buffer, test_mo_sms_text, dms_buffer_count), "Expecting SMS text to match");
+
+ ok();
+
+ return 0;
+}
+