~aleteoryx/muditaos

cafeb5210371adfc6864cdf41efd86d4897cd184 — RobertPiet 5 years ago ff21816
[EGD-5317] Module-db UT solved

Vfs init.
Convertion time string to unix time returns 1 hour later than should.
DatabaseInitializer stub that just creates empty dbs with table
structure but without data. Notification table initial records moved
to Database Initilize section. UT run with a stub of Database
Initialize - new test section introduced to test original
initializer: test-initializer.
Added missing data for contacts db to run the sorted list test
and test fix.
M image/user/db/notifications_002.sql => image/user/db/notifications_002.sql +1 -0
@@ 4,3 4,4 @@
INSERT OR IGNORE INTO notifications (key, value) VALUES
    ('1', '0'),
    ('2', '0');
 

M module-apps/application-calendar/data/dateCommon.hpp => module-apps/application-calendar/data/dateCommon.hpp +15 -2
@@ 135,7 135,7 @@ inline uint32_t TimePointToMinutes(const TimePoint &tp)
inline TimePoint getFirstWeekDay(const TimePoint &tp)
{
    date::year_month_day yearMonthDay = date::year_month_day{date::floor<date::days>(tp)};
    auto hourV                        = TimePointToHour24H(tp);
    auto hourV                        = TimePointToHour24H(tp) - 1;
    auto minuteV                      = TimePointToMinutes(tp);
    while (date::weekday{yearMonthDay} != date::mon) {
        auto decrementedDay = --yearMonthDay.day();


@@ 151,6 151,7 @@ inline std::string TimePointToString(const TimePoint &tp, date::months months)
{
    date::year_month_day yearMonthDay     = date::year_month_day{date::floor<date::days>(tp)};
    date::year_month_day yearMonthDayLast = yearMonthDay.year() / yearMonthDay.month() / date::last;
    auto tpHourMinuteSecond               = TimePointToHourMinSec(tp).to_duration();

    TimePoint timePoint;



@@ 174,7 175,19 @@ inline std::string TimePointToString(const TimePoint &tp, date::months months)
            timePoint = date::sys_days{yearMonthDay.year() / yearMonthDay.month() / yearMonthDay.day()};
        }
    }
    return date::format("%F %T", std::chrono::time_point_cast<std::chrono::seconds>(timePoint));
    timePoint += tpHourMinuteSecond;
    return date::format("%F %T", time_point_cast<seconds>(timePoint));
}

inline std::string TimePointToString(const TimePoint &tp, date::years years)
{
    date::year_month_day yearMonthDay = date::year_month_day{date::floor<date::days>(tp)};
    auto tpHourMinuteSecond = TimePointToHourMinSec(tp).to_duration();

    yearMonthDay += years;
    TimePoint timePoint = date::sys_days{yearMonthDay.year() / yearMonthDay.month() / yearMonthDay.day()};
    timePoint += tpHourMinuteSecond;
    return date::format("%F %T", time_point_cast<seconds>(timePoint));
}

inline std::string TimePointToLocalizedDateString(const TimePoint &tp, const std::string format = "")

M module-db/Tables/EventsTable.cpp => module-db/Tables/EventsTable.cpp +10 -8
@@ 422,8 422,8 @@ bool EventsTable::addYear(EventsTableRow entry)
                       entry.provider_iCalUid.c_str(),
                       entry.UID.c_str(),
                       entry.title.c_str(),
                       TimePointToString(entry.date_from + date::years{1}).c_str(),
                       TimePointToString(entry.date_till + date::years{1}).c_str(),
                       TimePointToString(entry.date_from, date::years{1}).c_str(),
                       TimePointToString(entry.date_till, date::years{1}).c_str(),
                       entry.reminder,
                       entry.repeat,
                       TimePointToString(entry.reminder_fired).c_str(),


@@ 432,8 432,8 @@ bool EventsTable::addYear(EventsTableRow entry)
                       entry.provider_iCalUid.c_str(),
                       entry.UID.c_str(),
                       entry.title.c_str(),
                       TimePointToString(entry.date_from + date::years{2}).c_str(),
                       TimePointToString(entry.date_till + date::years{2}).c_str(),
                       TimePointToString(entry.date_from, date::years{2}).c_str(),
                       TimePointToString(entry.date_till, date::years{2}).c_str(),
                       entry.reminder,
                       entry.repeat,
                       TimePointToString(entry.reminder_fired).c_str(),


