blob: c14dd664d090efb0df918126f0d0fb2c427f6d5f [file] [log] [blame]
Jan Luebbefaaa49c2008-12-27 01:07:07 +00001/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
Holger Freyther12aa50d2009-01-01 18:02:05 +00002 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Jan Luebbefaaa49c2008-12-27 01:07:07 +00003 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <openbsc/db.h>
Holger Hans Peter Freyther28dcbc52010-12-22 18:21:14 +010022#include <openbsc/gsm_subscriber.h>
Jan Luebbe7398eb92008-12-27 00:45:41 +000023
24#include <stdio.h>
Jan Luebbe5c15c852008-12-27 15:59:25 +000025#include <string.h>
Harald Welte12247c62009-05-21 07:23:02 +000026#include <stdlib.h>
Jan Luebbe7398eb92008-12-27 00:45:41 +000027
Holger Freyther12aa50d2009-01-01 18:02:05 +000028#define COMPARE(original, copy) \
29 if (original->id != copy->id) \
30 fprintf(stderr, "Ids do not match in %s:%d %llu %llu\n", \
31 __FUNCTION__, __LINE__, original->id, copy->id); \
32 if (original->lac != copy->lac) \
33 fprintf(stderr, "LAC do not match in %s:%d %d %d\n", \
34 __FUNCTION__, __LINE__, original->lac, copy->lac); \
35 if (original->authorized != copy->authorized) \
36 fprintf(stderr, "Authorize do not match in %s:%d %d %d\n", \
37 __FUNCTION__, __LINE__, original->authorized, \
38 copy->authorized); \
39 if (strcmp(original->imsi, copy->imsi) != 0) \
40 fprintf(stderr, "IMSIs do not match in %s:%d '%s' '%s'\n", \
41 __FUNCTION__, __LINE__, original->imsi, copy->imsi); \
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +020042 if (original->tmsi != copy->tmsi) \
43 fprintf(stderr, "TMSIs do not match in %s:%d '%u' '%u'\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000044 __FUNCTION__, __LINE__, original->tmsi, copy->tmsi); \
45 if (strcmp(original->name, copy->name) != 0) \
46 fprintf(stderr, "names do not match in %s:%d '%s' '%s'\n", \
47 __FUNCTION__, __LINE__, original->name, copy->name); \
48 if (strcmp(original->extension, copy->extension) != 0) \
49 fprintf(stderr, "names do not match in %s:%d '%s' '%s'\n", \
50 __FUNCTION__, __LINE__, original->extension, copy->extension); \
51
Jan Luebbe7398eb92008-12-27 00:45:41 +000052int main() {
53
Holger Freytherc7b86f92009-06-06 13:54:20 +000054 if (db_init("hlr.sqlite3")) {
Jan Luebbe5c15c852008-12-27 15:59:25 +000055 printf("DB: Failed to init database. Please check the option settings.\n");
56 return 1;
57 }
58 printf("DB: Database initialized.\n");
Jan Luebbe7398eb92008-12-27 00:45:41 +000059
Jan Luebbe5c15c852008-12-27 15:59:25 +000060 if (db_prepare()) {
61 printf("DB: Failed to prepare database.\n");
62 return 1;
63 }
64 printf("DB: Database prepared.\n");
Jan Luebbe7398eb92008-12-27 00:45:41 +000065
Jan Luebbe5c15c852008-12-27 15:59:25 +000066 struct gsm_subscriber *alice = NULL;
Holger Freyther12aa50d2009-01-01 18:02:05 +000067 struct gsm_subscriber *alice_db;
Jan Luebbe7398eb92008-12-27 00:45:41 +000068
Holger Freyther12aa50d2009-01-01 18:02:05 +000069 char *alice_imsi = "3243245432345";
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020070 alice = db_create_subscriber(NULL, alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000071 db_sync_subscriber(alice);
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020072 alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice->imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000073 COMPARE(alice, alice_db);
74 subscr_put(alice_db);
75 subscr_put(alice);
Jan Luebbe7398eb92008-12-27 00:45:41 +000076
Holger Freyther12aa50d2009-01-01 18:02:05 +000077 alice_imsi = "3693245423445";
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020078 alice = db_create_subscriber(NULL, alice_imsi);
Jan Luebbe391d86e2008-12-27 22:33:34 +000079 db_subscriber_assoc_imei(alice, "1234567890");
Jan Luebbe5c15c852008-12-27 15:59:25 +000080 db_subscriber_alloc_tmsi(alice);
81 alice->lac=42;
Holger Freyther12aa50d2009-01-01 18:02:05 +000082 db_sync_subscriber(alice);
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020083 alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000084 COMPARE(alice, alice_db);
85 subscr_put(alice);
86 subscr_put(alice_db);
Jan Luebbe7398eb92008-12-27 00:45:41 +000087
Holger Freyther12aa50d2009-01-01 18:02:05 +000088 alice_imsi = "9993245423445";
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020089 alice = db_create_subscriber(NULL, alice_imsi);
Jan Luebbe5c15c852008-12-27 15:59:25 +000090 db_subscriber_alloc_tmsi(alice);
91 alice->lac=42;
Holger Freyther12aa50d2009-01-01 18:02:05 +000092 db_sync_subscriber(alice);
Jan Luebbefac25fc2008-12-27 18:04:34 +000093 db_subscriber_assoc_imei(alice, "1234567890");
94 db_subscriber_assoc_imei(alice, "6543560920");
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020095 alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000096 COMPARE(alice, alice_db);
97 subscr_put(alice);
98 subscr_put(alice_db);
Jan Luebbe5c15c852008-12-27 15:59:25 +000099
100 db_fini();
101
102 return 0;
Jan Luebbe7398eb92008-12-27 00:45:41 +0000103}
Holger Freytherbab9cd92009-04-12 05:37:07 +0000104
105/* stubs */
106void input_event(void) {}
107void nm_state_event(void) {}