From b00efa685b26819a640ba9cacbce4e0e9af7da5c Mon Sep 17 00:00:00 2001 From: Borys Jelenski Date: Fri, 8 Jan 2021 16:44:18 +0100 Subject: [PATCH] [EGD-5115] Fix dangling ptrs in module-db tests The dangling ptrs derefencing freed memory has been fixed. They caused the tests to trigger the ASan. Additonally, in some tests where DB objects were allocated dynamically, they are now allocated automatically on the stack to simplify the code. --- module-db/tests/AlarmsRecord_tests.cpp | 4 +-- module-db/tests/AlarmsTable_tests.cpp | 4 +-- module-db/tests/CalllogRecord_tests.cpp | 8 +++--- module-db/tests/CalllogTable_tests.cpp | 4 +-- module-db/tests/ContactGroups_tests.cpp | 4 +-- .../tests/ContactsAddressTable_tests.cpp | 4 +-- module-db/tests/ContactsNameTable_tests.cpp | 6 ++-- module-db/tests/ContactsNumberTable_tests.cpp | 4 +-- module-db/tests/ContactsRecord_tests.cpp | 28 +++++++++---------- .../tests/ContactsRingtonesTable_tests.cpp | 4 +-- module-db/tests/ContactsTable_tests.cpp | 4 +-- module-db/tests/EventsRecord_tests.cpp | 4 +-- module-db/tests/EventsTable_tests.cpp | 4 +-- module-db/tests/NotesRecord_tests.cpp | 7 +++-- module-db/tests/NotesTable_tests.cpp | 7 +++-- module-db/tests/NotificationsRecord_tests.cpp | 4 +-- module-db/tests/NotificationsTable_tests.cpp | 4 +-- module-db/tests/SMSRecord_tests.cpp | 16 +++++------ module-db/tests/SMSTable_tests.cpp | 4 +-- module-db/tests/SMSTemplateRecord_tests.cpp | 8 +++--- module-db/tests/SMSTemplateTable_tests.cpp | 4 +-- module-db/tests/ThreadRecord_tests.cpp | 16 +++++------ module-db/tests/ThreadsTable_tests.cpp | 4 +-- 23 files changed, 79 insertions(+), 77 deletions(-) diff --git a/module-db/tests/AlarmsRecord_tests.cpp b/module-db/tests/AlarmsRecord_tests.cpp index 12b721714c27757bfe4884a48634edde216b0db7..60ca652cd837f3b17bcb127ec45e704f9ec4cdc0 100644 --- a/module-db/tests/AlarmsRecord_tests.cpp +++ b/module-db/tests/AlarmsRecord_tests.cpp @@ -26,10 +26,10 @@ TEST_CASE("Alarms Record tests") { Database::initialize(); - const auto alarmsPath = (purefs::dir::getUserDiskPath() / "alarms.db").c_str(); + const auto alarmsPath = purefs::dir::getUserDiskPath() / "alarms.db"; std::filesystem::remove(alarmsPath); - auto alarmsDB = AlarmsDB(alarmsPath); + AlarmsDB alarmsDB(alarmsPath.c_str()); REQUIRE(alarmsDB.isInitialized()); SECTION("Default Constructor") diff --git a/module-db/tests/AlarmsTable_tests.cpp b/module-db/tests/AlarmsTable_tests.cpp index 3cbfb9da2e247ea1fedcccbc137d3eb174a728c9..8974e495d8e2b48d3f76f42cdea27d97611e0ddc 100644 --- a/module-db/tests/AlarmsTable_tests.cpp +++ b/module-db/tests/AlarmsTable_tests.cpp @@ -21,10 +21,10 @@ TEST_CASE("Alarms Table tests") { Database::initialize(); - const auto alarmsPath = (purefs::dir::getUserDiskPath() / "alarms.db").c_str(); + const auto alarmsPath = purefs::dir::getUserDiskPath() / "alarms.db"; std::filesystem::remove(alarmsPath); - AlarmsDB alarmsDb(alarmsPath); + AlarmsDB alarmsDb(alarmsPath.c_str()); REQUIRE(alarmsDb.isInitialized()); auto &alarmsTbl = alarmsDb.alarms; diff --git a/module-db/tests/CalllogRecord_tests.cpp b/module-db/tests/CalllogRecord_tests.cpp index d9b0e3b80816936dc59cb6bb8b38a6924a8eb6ce..39b11e5a8c89d146c0daeda0122165833675e750 100644 --- a/module-db/tests/CalllogRecord_tests.cpp +++ b/module-db/tests/CalllogRecord_tests.cpp @@ -20,13 +20,13 @@ TEST_CASE("Calllog Record tests") { Database::initialize(); - const auto callogPath = (purefs::dir::getUserDiskPath() / "callog.db").c_str(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); + const auto callogPath = purefs::dir::getUserDiskPath() / "callog.db"; + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; std::filesystem::remove(callogPath); std::filesystem::remove(contactsPath); - CalllogDB calllogDb(callogPath); - ContactsDB contactsDb(contactsPath); + CalllogDB calllogDb(callogPath.c_str()); + ContactsDB contactsDb(contactsPath.c_str()); REQUIRE(calllogDb.isInitialized()); REQUIRE(contactsDb.isInitialized()); diff --git a/module-db/tests/CalllogTable_tests.cpp b/module-db/tests/CalllogTable_tests.cpp index 5d3ae9b47df0733f1e8187a7eeb937c908ee5ced..9e3a211bba58a9d3f2c3fc8c34af5b28b77fec65 100644 --- a/module-db/tests/CalllogTable_tests.cpp +++ b/module-db/tests/CalllogTable_tests.cpp @@ -20,10 +20,10 @@ TEST_CASE("Calllog Table tests") { Database::initialize(); - const auto callogPath = (purefs::dir::getUserDiskPath() / "callog.db").c_str(); + const auto callogPath = purefs::dir::getUserDiskPath() / "callog.db"; std::filesystem::remove(callogPath); - CalllogDB calllogDb{callogPath}; + CalllogDB calllogDb{callogPath.c_str()}; REQUIRE(calllogDb.isInitialized()); auto &callsTbl = calllogDb.calls; diff --git a/module-db/tests/ContactGroups_tests.cpp b/module-db/tests/ContactGroups_tests.cpp index c4974791dc2a9d21cce56812b7a2b44c37082018..ab52d68fca801c0b7e129f9618c866002931299c 100644 --- a/module-db/tests/ContactGroups_tests.cpp +++ b/module-db/tests/ContactGroups_tests.cpp @@ -28,9 +28,9 @@ TEST_CASE("Contact Groups tests", "[Groups]") { INFO("sqlite Init"); Database::initialize(); - const auto callogPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); + const auto callogPath = purefs::dir::getUserDiskPath() / "contacts.db"; std::filesystem::remove(callogPath); - ContactsDB contactDb{callogPath}; + ContactsDB contactDb{callogPath.c_str()}; INFO("contactDB init"); REQUIRE(contactDb.isInitialized()); ContactsGroupsTable contactGroupsTable = ContactsGroupsTable(&contactDb); diff --git a/module-db/tests/ContactsAddressTable_tests.cpp b/module-db/tests/ContactsAddressTable_tests.cpp index 8cfb153f5195f845af54a4acbf7b7b66069e2292..23e73699ebbb82010e7732288b30978c0acb4b16 100644 --- a/module-db/tests/ContactsAddressTable_tests.cpp +++ b/module-db/tests/ContactsAddressTable_tests.cpp @@ -12,10 +12,10 @@ TEST_CASE("Contacts address Table tests") { Database::initialize(); - const auto callogPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); + const auto callogPath = purefs::dir::getUserDiskPath() / "contacts.db"; std::filesystem::remove(callogPath); - ContactsDB contactsdb{callogPath}; + ContactsDB contactsdb{callogPath.c_str()}; REQUIRE(contactsdb.isInitialized()); ContactsAddressTableRow testRow1 = {{.ID = DB_ID_NONE}, diff --git a/module-db/tests/ContactsNameTable_tests.cpp b/module-db/tests/ContactsNameTable_tests.cpp index 17bcac504d761325835636a8ad3068a4f4b58988..facd858045794f7690c18ba353ceeda2805ed929 100644 --- a/module-db/tests/ContactsNameTable_tests.cpp +++ b/module-db/tests/ContactsNameTable_tests.cpp @@ -18,10 +18,10 @@ TEST_CASE("Contacts Name Table tests") { Database::initialize(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); - std::remove(contactsPath); + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; + std::filesystem::remove(contactsPath); - ContactsDB contactsdb(contactsPath); + ContactsDB contactsdb(contactsPath.c_str()); REQUIRE(contactsdb.isInitialized()); ContactsNameTableRow testRow1 = { diff --git a/module-db/tests/ContactsNumberTable_tests.cpp b/module-db/tests/ContactsNumberTable_tests.cpp index 5ff5c9bf50228c207454e138e481367c5bc2e376..40fae2ce57807e4c482bb7f738e08ac59498b6e6 100644 --- a/module-db/tests/ContactsNumberTable_tests.cpp +++ b/module-db/tests/ContactsNumberTable_tests.cpp @@ -20,10 +20,10 @@ TEST_CASE("Contacts Number Table tests") { Database::initialize(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; std::filesystem::remove(contactsPath); - ContactsDB contactsdb{contactsPath}; + ContactsDB contactsdb{contactsPath.c_str()}; REQUIRE(contactsdb.isInitialized()); ContactsNumberTableRow testRow1 = { diff --git a/module-db/tests/ContactsRecord_tests.cpp b/module-db/tests/ContactsRecord_tests.cpp index 3379fb659dfdbf3b63bfb2773eb43fc7ce4d5f0d..b250202afc9b46ddafb2666aa7425ab09688c249 100644 --- a/module-db/tests/ContactsRecord_tests.cpp +++ b/module-db/tests/ContactsRecord_tests.cpp @@ -12,11 +12,11 @@ TEST_CASE("Contact Record db tests") { Database::initialize(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; std::filesystem::remove(contactsPath); - auto contactDB = std::make_unique(contactsPath); - REQUIRE(contactDB->isInitialized()); + ContactsDB contactDB(contactsPath.c_str()); + REQUIRE(contactDB.isInitialized()); const char *primaryNameTest = "PrimaryNameTest"; const char *alternativeNameTest = "AlternativeNameTest"; @@ -29,7 +29,7 @@ TEST_CASE("Contact Record db tests") const char *speeddialTest = "100"; const ContactNumberType contactNumberTypeTest = ContactNumberType ::PAGER; - ContactRecordInterface contRecInterface(contactDB.get()); + ContactRecordInterface contRecInterface(&contactDB); ContactRecord recordIN; @@ -261,13 +261,13 @@ TEST_CASE("Test converting contact data to string") TEST_CASE("Contact record numbers update") { Database::initialize(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; std::filesystem::remove(contactsPath); - auto contactDB = std::make_unique(contactsPath); - REQUIRE(contactDB->isInitialized()); + ContactsDB contactDB(contactsPath.c_str()); + REQUIRE(contactDB.isInitialized()); - auto records = ContactRecordInterface(contactDB.get()); + auto records = ContactRecordInterface(&contactDB); ContactRecord testRecord, otherRecord; std::array numbers = {{{"600100100"}, {"600100200"}, {"600100300"}, {"600100400"}}}; @@ -289,7 +289,7 @@ TEST_CASE("Contact record numbers update") auto newRecord = records.GetByID(1); REQUIRE(newRecord.numbers.size() == 2); REQUIRE(records.Update(newRecord)); - REQUIRE(contactDB->number.count() == 4); + REQUIRE(contactDB.number.count() == 4); auto validatationRecord = records.GetByID(1); REQUIRE(validatationRecord.numbers.size() == 2); @@ -310,7 +310,7 @@ TEST_CASE("Contact record numbers update") newRecord.numbers = std::vector({ContactRecord::Number(numbers[1], std::string(""))}); REQUIRE(records.Update(newRecord)); - REQUIRE(contactDB->number.count() == 3); + REQUIRE(contactDB.number.count() == 3); auto validatationRecord = records.GetByID(1); REQUIRE(validatationRecord.numbers.size() == 1); @@ -324,7 +324,7 @@ TEST_CASE("Contact record numbers update") newRecord.numbers = std::vector( {ContactRecord::Number(numbers[0], std::string("")), ContactRecord::Number(numbers[1], std::string(""))}); REQUIRE(records.Update(newRecord)); - REQUIRE(contactDB->number.count() == 4); + REQUIRE(contactDB.number.count() == 4); validatationRecord = records.GetByID(1); REQUIRE(validatationRecord.numbers.size() == 2); @@ -349,7 +349,7 @@ TEST_CASE("Contact record numbers update") REQUIRE(records.Update(newRecord)); auto validatationRecord = records.GetByID(1); - REQUIRE(contactDB->number.count() == 4); + REQUIRE(contactDB.number.count() == 4); REQUIRE(validatationRecord.numbers.size() == 2); REQUIRE(validatationRecord.numbers[0].number.getEntered() == numbers[1]); REQUIRE(validatationRecord.numbers[1].number.getEntered() == numbers[0]); @@ -363,7 +363,7 @@ TEST_CASE("Contact record numbers update") newRecord.numbers = std::vector( {ContactRecord::Number(numbers[2], std::string("")), ContactRecord::Number(numbers[1], std::string(""))}); REQUIRE(records.Update(newRecord)); - REQUIRE(contactDB->number.count() == 3); + REQUIRE(contactDB.number.count() == 3); auto validatationRecord = records.GetByID(1); REQUIRE(validatationRecord.numbers.size() == 2); @@ -383,7 +383,7 @@ TEST_CASE("Contact record numbers update") newRecord.numbers = std::vector( {ContactRecord::Number(numbers[2], std::string("")), ContactRecord::Number(numbers[3], std::string(""))}); REQUIRE(records.Update(newRecord)); - REQUIRE(contactDB->number.count() == 2); + REQUIRE(contactDB.number.count() == 2); auto validatationRecord = records.GetByID(1); REQUIRE(validatationRecord.numbers.size() == 2); diff --git a/module-db/tests/ContactsRingtonesTable_tests.cpp b/module-db/tests/ContactsRingtonesTable_tests.cpp index 07e255de7ebc50b0a696dfe2e424a925322235be..fbc3560baa5ad9a2beacdb23181baa3ffb78ef17 100644 --- a/module-db/tests/ContactsRingtonesTable_tests.cpp +++ b/module-db/tests/ContactsRingtonesTable_tests.cpp @@ -20,10 +20,10 @@ TEST_CASE("Contacts Ringtones Table tests") { Database::initialize(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; std::filesystem::remove(contactsPath); - ContactsDB contactsdb{contactsPath}; + ContactsDB contactsdb{contactsPath.c_str()}; REQUIRE(contactsdb.isInitialized()); ContactsRingtonesTableRow testRow1(DB_ID_NONE, DB_ID_NONE, "/test/assets/path/ringtone.wr"); diff --git a/module-db/tests/ContactsTable_tests.cpp b/module-db/tests/ContactsTable_tests.cpp index bedc5eca4d8c2a52d8e3a71218c280878c7ecffc..80f2be165f9dc408bf66c6332bcda75d10732b3a 100644 --- a/module-db/tests/ContactsTable_tests.cpp +++ b/module-db/tests/ContactsTable_tests.cpp @@ -14,10 +14,10 @@ TEST_CASE("Contacts Table tests") { Database::initialize(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; std::filesystem::remove(contactsPath); - ContactsDB contactsdb{contactsPath}; + ContactsDB contactsdb{contactsPath.c_str()}; REQUIRE(contactsdb.isInitialized()); ContactsTableRow testRow1 = {{.ID = DB_ID_NONE}, diff --git a/module-db/tests/EventsRecord_tests.cpp b/module-db/tests/EventsRecord_tests.cpp index 94785e4ee8fc88facdc5ecc57eacb31a1d7a731f..d4bf2608b74fc488734385d9566138e968cc9ba9 100644 --- a/module-db/tests/EventsRecord_tests.cpp +++ b/module-db/tests/EventsRecord_tests.cpp @@ -41,10 +41,10 @@ TEST_CASE("Events Record tests") { Database::initialize(); - const auto eventsPath = (purefs::dir::getUserDiskPath() / "events.db").c_str(); + const auto eventsPath = purefs::dir::getUserDiskPath() / "events.db"; std::filesystem::remove(eventsPath); - EventsDB eventsDb{eventsPath}; + EventsDB eventsDb{eventsPath.c_str()}; REQUIRE(eventsDb.isInitialized()); diff --git a/module-db/tests/EventsTable_tests.cpp b/module-db/tests/EventsTable_tests.cpp index 92bcd131c2280c70b8e7788f1def5d6dbbad4d30..ff4ce6a8c888f319baf45adc51c7e859f1568a87 100644 --- a/module-db/tests/EventsTable_tests.cpp +++ b/module-db/tests/EventsTable_tests.cpp @@ -33,10 +33,10 @@ TEST_CASE("Events Table tests") Database::initialize(); - const auto eventsPath = (purefs::dir::getUserDiskPath() / "events.db").c_str(); + const auto eventsPath = purefs::dir::getUserDiskPath() / "events.db"; // std::filesystem::remove(eventsPath); - EventsDB eventsDb{eventsPath}; + EventsDB eventsDb{eventsPath.c_str()}; REQUIRE(eventsDb.isInitialized()); auto &eventsTbl = eventsDb.events; diff --git a/module-db/tests/NotesRecord_tests.cpp b/module-db/tests/NotesRecord_tests.cpp index e9be01aa8830bbfd4ac22aafede496a6b7461c70..7d86eecd2df880996762ab53ce570972d95fdd65 100644 --- a/module-db/tests/NotesRecord_tests.cpp +++ b/module-db/tests/NotesRecord_tests.cpp @@ -17,10 +17,11 @@ TEST_CASE("Notes Record tests") { Database::initialize(); - auto notesDb = std::make_unique((purefs::dir::getUserDiskPath() / "notes.db").c_str()); - REQUIRE(notesDb->isInitialized()); + const auto notesDbPath = purefs::dir::getUserDiskPath() / "notes.db"; + NotesDB notesDb{notesDbPath.c_str()}; + REQUIRE(notesDb.isInitialized()); - NotesRecordInterface notesRecordInterface{notesDb.get()}; + NotesRecordInterface notesRecordInterface{¬esDb}; notesRecordInterface.RemoveAll(); // Empty the notes database. constexpr auto testSnippet = "TEST SNIPPET"; diff --git a/module-db/tests/NotesTable_tests.cpp b/module-db/tests/NotesTable_tests.cpp index 2487b10856e095ee5175e49b7cbc3316479a7fb8..421dac6139906d7aba690582f9ff439c14e15def 100644 --- a/module-db/tests/NotesTable_tests.cpp +++ b/module-db/tests/NotesTable_tests.cpp @@ -12,10 +12,11 @@ TEST_CASE("Notes Table tests") { Database::initialize(); - auto notesDb = std::make_unique((purefs::dir::getUserDiskPath() / "notes.db").c_str()); - REQUIRE(notesDb->isInitialized()); + const auto notesDbPath = purefs::dir::getUserDiskPath() / "notes.db"; + NotesDB notesDb{notesDbPath.c_str()}; + REQUIRE(notesDb.isInitialized()); - NotesTable table{notesDb.get()}; + NotesTable table{¬esDb}; table.removeAll(); REQUIRE(table.count() == 0); diff --git a/module-db/tests/NotificationsRecord_tests.cpp b/module-db/tests/NotificationsRecord_tests.cpp index 9486e1ae4a5fea90c302ec823f5ce3e24c4b36b5..e9cabfb9d92e617116e9374f72f27a83874b7647 100644 --- a/module-db/tests/NotificationsRecord_tests.cpp +++ b/module-db/tests/NotificationsRecord_tests.cpp @@ -25,10 +25,10 @@ TEST_CASE("Notifications Record tests") { Database::initialize(); - const auto notificationsPath = (purefs::dir::getUserDiskPath() / "notifications.db").c_str(); + const auto notificationsPath = purefs::dir::getUserDiskPath() / "notifications.db"; std::filesystem::remove(notificationsPath); - NotificationsDB notificationsDb{notificationsPath}; + NotificationsDB notificationsDb{notificationsPath.c_str()}; REQUIRE(notificationsDb.isInitialized()); diff --git a/module-db/tests/NotificationsTable_tests.cpp b/module-db/tests/NotificationsTable_tests.cpp index a9b6210d900063a85d0472fbd6de03433b5a47fa..2c38598f50bf835c4d9878de3fed8a93159a2b3e 100644 --- a/module-db/tests/NotificationsTable_tests.cpp +++ b/module-db/tests/NotificationsTable_tests.cpp @@ -20,10 +20,10 @@ TEST_CASE("Notifications Table tests") { Database::initialize(); - const auto notificationsPath = (purefs::dir::getUserDiskPath() / "notifications.db").c_str(); + const auto notificationsPath = purefs::dir::getUserDiskPath() / "notifications.db"; std::filesystem::remove(notificationsPath); - NotificationsDB notificationsDb{notificationsPath}; + NotificationsDB notificationsDb{notificationsPath.c_str()}; REQUIRE(notificationsDb.isInitialized()); auto ¬ificationsTbl = notificationsDb.notifications; diff --git a/module-db/tests/SMSRecord_tests.cpp b/module-db/tests/SMSRecord_tests.cpp index f1fac9cb81ab624fcebe5ae7ce10ac7e901c68f5..0267e359a9b7d196d24d5be886e27985c52ab484 100644 --- a/module-db/tests/SMSRecord_tests.cpp +++ b/module-db/tests/SMSRecord_tests.cpp @@ -32,13 +32,13 @@ TEST_CASE("SMS Record tests") { Database::initialize(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); - const auto smsPath = (purefs::dir::getUserDiskPath() / "sms.db").c_str(); + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; + const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db"; std::filesystem::remove(contactsPath); std::filesystem::remove(smsPath); - auto contactsDB = std::make_unique(contactsPath); - auto smsDB = std::make_unique(smsPath); + ContactsDB contactsDB(contactsPath.c_str()); + SmsDB smsDB(smsPath.c_str()); const uint32_t dateTest = 123456789; const uint32_t dateSentTest = 987654321; @@ -49,7 +49,7 @@ TEST_CASE("SMS Record tests") const char *bodyTest2 = "Test SMS Body2"; const SMSType typeTest = SMSType ::DRAFT; - SMSRecordInterface smsRecInterface(smsDB.get(), contactsDB.get()); + SMSRecordInterface smsRecInterface(&smsDB, &contactsDB); SMSRecord recordIN; recordIN.date = dateTest; @@ -160,7 +160,7 @@ TEST_CASE("SMS Record tests") } // Remove sms records in order to check automatic management of threads and contact databases - ThreadRecordInterface threadRecordInterface(smsDB.get(), contactsDB.get()); + ThreadRecordInterface threadRecordInterface(&smsDB, &contactsDB); REQUIRE(smsRecInterface.RemoveByID(1)); records = smsRecInterface.GetLimitOffsetByField(0, 100, SMSRecordField::ContactID, "1"); REQUIRE((*records).size() == 1); @@ -178,7 +178,7 @@ TEST_CASE("SMS Record tests") // Test removing a message which belongs to non-existent thread REQUIRE(smsRecInterface.Add(recordIN)); - REQUIRE(smsDB->threads.removeById(1)); // stealthy thread remove + REQUIRE(smsDB.threads.removeById(1)); // stealthy thread remove REQUIRE(smsRecInterface.RemoveByID(1)); // Test handling of missmatch in sms vs. thread tables @@ -199,7 +199,7 @@ TEST_CASE("SMS Record tests") .snippet = threadRec.snippet, .type = threadRec.type}; threadRaw.msgCount = trueCount + 1; // break the DB - REQUIRE(smsDB->threads.update(threadRaw)); + REQUIRE(smsDB.threads.update(threadRaw)); REQUIRE(static_cast( smsRecInterface.GetLimitOffsetByField(0, 100, SMSRecordField::ThreadID, "1")->size()) == trueCount); diff --git a/module-db/tests/SMSTable_tests.cpp b/module-db/tests/SMSTable_tests.cpp index 223d8b1882067bb2f33a6ad8522ea5206eabde65..d597fa8dcf8b0b20761260befce2017d3b3ad74b 100644 --- a/module-db/tests/SMSTable_tests.cpp +++ b/module-db/tests/SMSTable_tests.cpp @@ -17,10 +17,10 @@ TEST_CASE("SMS Table tests") { Database::initialize(); - const auto smsPath = (purefs::dir::getUserDiskPath() / "sms.db").c_str(); + const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db"; std::filesystem::remove(smsPath); - SmsDB smsdb(smsPath); + SmsDB smsdb(smsPath.c_str()); REQUIRE(smsdb.isInitialized()); SMSTableRow testRow1 = {{.ID = 0}, diff --git a/module-db/tests/SMSTemplateRecord_tests.cpp b/module-db/tests/SMSTemplateRecord_tests.cpp index 0bfdf93bf179e830e21f32e365179d0e7d8419fd..e7928d24589dc748f8688647139e575969eea957 100644 --- a/module-db/tests/SMSTemplateRecord_tests.cpp +++ b/module-db/tests/SMSTemplateRecord_tests.cpp @@ -21,13 +21,13 @@ TEST_CASE("SMS templates Record tests") { Database::initialize(); - const auto smsPath = (purefs::dir::getUserDiskPath() / "sms.db").c_str(); + const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db"; std::filesystem::remove(smsPath); - auto smsDB = std::make_unique(smsPath); - REQUIRE(smsDB->isInitialized()); + SmsDB smsDB(smsPath.c_str()); + REQUIRE(smsDB.isInitialized()); - SMSTemplateRecordInterface SMSTemplateRecordInterface(smsDB.get()); + SMSTemplateRecordInterface SMSTemplateRecordInterface(&smsDB); SMSTemplateRecord testRec; testRec.text = "Test text"; testRec.lastUsageTimestamp = 100; diff --git a/module-db/tests/SMSTemplateTable_tests.cpp b/module-db/tests/SMSTemplateTable_tests.cpp index 1470f8bd4289bb8af8c54451806151f393ec526e..ae81dabc01ba1d4257d71f4a864310b81b5d756f 100644 --- a/module-db/tests/SMSTemplateTable_tests.cpp +++ b/module-db/tests/SMSTemplateTable_tests.cpp @@ -21,10 +21,10 @@ TEST_CASE("SMS Templates Table tests") { Database::initialize(); - const auto smsPath = (purefs::dir::getUserDiskPath() / "sms.db").c_str(); + const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db"; std::filesystem::remove(smsPath); - SmsDB smsDb{smsPath}; + SmsDB smsDb{smsPath.c_str()}; REQUIRE(smsDb.isInitialized()); auto &templatesTbl = smsDb.templates; diff --git a/module-db/tests/ThreadRecord_tests.cpp b/module-db/tests/ThreadRecord_tests.cpp index 73b06fa5f0cea184f12caeb260de48a8626072fa..cc1276bf8a23973af46e514d61e7403c78b94a45 100644 --- a/module-db/tests/ThreadRecord_tests.cpp +++ b/module-db/tests/ThreadRecord_tests.cpp @@ -30,15 +30,15 @@ TEST_CASE("Thread Record tests") { Database::initialize(); - const auto contactsPath = (purefs::dir::getUserDiskPath() / "contacts.db").c_str(); - const auto smsPath = (purefs::dir::getUserDiskPath() / "sms.db").c_str(); + const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db"; + const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db"; std::filesystem::remove(contactsPath); std::filesystem::remove(smsPath); - auto smsDB = std::make_unique(smsPath); - REQUIRE(smsDB->isInitialized()); - auto contactsDB = std::make_unique(contactsPath); - REQUIRE(contactsDB->isInitialized()); + SmsDB smsDB(smsPath.c_str()); + REQUIRE(smsDB.isInitialized()); + ContactsDB contactsDB(contactsPath.c_str()); + REQUIRE(contactsDB.isInitialized()); const uint32_t dateTest = 123456789; const char *snippetTest = "Test snippet"; @@ -46,7 +46,7 @@ TEST_CASE("Thread Record tests") const SMSType typeTest = SMSType ::UNKNOWN; const uint32_t contactIDTest = 100; - ThreadRecordInterface threadRecordInterface1(smsDB.get(), contactsDB.get()); + ThreadRecordInterface threadRecordInterface1(&smsDB, &contactsDB); ThreadRecord recordIN; recordIN.date = dateTest; @@ -208,7 +208,7 @@ TEST_CASE("Thread Record tests") const utils::PhoneNumber phoneNumber("+48600123456", utils::country::Id::UNKNOWN); const std::string lastSmsBody = "Ola"; - SMSRecordInterface smsRecInterface(smsDB.get(), contactsDB.get()); + SMSRecordInterface smsRecInterface(&smsDB, &contactsDB); SMSRecord recordIN; recordIN.date = 123456789; recordIN.dateSent = 987654321; diff --git a/module-db/tests/ThreadsTable_tests.cpp b/module-db/tests/ThreadsTable_tests.cpp index 3273febad5bfbcf53dff46e67df9ab8725be1811..80e202b15218909463300927e55a6215677cf0dc 100644 --- a/module-db/tests/ThreadsTable_tests.cpp +++ b/module-db/tests/ThreadsTable_tests.cpp @@ -21,10 +21,10 @@ TEST_CASE("Threads Table tests") { Database::initialize(); - const auto smsPath = (purefs::dir::getUserDiskPath() / "sms.db").c_str(); + const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db"; std::filesystem::remove(smsPath); - SmsDB smsdb{smsPath}; + SmsDB smsdb{smsPath.c_str()}; REQUIRE(smsdb.isInitialized()); ThreadsTableRow testRow1 = {{.ID = 0},