From patchwork Wed May 4 11:02:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max X-Patchwork-Id: 618355 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 3r0FWx4P3Lz9t50 for ; Wed, 4 May 2016 21:03:25 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 8202213DF5; Wed, 4 May 2016 11:03:23 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.sysmocom.de (mail.sysmocom.de [IPv6:2a01:4f8:191:444c::2:4]) by lists.osmocom.org (Postfix) with ESMTP id 246F913DB3 for ; Wed, 4 May 2016 11:03:13 +0000 (UTC) Received: from mail.sysmocom.de (mail.sysmocom.de [144.76.43.93]) by mail.sysmocom.de (Postfix) with ESMTP id 01A291BD6D4; Wed, 4 May 2016 11:02:43 +0000 (UTC) Received: from pbell.local (ip5b418565.dynamic.kabel-deutschland.de [91.65.133.101]) by mail.sysmocom.de (Postfix) with ESMTPSA id A97CD1BD6D2; Wed, 4 May 2016 11:02:42 +0000 (UTC) From: msuraev@sysmocom.de To: openbsc@lists.osmocom.org Subject: [PATCH 4/6] Cleanup db tests Date: Wed, 4 May 2016 13:02:36 +0200 Message-Id: <1462359758-11287-4-git-send-email-msuraev@sysmocom.de> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1462359758-11287-1-git-send-email-msuraev@sysmocom.de> References: <1462359758-11287-1-git-send-email-msuraev@sysmocom.de> X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" From: Max Move copy-pasted code into separate function to make writing more tests easier. --- openbsc/tests/db/db_test.c | 91 +++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 54 deletions(-) diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c index fb159a5..6b40e84 100644 --- a/openbsc/tests/db/db_test.c +++ b/openbsc/tests/db/db_test.c @@ -159,10 +159,43 @@ static void test_sms_migrate(void) subscr_put(rcv_subscr); } -int main() +static void test_subs(const char *alice_imsi, char *imei1, char *imei2) { - char scratch_str[256]; + struct gsm_subscriber *alice = NULL, *alice_db; + char scratch_str[256]; + alice = db_create_subscriber(alice_imsi); + db_subscriber_assoc_imei(alice, imei1); + if (imei2) + db_subscriber_assoc_imei(alice, imei2); + 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_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); + if (alice_db) { + COMPARE(alice, alice_db); + SUBSCR_PUT(alice_db); + } + SUBSCR_PUT(alice); +} + +int main() +{ printf("Testing subscriber database code.\n"); osmo_init_logging(&log_info); log_set_print_filename(osmo_stderr_target, 0); @@ -193,58 +226,8 @@ int main() SUBSCR_PUT(alice_db); SUBSCR_PUT(alice); - alice_imsi = "3693245423445"; - alice = db_create_subscriber(alice_imsi); - db_subscriber_assoc_imei(alice, "1234567890"); - 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_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); - db_subscriber_alloc_tmsi(alice); - alice->lac=42; - 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_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_subs("3693245423445", "1234567890", NULL); + test_subs("9993245423445", "1234567890", "6543560920"); /* create it again and see it fails */ alice = db_create_subscriber(alice_imsi);