-- Regards, Alexander Chemeris. CEO, Fairwaves, Inc. / ООО УмРадио https://fairwaves.co
From 458ea0f1bfe68a8094669919dc640d5dbce41bd4 Mon Sep 17 00:00:00 2001 From: Alexander Chemeris <[email protected]> Date: Sat, 8 Mar 2014 18:48:49 +0100 Subject: [PATCH] db: Add more tests for retrieving subscribers from a DB.
--- openbsc/tests/db/db_test.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c index 039b152..ea6f2dc 100644 --- a/openbsc/tests/db/db_test.c +++ b/openbsc/tests/db/db_test.c @@ -1,5 +1,6 @@ /* (C) 2008 by Jan Luebbe <[email protected]> * (C) 2009 by Holger Hans Peter Freyther <[email protected]> + * (C) 2014 by Alexander Chemeris <[email protected]> * All Rights Reserved * * This program is free software; you can redistribute it and/or modify @@ -27,6 +28,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <inttypes.h> static struct gsm_network dummy_net; @@ -123,6 +125,8 @@ static void test_sms(void) int main() { + char scratch_str[256]; + printf("Testing subscriber database code.\n"); osmo_init_logging(&log_info); @@ -155,10 +159,25 @@ int main() db_subscriber_alloc_tmsi(alice); alice->lac=42; db_sync_subscriber(alice); + /* Get by TMSI */ + snprintf(scratch_str, sizeof(scratch_str), "%"PRIu32, alice->tmsi); + alice_db = db_get_subscriber(GSM_SUBSCRIBER_TMSI, scratch_str); + COMPARE(alice, alice_db); + SUBSCR_PUT(alice_db); + /* Get by IMSI */ alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice_imsi); COMPARE(alice, alice_db); - SUBSCR_PUT(alice); SUBSCR_PUT(alice_db); + /* Get by id */ + snprintf(scratch_str, sizeof(scratch_str), "%llu", alice->id); + alice_db = db_get_subscriber(GSM_SUBSCRIBER_ID, scratch_str); + COMPARE(alice, alice_db); + SUBSCR_PUT(alice_db); + /* Get by extension */ + alice_db = db_get_subscriber(GSM_SUBSCRIBER_EXTENSION, alice->extension); + COMPARE(alice, alice_db); + SUBSCR_PUT(alice_db); + SUBSCR_PUT(alice); alice_imsi = "9993245423445"; alice = db_create_subscriber(alice_imsi); @@ -167,10 +186,25 @@ int main() db_sync_subscriber(alice); db_subscriber_assoc_imei(alice, "1234567890"); db_subscriber_assoc_imei(alice, "6543560920"); + /* Get by TMSI */ + snprintf(scratch_str, sizeof(scratch_str), "%"PRIu32, alice->tmsi); + alice_db = db_get_subscriber(GSM_SUBSCRIBER_TMSI, scratch_str); + COMPARE(alice, alice_db); + SUBSCR_PUT(alice_db); + /* Get by IMSI */ alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice_imsi); COMPARE(alice, alice_db); - SUBSCR_PUT(alice); SUBSCR_PUT(alice_db); + /* Get by id */ + snprintf(scratch_str, sizeof(scratch_str), "%llu", alice->id); + alice_db = db_get_subscriber(GSM_SUBSCRIBER_ID, scratch_str); + COMPARE(alice, alice_db); + SUBSCR_PUT(alice_db); + /* Get by extension */ + alice_db = db_get_subscriber(GSM_SUBSCRIBER_EXTENSION, alice->extension); + COMPARE(alice, alice_db); + SUBSCR_PUT(alice_db); + SUBSCR_PUT(alice); test_sms(); -- 1.7.9.5
