diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2019-04-09 16:55:44 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2019-06-03 17:28:35 +0700 |
commit | e1e7247500417d0c3f4046d5871c06a625fd556c (patch) | |
tree | 07f739e4e68ba11ff451b1106a7f098e0ff9e15d /src | |
parent | 98f0675ffcf54a1787a4ad90e1ee5e71ae632a57 (diff) |
Introduce initial unit test for db_sms_* API
Since OsmoMSC has built-in SMSC, it needs to store the messages
somewhere. Currently we use libdbi and SQLite3 back-end for that.
For a long time, the db_sms_* API remained uncovered by unit tests.
This change aims to fix that, and does cover the following calls:
- db_sms_store(),
- db_sms_get(),
- db_sms_get_next_unsent(),
- db_sms_mark_delivered(),
- db_sms_delete_sent_message_by_id(),
- db_sms_delete_by_msisdn(),
- db_sms_delete_oldest_expired_message().
Due to performance reasons, the test database is initialized in
RAM using the magic filename ':memory:'. This is a feature of
SQLite3 (and not libdbi), see:
https://www.sqlite.org/inmemorydb.html
Of course, this unit test helped to discover some problems:
1) Storing an SMS with empty TP-User-Data (TP-UDL=0) causes
buffer overruns in both db_sms_store() and db_sms_get().
2) TP-User-Data-Length is always being interpreted in octets,
regardless of DCS (Data Coding Scheme). This results in
storing garbage in the database if the default 7-bit
encoding is used. Fortunately, the 'user_data' buffer
in structure 'gsm_sms' is large emough, so we don't
experience buffer overruns.
3) db_sms_delete_oldest_expired_message() doesn't work
as expected. Instead of removing the *oldest* expired
message, it tries to remove the *newest* one.
The current test expectations do reflect these problems.
All of them will be fixed in the follow-up patches.
Change-Id: Id94ad35b6f78f839137db2e17010fbf9b40111a3
Diffstat (limited to 'src')
-rw-r--r-- | src/libmsc/db.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libmsc/db.c b/src/libmsc/db.c index c2d833939..b564697f9 100644 --- a/src/libmsc/db.c +++ b/src/libmsc/db.c @@ -772,7 +772,10 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul daddr = dbi_result_get_string(result, "dest_addr"); if (daddr) OSMO_STRLCPY_ARRAY(sms->dst.addr, daddr); - sms->receiver = vlr_subscr_find_by_msisdn(net->vlr, sms->dst.addr, VSUB_USE_SMS_RECEIVER); + + if (net != NULL) /* db_sms_test passes NULL, so we need to be tolerant */ + sms->receiver = vlr_subscr_find_by_msisdn(net->vlr, sms->dst.addr, + VSUB_USE_SMS_RECEIVER); sms->src.npi = dbi_result_get_ulonglong(result, "src_npi"); sms->src.ton = dbi_result_get_ulonglong(result, "src_ton"); |