summaryrefslogtreecommitdiffstats
path: root/openbsc/tests/db
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-04-30 15:31:57 +0200
commit73bc51deeab1eb38049614d67cd57f89275d7ad3 (patch)
treed2297de4aa5072271a2d271861d64042b15f7dd3 /openbsc/tests/db
parentca3c256579a731b6b2bcea73478af1e0cadd1355 (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/tests/db')
-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 e117b79..ee2fee7 100644
--- a/openbsc/tests/db/db_test.c
+++ b/openbsc/tests/db/db_test.c
@@ -21,6 +21,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>
@@ -59,6 +60,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()
{
char scratch_str[256];
@@ -142,6 +201,8 @@ int main()
SUBSCR_PUT(alice_db);
SUBSCR_PUT(alice);
+ test_sms();
+
db_fini();
printf("Done\n");