[2/5] db: Add testcase for storing/loading/comparing a sms
diff mbox

Message ID 1398423450-23319-2-git-send-email-holger@freyther.de
State Accepted
Headers show

Commit Message

Holger Freyther April 25, 2014, 10:57 a.m. UTC
From: Holger Hans Peter Freyther <holger@moiji-mobile.com>

Use the already created subscriber, create a sms and read it
back from the subscriber.
---
 openbsc/tests/db/db_test.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

Patch
diff mbox

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");