aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-03-07 19:08:03 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-03-07 19:48:49 +0100
commit9f83d94170ec94cd97e1d7ea69e9add27e0a9ccf (patch)
tree0af0ef6b0c83c82e716abaa1bf6c0ed346db66bb /openbsc
parentf2914cf2fbcaac7e3bf31d099a0fa856cbf16f20 (diff)
db: Add testcase for storing/loading/comparing a sms
Use the already created subscriber, create a sms and read it back from the subscriber.
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/tests/db/db_test.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c
index 3c5de9026..ba3fdfb4d 100644
--- a/openbsc/tests/db/db_test.c
+++ b/openbsc/tests/db/db_test.c
@@ -20,6 +20,7 @@
#include <openbsc/debug.h>
#include <openbsc/db.h>
#include <openbsc/gsm_subscriber.h>
+#include <openbsc/gsm_04_11.h>
#include <osmocom/core/application.h>
@@ -57,6 +58,64 @@ static struct gsm_network dummy_net;
printf("Extensions do not match in %s:%d '%s' '%s'\n", \
__FUNCTION__, __LINE__, original->extension, copy->extension); \
+/*
+ * Create/Store a SMS and then try to load it.
+ */
+static void test_sms(void)
+{
+ int rc;
+ struct gsm_sms *sms;
+ struct gsm_subscriber *subscr;
+ subscr = db_get_subscriber(GSM_SUBSCRIBER_IMSI, "9993245423445");
+ OSMO_ASSERT(subscr);
+ subscr->net = &dummy_net;
+
+ sms = sms_alloc();
+ sms->receiver = subscr_get(subscr);
+
+ sms->src.ton = 0x23;
+ sms->src.npi = 0x24;
+ memcpy(sms->src.addr, "1234", strlen("1234") + 1);
+
+ sms->dst.ton = 0x32;
+ sms->dst.npi = 0x42;
+ memcpy(sms->dst.addr, subscr->extension, sizeof(subscr->extension));
+
+ memcpy(sms->text, "Text123", strlen("Text123") + 1);
+ memcpy(sms->user_data, "UserData123", strlen("UserData123") + 1);
+ sms->user_data_len = strlen("UserData123");
+
+ /* random values */
+ sms->reply_path_req = 1;
+ sms->status_rep_req = 2;
+ sms->ud_hdr_ind = 3;
+ sms->protocol_id = 4;
+ sms->data_coding_scheme = 5;
+
+ rc = db_sms_store(sms);
+ sms_free(sms);
+ OSMO_ASSERT(rc == 0);
+
+ /* now query */
+ sms = db_sms_get_unsent_for_subscr(subscr);
+ OSMO_ASSERT(sms);
+ OSMO_ASSERT(sms->receiver == subscr);
+ OSMO_ASSERT(sms->reply_path_req == 1);
+ OSMO_ASSERT(sms->status_rep_req == 2);
+ OSMO_ASSERT(sms->ud_hdr_ind == 3);
+ OSMO_ASSERT(sms->protocol_id == 4);
+ OSMO_ASSERT(sms->data_coding_scheme == 5);
+ OSMO_ASSERT(sms->src.ton == 0x23);
+ OSMO_ASSERT(sms->src.npi == 0x24);
+ OSMO_ASSERT(sms->dst.ton == 0x32);
+ OSMO_ASSERT(sms->dst.npi == 0x42);
+ OSMO_ASSERT(strcmp((char *) sms->text, "Text123") == 0);
+ OSMO_ASSERT(sms->user_data_len == strlen("UserData123"));
+ OSMO_ASSERT(strcmp((char *) sms->user_data, "UserData123") == 0);
+
+ subscr_put(subscr);
+}
+
int main()
{
printf("Testing subscriber database code.\n");
@@ -108,6 +167,8 @@ int main()
SUBSCR_PUT(alice);
SUBSCR_PUT(alice_db);
+ test_sms();
+
db_fini();
printf("Done\n");