2008-12-27 01:07:07 +00:00
|
|
|
/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
|
2009-01-01 18:02:05 +00:00
|
|
|
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
|
2008-12-27 01:07:07 +00:00
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-12-27 01:07:07 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-27 01:07:07 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-01-06 13:27:08 +00:00
|
|
|
#include <openbsc/debug.h>
|
2008-12-27 01:07:07 +00:00
|
|
|
#include <openbsc/db.h>
|
2010-12-22 17:21:14 +00:00
|
|
|
#include <openbsc/gsm_subscriber.h>
|
2008-12-27 00:45:41 +00:00
|
|
|
|
2012-01-06 13:27:08 +00:00
|
|
|
#include <osmocom/core/application.h>
|
|
|
|
|
2008-12-27 00:45:41 +00:00
|
|
|
#include <stdio.h>
|
2008-12-27 15:59:25 +00:00
|
|
|
#include <string.h>
|
2009-05-21 07:23:02 +00:00
|
|
|
#include <stdlib.h>
|
2008-12-27 00:45:41 +00:00
|
|
|
|
2012-01-06 13:27:08 +00:00
|
|
|
static struct gsm_network dummy_net;
|
|
|
|
|
|
|
|
#define SUBSCR_PUT(sub) \
|
|
|
|
sub->net = &dummy_net; \
|
|
|
|
subscr_put(sub);
|
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
#define COMPARE(original, copy) \
|
|
|
|
if (original->id != copy->id) \
|
2012-01-06 13:27:08 +00:00
|
|
|
printf("Ids do not match in %s:%d %llu %llu\n", \
|
2009-01-01 18:02:05 +00:00
|
|
|
__FUNCTION__, __LINE__, original->id, copy->id); \
|
|
|
|
if (original->lac != copy->lac) \
|
2012-01-06 13:27:08 +00:00
|
|
|
printf("LAC do not match in %s:%d %d %d\n", \
|
2009-01-01 18:02:05 +00:00
|
|
|
__FUNCTION__, __LINE__, original->lac, copy->lac); \
|
|
|
|
if (original->authorized != copy->authorized) \
|
2012-01-06 13:27:08 +00:00
|
|
|
printf("Authorize do not match in %s:%d %d %d\n", \
|
2009-01-01 18:02:05 +00:00
|
|
|
__FUNCTION__, __LINE__, original->authorized, \
|
|
|
|
copy->authorized); \
|
|
|
|
if (strcmp(original->imsi, copy->imsi) != 0) \
|
2012-01-06 13:27:08 +00:00
|
|
|
printf("IMSIs do not match in %s:%d '%s' '%s'\n", \
|
2009-01-01 18:02:05 +00:00
|
|
|
__FUNCTION__, __LINE__, original->imsi, copy->imsi); \
|
2009-08-19 10:53:57 +00:00
|
|
|
if (original->tmsi != copy->tmsi) \
|
2012-01-06 13:27:08 +00:00
|
|
|
printf("TMSIs do not match in %s:%d '%u' '%u'\n", \
|
2009-01-01 18:02:05 +00:00
|
|
|
__FUNCTION__, __LINE__, original->tmsi, copy->tmsi); \
|
|
|
|
if (strcmp(original->name, copy->name) != 0) \
|
2012-01-06 13:27:08 +00:00
|
|
|
printf("names do not match in %s:%d '%s' '%s'\n", \
|
2009-01-01 18:02:05 +00:00
|
|
|
__FUNCTION__, __LINE__, original->name, copy->name); \
|
|
|
|
if (strcmp(original->extension, copy->extension) != 0) \
|
2013-10-04 00:42:24 +00:00
|
|
|
printf("Extensions do not match in %s:%d '%s' '%s'\n", \
|
2009-01-01 18:02:05 +00:00
|
|
|
__FUNCTION__, __LINE__, original->extension, copy->extension); \
|
|
|
|
|
2012-01-06 13:27:08 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
printf("Testing subscriber database code.\n");
|
|
|
|
osmo_init_logging(&log_info);
|
2008-12-27 00:45:41 +00:00
|
|
|
|
2009-06-06 13:54:20 +00:00
|
|
|
if (db_init("hlr.sqlite3")) {
|
2008-12-27 15:59:25 +00:00
|
|
|
printf("DB: Failed to init database. Please check the option settings.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("DB: Database initialized.\n");
|
2008-12-27 00:45:41 +00:00
|
|
|
|
2008-12-27 15:59:25 +00:00
|
|
|
if (db_prepare()) {
|
|
|
|
printf("DB: Failed to prepare database.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("DB: Database prepared.\n");
|
2008-12-27 00:45:41 +00:00
|
|
|
|
2008-12-27 15:59:25 +00:00
|
|
|
struct gsm_subscriber *alice = NULL;
|
2009-01-01 18:02:05 +00:00
|
|
|
struct gsm_subscriber *alice_db;
|
2008-12-27 00:45:41 +00:00
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
char *alice_imsi = "3243245432345";
|
2009-07-29 04:46:07 +00:00
|
|
|
alice = db_create_subscriber(NULL, alice_imsi);
|
2009-01-01 18:02:05 +00:00
|
|
|
db_sync_subscriber(alice);
|
2009-07-29 04:46:07 +00:00
|
|
|
alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice->imsi);
|
2009-01-01 18:02:05 +00:00
|
|
|
COMPARE(alice, alice_db);
|
2012-01-06 13:27:08 +00:00
|
|
|
SUBSCR_PUT(alice_db);
|
|
|
|
SUBSCR_PUT(alice);
|
2008-12-27 00:45:41 +00:00
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
alice_imsi = "3693245423445";
|
2009-07-29 04:46:07 +00:00
|
|
|
alice = db_create_subscriber(NULL, alice_imsi);
|
2008-12-27 22:33:34 +00:00
|
|
|
db_subscriber_assoc_imei(alice, "1234567890");
|
2008-12-27 15:59:25 +00:00
|
|
|
db_subscriber_alloc_tmsi(alice);
|
|
|
|
alice->lac=42;
|
2009-01-01 18:02:05 +00:00
|
|
|
db_sync_subscriber(alice);
|
2009-07-29 04:46:07 +00:00
|
|
|
alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice_imsi);
|
2009-01-01 18:02:05 +00:00
|
|
|
COMPARE(alice, alice_db);
|
2012-01-06 13:27:08 +00:00
|
|
|
SUBSCR_PUT(alice);
|
|
|
|
SUBSCR_PUT(alice_db);
|
2008-12-27 00:45:41 +00:00
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
alice_imsi = "9993245423445";
|
2009-07-29 04:46:07 +00:00
|
|
|
alice = db_create_subscriber(NULL, alice_imsi);
|
2008-12-27 15:59:25 +00:00
|
|
|
db_subscriber_alloc_tmsi(alice);
|
|
|
|
alice->lac=42;
|
2009-01-01 18:02:05 +00:00
|
|
|
db_sync_subscriber(alice);
|
2008-12-27 18:04:34 +00:00
|
|
|
db_subscriber_assoc_imei(alice, "1234567890");
|
|
|
|
db_subscriber_assoc_imei(alice, "6543560920");
|
2009-07-29 04:46:07 +00:00
|
|
|
alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice_imsi);
|
2009-01-01 18:02:05 +00:00
|
|
|
COMPARE(alice, alice_db);
|
2012-01-06 13:27:08 +00:00
|
|
|
SUBSCR_PUT(alice);
|
|
|
|
SUBSCR_PUT(alice_db);
|
2008-12-27 15:59:25 +00:00
|
|
|
|
|
|
|
db_fini();
|
|
|
|
|
2012-01-06 13:27:08 +00:00
|
|
|
printf("Done\n");
|
2008-12-27 15:59:25 +00:00
|
|
|
return 0;
|
2008-12-27 00:45:41 +00:00
|
|
|
}
|
2009-04-12 05:37:07 +00:00
|
|
|
|
|
|
|
/* stubs */
|
2010-12-29 10:07:22 +00:00
|
|
|
void vty_out() {}
|