summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-10-06 04:10:06 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2017-10-11 22:32:19 +0200
commite8ccd5013abe0e04b2400661405fd9e18e88cd89 (patch)
tree7d7fb204db38325a0a54e5d58e56f07fa1ffbe1a /tests
parent9c2bbc840f3678489d744d69a718afacafa60ad3 (diff)
refactor db_subscr_ps() to db_subscr_nam()
Allow to set nam_ps and nam_cs from this same function, by adding the is_ps arg. Combine both NAM_PS stmts to DB_STMT_UPD_NAM_PS_BY_IMSI, add another such stmt for CS. Use named parameters instead of parameter indexes. Improve error return values as well as error logging to clearly indicate whether the operation could not find the requested IMSI, or other errors occured. Adjust the single caller. This prepares for upcoming VTY and possibly CTRL commands, and the error handling introduced here has been or will be adopted by other functions in previous or subsequent patches. Change-Id: I6e70e15228f5bb10bee6758ae5dc9687d65839bd
Diffstat (limited to 'tests')
-rw-r--r--tests/db/db_test.c39
-rw-r--r--tests/db/db_test.err144
2 files changed, 183 insertions, 0 deletions
diff --git a/tests/db/db_test.c b/tests/db/db_test.c
index 250b363..30de51d 100644
--- a/tests/db/db_test.c
+++ b/tests/db/db_test.c
@@ -244,6 +244,45 @@ static void test_subscr_create_update_sel_delete()
ASSERT_RC(db_subscr_update_msisdn_by_imsi(dbc, "foobar", "99"), -ENOENT);
ASSERT_SEL(msisdn, "99", -ENOENT);
+ comment("Set / unset nam_cs and nam_ps");
+
+ /* nam_val, is_ps */
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, false, true), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, false, false), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, true, false), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, true, true), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+
+ comment("Set / unset nam_cs and nam_ps *again*");
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, false, true), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, false, true), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, false, false), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, false, false), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, true, true), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, true, true), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, true, false), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+ ASSERT_RC(db_subscr_nam(dbc, imsi0, true, false), 0);
+ ASSERT_SEL(imsi, imsi0, 0);
+
+ comment("Set nam_cs and nam_ps on non-existent / invalid IMSI");
+
+ ASSERT_RC(db_subscr_nam(dbc, unknown_imsi, false, true), -ENOENT);
+ ASSERT_RC(db_subscr_nam(dbc, unknown_imsi, false, false), -ENOENT);
+ ASSERT_SEL(imsi, unknown_imsi, -ENOENT);
+
+ ASSERT_RC(db_subscr_nam(dbc, "foobar", false, true), -ENOENT);
+ ASSERT_RC(db_subscr_nam(dbc, "foobar", false, false), -ENOENT);
+
comment("Delete non-existent / invalid IDs");
ASSERT_RC(db_subscr_delete_by_id(dbc, 999), -ENOENT);
diff --git a/tests/db/db_test.err b/tests/db/db_test.err
index 17323b5..f7c03d9 100644
--- a/tests/db/db_test.err
+++ b/tests/db/db_test.err
@@ -232,6 +232,150 @@ db_subscr_get_by_msisdn(dbc, "99", &g_subscr) --> -ENOENT
DAUC Cannot read subscriber from db: MSISDN='99': No such subscriber
+--- Set / unset nam_cs and nam_ps
+
+db_subscr_nam(dbc, imsi0, false, true) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_ps = false,
+}
+
+db_subscr_nam(dbc, imsi0, false, false) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_cs = false,
+ .nam_ps = false,
+}
+
+db_subscr_nam(dbc, imsi0, true, false) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_ps = false,
+}
+
+db_subscr_nam(dbc, imsi0, true, true) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+}
+
+
+--- Set / unset nam_cs and nam_ps *again*
+
+db_subscr_nam(dbc, imsi0, false, true) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_ps = false,
+}
+
+db_subscr_nam(dbc, imsi0, false, true) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_ps = false,
+}
+
+db_subscr_nam(dbc, imsi0, false, false) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_cs = false,
+ .nam_ps = false,
+}
+
+db_subscr_nam(dbc, imsi0, false, false) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_cs = false,
+ .nam_ps = false,
+}
+
+db_subscr_nam(dbc, imsi0, true, true) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_cs = false,
+}
+
+db_subscr_nam(dbc, imsi0, true, true) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .nam_cs = false,
+}
+
+db_subscr_nam(dbc, imsi0, true, false) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+}
+
+db_subscr_nam(dbc, imsi0, true, false) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+}
+
+
+--- Set nam_cs and nam_ps on non-existent / invalid IMSI
+
+db_subscr_nam(dbc, unknown_imsi, false, true) --> -ENOENT
+DAUC Cannot disable PS: no such subscriber: IMSI='999999999'
+
+db_subscr_nam(dbc, unknown_imsi, false, false) --> -ENOENT
+DAUC Cannot disable CS: no such subscriber: IMSI='999999999'
+
+db_subscr_get_by_imsi(dbc, unknown_imsi, &g_subscr) --> -ENOENT
+DAUC Cannot read subscriber from db: IMSI='999999999': No such subscriber
+
+db_subscr_nam(dbc, "foobar", false, true) --> -ENOENT
+DAUC Cannot disable PS: no such subscriber: IMSI='foobar'
+
+db_subscr_nam(dbc, "foobar", false, false) --> -ENOENT
+DAUC Cannot disable CS: no such subscriber: IMSI='foobar'
+
+
--- Delete non-existent / invalid IDs
db_subscr_delete_by_id(dbc, 999) --> -ENOENT