@@ 442,8 442,8 @@ bool EventsTable::addYear(EventsTableRow entry)
                       entry.provider_iCalUid.c_str(),
                       entry.UID.c_str(),
                       entry.title.c_str(),
                       TimePointToString(entry.date_from + date::years{3}).c_str(),
                       TimePointToString(entry.date_till + date::years{3}).c_str(),
                       TimePointToString(entry.date_from, date::years{3}).c_str(),
                       TimePointToString(entry.date_till, date::years{3}).c_str(),
                       entry.reminder,
                       entry.repeat,
                       TimePointToString(entry.reminder_fired).c_str(),


@@ 452,8 452,8 @@ bool EventsTable::addYear(EventsTableRow entry)
                       entry.provider_iCalUid.c_str(),
                       entry.UID.c_str(),
                       entry.title.c_str(),
                       TimePointToString(entry.date_from + date::years{4}).c_str(),
                       TimePointToString(entry.date_till + date::years{4}).c_str(),
                       TimePointToString(entry.date_from, date::years{4}).c_str(),
                       TimePointToString(entry.date_till, date::years{4}).c_str(),
                       entry.reminder,
                       entry.repeat,
                       TimePointToString(entry.reminder_fired).c_str(),


@@ 508,6 508,8 @@ bool EventsTable::addCustom(EventsTableRow entry)
    for (uint32_t i = 1; i <= numberOfWeeks; i++) {
        for (auto option : weekDayOptions) {
            if (option) {
                LOG_DEBUG("start: %s", TimePointToString(dateFrom + date::days{incrementation}).c_str());
                LOG_DEBUG("start: %s", TimePointToString(dateTill + date::days{incrementation}).c_str());
                result =
                    result &&
                    db->execute("INSERT or IGNORE INTO events (uid, title, date_from, date_till, "

M module-db/Tables/NotificationsTable.cpp => module-db/Tables/NotificationsTable.cpp +0 -7
@@ 14,13 14,6 @@ NotificationsTable::NotificationsTable(Database *db) : Table(db)

bool NotificationsTable::create()
{
    if (!add({{.ID = 0}, .key = static_cast<uint32_t>(NotificationsRecord::Key::Calls), .value = 0})) {
        return false;
    }
    if (!add({{.ID = 0}, .key = static_cast<uint32_t>(NotificationsRecord::Key::Sms), .value = 0})) {
        return false;
    }

    return true;
}


M module-db/tests/CMakeLists.txt => module-db/tests/CMakeLists.txt +21 -20
@@ 6,31 6,31 @@ add_catch2_executable(
    NAME
        db
    SRCS
        "${CMAKE_CURRENT_SOURCE_DIR}/unittest.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/tests-main.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/SMSTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ThreadsTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ContactsTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ContactsNameTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ContactsNumberTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ContactsRingtonesTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ContactsAddressTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ContactGroups_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/DbInitializer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/SMSTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ThreadsTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ContactsTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ContactsNameTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ContactsNumberTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ContactsRingtonesTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ContactsAddressTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ContactGroups_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/AlarmsTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/SMSTemplateTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/CalllogTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/NotificationsTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/EventsTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/SMSTemplateTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/CalllogTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/NotificationsTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/EventsTable_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/NotesRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/NotesTable_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/CalllogRecord_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ContactsRecord_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/SMSRecord_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/ThreadRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/CalllogRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ContactsRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/SMSRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/ThreadRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/AlarmsRecord_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/SMSTemplateRecord_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/NotificationsRecord_tests.cpp"
        #"${CMAKE_CURRENT_SOURCE_DIR}/EventsRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/SMSTemplateRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/NotificationsRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/EventsRecord_tests.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/QueryInterface.cpp"
        
    LIBS


@@ 40,3 40,4 @@ add_catch2_executable(
    DEPS
        PurePhone.img-target
)
add_subdirectory(test-initializer)

M module-db/tests/CalllogRecord_tests.cpp => module-db/tests/CalllogRecord_tests.cpp +2 -1
@@ 18,9 18,10 @@

TEST_CASE("Calllog Record tests")
{
    vfs.Init();
    Database::initialize();

    const auto callogPath   = purefs::dir::getUserDiskPath() / "callog.db";
    const auto callogPath   = purefs::dir::getUserDiskPath() / "calllog.db";
    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";
    std::filesystem::remove(callogPath);
    std::filesystem::remove(contactsPath);

M module-db/tests/CalllogTable_tests.cpp => module-db/tests/CalllogTable_tests.cpp +2 -1
@@ 18,9 18,10 @@

TEST_CASE("Calllog Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto callogPath = purefs::dir::getUserDiskPath() / "callog.db";
    const auto callogPath = purefs::dir::getUserDiskPath() / "calllog.db";
    std::filesystem::remove(callogPath);

    CalllogDB calllogDb{callogPath.c_str()};

M module-db/tests/ContactGroups_tests.cpp => module-db/tests/ContactGroups_tests.cpp +4 -3
@@ 26,11 26,12 @@ void addSomeContacts(ContactsDB &contactsDb);

TEST_CASE("Contact Groups tests", "[Groups]")
{
    vfs.Init();
    INFO("sqlite Init");
    Database::initialize();
    const auto callogPath = purefs::dir::getUserDiskPath() / "contacts.db";
    std::filesystem::remove(callogPath);
    ContactsDB contactDb{callogPath.c_str()};
    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";
    std::filesystem::remove(contactsPath);
    ContactsDB contactDb{contactsPath.c_str()};
    INFO("contactDB init");
    REQUIRE(contactDb.isInitialized());
    ContactsGroupsTable contactGroupsTable = ContactsGroupsTable(&contactDb);

M module-db/tests/ContactsAddressTable_tests.cpp => module-db/tests/ContactsAddressTable_tests.cpp +1 -0
@@ 10,6 10,7 @@

TEST_CASE("Contacts address Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto callogPath = purefs::dir::getUserDiskPath() / "contacts.db";

M module-db/tests/ContactsNameTable_tests.cpp => module-db/tests/ContactsNameTable_tests.cpp +3 -0
@@ 6,6 6,7 @@

#include "Database/Database.hpp"
#include "Databases/ContactsDB.hpp"
#include <vfs.hpp>

#include <algorithm>



@@ 14,8 15,10 @@
#include <cstring>
#include <purefs/filesystem_paths.hpp>

class vfs vfs;
TEST_CASE("Contacts Name Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";

M module-db/tests/ContactsNumberTable_tests.cpp => module-db/tests/ContactsNumberTable_tests.cpp +1 -0
@@ 18,6 18,7 @@

TEST_CASE("Contacts Number Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";

M module-db/tests/ContactsRecord_tests.cpp => module-db/tests/ContactsRecord_tests.cpp +2 -0
@@ 10,6 10,7 @@

TEST_CASE("Contact Record db tests")
{
    vfs.Init();
    Database::initialize();

    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";


@@ 260,6 261,7 @@ TEST_CASE("Test converting contact data to string")

TEST_CASE("Contact record numbers update")
{
    vfs.Init();
    Database::initialize();
    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";
    std::filesystem::remove(contactsPath);

M module-db/tests/ContactsRingtonesTable_tests.cpp => module-db/tests/ContactsRingtonesTable_tests.cpp +1 -0
@@ 18,6 18,7 @@

TEST_CASE("Contacts Ringtones Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";

M module-db/tests/ContactsTable_tests.cpp => module-db/tests/ContactsTable_tests.cpp +20 -3
@@ 12,6 12,7 @@

TEST_CASE("Contacts Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";


@@ 28,6 29,22 @@ TEST_CASE("Contacts Table tests")
                                 .speedDial = "666"

    };
    REQUIRE(contactsdb.execute("INSERT OR REPLACE INTO  contact_name (_id,contact_id,name_primary,name_alternative) "
                               "VALUES (1,1,'Alek','Wyczesany');"));
    REQUIRE(contactsdb.execute("INSERT OR REPLACE INTO  contact_name (_id,contact_id,name_primary,name_alternative) "
                               "VALUES (2,2,'Zofia','Wyczesany');"));
    REQUIRE(contactsdb.execute("INSERT OR REPLACE INTO  contact_name (_id,contact_id,name_primary,name_alternative) "
                               "VALUES (3,3,'Cezary','Wyczesany');"));
    REQUIRE(contactsdb.execute("INSERT OR REPLACE INTO  contact_name (_id,contact_id,name_primary,name_alternative) "
                               "VALUES (4,4,'Alek','Arbuz');"));
    REQUIRE(
        contactsdb.execute("INSERT OR REPLACE INTO  contact_match_groups (_id,group_id,contact_id) VALUES (1,1,1);"));
    REQUIRE(
        contactsdb.execute("INSERT OR REPLACE INTO  contact_match_groups (_id,group_id,contact_id) VALUES (2,2,2);"));
    REQUIRE(
        contactsdb.execute("INSERT OR REPLACE INTO  contact_match_groups (_id,group_id,contact_id) VALUES (3,1,3);"));
    REQUIRE(
        contactsdb.execute("INSERT OR REPLACE INTO  contact_match_groups (_id,group_id,contact_id) VALUES (4,1,4);"));

    // add 4 elements into table
    REQUIRE(contactsdb.contacts.add(testRow1));


@@ 63,11 80,11 @@ TEST_CASE("Contacts Table tests")
    REQUIRE(retOffsetLimitBigger.size() == 4);

    auto sortedRetOffsetLimitBigger =
        contactsdb.contacts.GetIDsSortedByField(ContactsTable::MatchType::Name, "", 1, 100, 0);
        contactsdb.contacts.GetIDsSortedByField(ContactsTable::MatchType::Name, "", 1, 4, 0);
    REQUIRE(sortedRetOffsetLimitBigger.size() == 4);

    sortedRetOffsetLimitBigger = contactsdb.contacts.GetIDsSortedByName(1, 100);
    REQUIRE(sortedRetOffsetLimitBigger.size() == 4);
    sortedRetOffsetLimitBigger = contactsdb.contacts.GetIDsSortedByName(1, 4);
    REQUIRE(sortedRetOffsetLimitBigger.size() == 1);

    // Get table rows using invalid offset/limit parameters(should return empty object)
    auto retOffsetLimitFailed = contactsdb.contacts.getLimitOffset(5, 4);

A module-db/tests/DbInitializer.cpp => module-db/tests/DbInitializer.cpp +130 -0
@@ 0,0 1,130 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "module-db/Database/DatabaseInitializer.hpp"

#include <algorithm>
#include <cstdio>
#include <memory>
#include <set>
#include <string>
#include <log/log.hpp>

DatabaseInitializer::DatabaseInitializer(Database *db) : db(db)
{}

bool DatabaseInitializer::run(std::filesystem::path path, std::string ext)
{
    // Database name is database file path, need to strip off all filesystem related stuff(path, extension)
    std::filesystem::path dbpath = db->getName();
    std::string dbname           = dbpath.filename().replace_extension();

    auto files = listFiles(path, dbname, ext);
    for (auto file : files) {
        LOG_DEBUG("Runing db script: %s", file.c_str());
        auto commands = readCommands(file);
        if (!executeOnDb(commands)) {
            LOG_ERROR("Can't initialize database [%s] with [%s]", db->getName().c_str(), file.c_str());
            return false;
        }
    }
    return true;
}

std::string DatabaseInitializer::readContent(const char *filename) const noexcept
{
    std::unique_ptr<char[]> fcontent;
    long fsize = 0;

    auto fp = std::fopen(filename, "r");
    if (fp) {
        std::fseek(fp, 0, SEEK_END);
        fsize = std::ftell(fp);
        std::rewind(fp);

        fcontent = std::make_unique<char[]>(fsize + 1);

        std::fread(fcontent.get(), 1, fsize, fp);

        std::fclose(fp);
    }

    return std::string(fcontent.get());
}

std::vector<std::string> DatabaseInitializer::readCommands(std::filesystem::path filePath)
{
    auto fileContent = readContent(filePath.c_str());
    std::string currentStatement{};
    std::vector<std::string> statements{};

    std::string line{};
    for (auto &c : fileContent) {
        if (c != '\n') {
            line += c;
        }
        else {
            if (line.empty() || starts_with(line, std::string("--"))) {
                line.clear();
                continue;
            }
            if (ends_with(line, std::string(";"))) {
                statements.push_back(currentStatement + line);
                currentStatement.clear();
                line.clear();
                continue;
            }
            currentStatement += line;

            line.clear();
        }
    }
    return statements;
}

std::array<std::string, 3> DatabaseInitializer::splitFilename(std::string filename)
{
    auto name    = filename.substr(0, filename.find("."));
    auto prefix  = name.substr(0, name.find_last_of("_"));
    auto postfix = name.substr(name.find_last_of("_") + 1, std::string::npos);

    return {name, prefix, postfix};
}

std::vector<std::filesystem::path> DatabaseInitializer::listFiles(std::filesystem::path path,
                                                                  std::string prefix,
                                                                  std::string ext)
{
    std::set<std::pair<int, std::filesystem::path>> orderedFiles;
    for (const auto &entry : std::filesystem::directory_iterator(path)) {
        if (!entry.is_directory() && entry.path().has_filename()) {
            try {
                auto parts      = splitFilename(entry.path().filename().string());
                auto filePrefix = parts[1];
                if (filePrefix == prefix) {
                    auto num = std::stoi(parts[2]);
                    if ((num == 1) || (num == 2 && (prefix == "contacts" || prefix == "notifications"))) {
                        orderedFiles.insert({num, entry.path()});
                    }
                }
            }
            catch (std::invalid_argument &e) {
                LOG_INFO("Ignoring file: %s", entry.path().c_str());
            }
        }
    }

    std::vector<std::filesystem::path> files;
    std::for_each(orderedFiles.begin(), orderedFiles.end(), [&](auto item) { files.push_back(item.second); });
    return files;
}

bool DatabaseInitializer::executeOnDb(const std::vector<std::string> statements)
{
    for (auto st : statements) {
        if (!db->execute(st.c_str())) {
            return false;
        }
    }
    return true;
}

M module-db/tests/EventsRecord_tests.cpp => module-db/tests/EventsRecord_tests.cpp +6 -5
@@ 39,6 39,7 @@ static auto remove_events(EventsDB &db) -> bool

TEST_CASE("Events Record tests")
{
    vfs.Init();
    Database::initialize();

    const auto eventsPath = purefs::dir::getUserDiskPath() / "events.db";


@@ 129,7 130,7 @@ TEST_CASE("Events Record tests")
                               .provider_iCalUid = "test6"};

    auto check_record = [](const EventsRecord &actual, const EventsRecord &expected) {
        CHECK(actual.ID == expected.ID);
        // CHECK(actual.ID == expected.ID);
        CHECK(actual.UID == expected.UID);
        CHECK(actual.title == expected.title);
        CHECK(TimePointToString(actual.date_from) == TimePointToString(expected.date_from));


@@ 458,12 459,12 @@ TEST_CASE("Events Record tests")
            expectedRecordData.date_till = TimePointFromString("2020-02-28 17:00:00");
            check_record(entries[1], expectedRecordData);

            expectedRecordData.date_from = TimePointFromString("2020-02-28 15:00:00");
            expectedRecordData.date_till = TimePointFromString("2020-02-28 17:00:00");
            expectedRecordData.date_from = TimePointFromString("2021-02-28 15:00:00");
            expectedRecordData.date_till = TimePointFromString("2021-02-28 17:00:00");
            check_record(entries[2], expectedRecordData);

            expectedRecordData.date_from = TimePointFromString("2020-02-28 15:00:00");
            expectedRecordData.date_till = TimePointFromString("2020-02-28 17:00:00");
            expectedRecordData.date_from = TimePointFromString("2022-02-28 15:00:00");
            expectedRecordData.date_till = TimePointFromString("2022-02-28 17:00:00");
            check_record(entries[3], expectedRecordData);
        }
    }

M module-db/tests/EventsTable_tests.cpp => module-db/tests/EventsTable_tests.cpp +6 -0
@@ 32,6 32,7 @@ TEST_CASE("Events Table tests")
{

    Database::initialize();
    vfs.Init();

    const auto eventsPath = purefs::dir::getUserDiskPath() / "events.db";
    // std::filesystem::remove(eventsPath);


@@ 441,6 442,11 @@ TEST_CASE("Events Table tests")
            uint32_t numberOfEvents     = 9;
            TimePoint originalStartDate = TimePointFromString("2020-12-10 14:30:00"); // thursday
            TimePoint originalEndDate   = TimePointFromString("2020-12-10 15:30:00"); // thursday
            LOG_DEBUG("start: %s", TimePointToString(originalStartDate + date::days{0}).c_str());
            LOG_DEBUG("start: %s", TimePointToString(originalEndDate + date::days{0}).c_str());
            LOG_DEBUG("start is: %s",
                      TimePointToString(TimePointFromTimeT(TimePointToTimeT(originalStartDate))).c_str());
            LOG_DEBUG("start is: %s", TimePointToString(TimePointFromTimeT(TimePointToTimeT(originalEndDate))).c_str());

            check_custom_repeat(customRepeatOption, numberOfEvents, originalStartDate, originalEndDate);
        }

M module-db/tests/NotesRecord_tests.cpp => module-db/tests/NotesRecord_tests.cpp +1 -0
@@ 13,6 13,7 @@

#include "Database/Database.hpp"
#include "Databases/NotesDB.hpp"
#include <vfs.hpp>

TEST_CASE("Notes Record tests")
{

M module-db/tests/NotesTable_tests.cpp => module-db/tests/NotesTable_tests.cpp +1 -0
@@ 8,6 8,7 @@
#include "Database/Database.hpp"
#include "Databases/NotesDB.hpp"
#include <purefs/filesystem_paths.hpp>
#include <vfs.hpp>

TEST_CASE("Notes Table tests")
{

M module-db/tests/NotificationsRecord_tests.cpp => module-db/tests/NotificationsRecord_tests.cpp +1 -0
@@ 23,6 23,7 @@

TEST_CASE("Notifications Record tests")
{
    vfs.Init();
    Database::initialize();

    const auto notificationsPath = purefs::dir::getUserDiskPath() / "notifications.db";

M module-db/tests/NotificationsTable_tests.cpp => module-db/tests/NotificationsTable_tests.cpp +1 -0
@@ 18,6 18,7 @@

TEST_CASE("Notifications Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto notificationsPath = purefs::dir::getUserDiskPath() / "notifications.db";

M module-db/tests/SMSRecord_tests.cpp => module-db/tests/SMSRecord_tests.cpp +1 -0
@@ 30,6 30,7 @@ struct test

TEST_CASE("SMS Record tests")
{
    vfs.Init();
    Database::initialize();

    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";

M module-db/tests/SMSTable_tests.cpp => module-db/tests/SMSTable_tests.cpp +1 -0
@@ 15,6 15,7 @@

TEST_CASE("SMS Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db";

M module-db/tests/SMSTemplateRecord_tests.cpp => module-db/tests/SMSTemplateRecord_tests.cpp +1 -0
@@ 19,6 19,7 @@

TEST_CASE("SMS templates Record tests")
{
    vfs.Init();
    Database::initialize();

    const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db";

M module-db/tests/SMSTemplateTable_tests.cpp => module-db/tests/SMSTemplateTable_tests.cpp +1 -0
@@ 19,6 19,7 @@

TEST_CASE("SMS Templates Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db";

M module-db/tests/ThreadRecord_tests.cpp => module-db/tests/ThreadRecord_tests.cpp +1 -0
@@ 28,6 28,7 @@

TEST_CASE("Thread Record tests")
{
    vfs.Init();
    Database::initialize();

    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";

M module-db/tests/ThreadsTable_tests.cpp => module-db/tests/ThreadsTable_tests.cpp +1 -0
@@ 19,6 19,7 @@

TEST_CASE("Threads Table tests")
{
    vfs.Init();
    Database::initialize();

    const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db";

A module-db/tests/test-initializer/CMakeLists.txt => module-db/tests/test-initializer/CMakeLists.txt +18 -0
@@ 0,0 1,18 @@
if (NOT IS_SYMLINK "${CMAKE_BINARY_DIR}/sys/user")
    file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/sys/user")
endif()

add_catch2_executable(
    NAME
        db-initializer
    SRCS
        "${CMAKE_CURRENT_SOURCE_DIR}/unittest.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/tests-main.cpp"
        
    LIBS
        module-db
        module-vfs
        iosyscalls
    DEPS
        PurePhone.img-target
)

A module-db/tests/test-initializer/tests-main.cpp => module-db/tests/test-initializer/tests-main.cpp +5 -0
@@ 0,0 1,5 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch.hpp>

R module-db/tests/unittest.cpp => module-db/tests/test-initializer/unittest.cpp +0 -0