mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-02-20 07:55:27 -05:00
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.
108 lines
3.4 KiB
C++
108 lines
3.4 KiB
C++
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include "Interface/SMSTemplateRecord.hpp"
|
|
#include "Database/Database.hpp"
|
|
#include "Databases/SmsDB.hpp"
|
|
|
|
#include <vfs.hpp>
|
|
#include <purefs/filesystem_paths.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <filesystem>
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
|
|
TEST_CASE("SMS templates Record tests")
|
|
{
|
|
vfs.Init();
|
|
Database::initialize();
|
|
|
|
const auto smsPath = purefs::dir::getUserDiskPath() / "sms.db";
|
|
std::filesystem::remove(smsPath);
|
|
|
|
SmsDB smsDB(smsPath.c_str());
|
|
REQUIRE(smsDB.isInitialized());
|
|
|
|
SMSTemplateRecordInterface SMSTemplateRecordInterface(&smsDB);
|
|
SMSTemplateRecord testRec;
|
|
testRec.text = "Test text";
|
|
testRec.lastUsageTimestamp = 100;
|
|
|
|
// Add 4 records
|
|
REQUIRE(SMSTemplateRecordInterface.Add(testRec));
|
|
REQUIRE(SMSTemplateRecordInterface.Add(testRec));
|
|
REQUIRE(SMSTemplateRecordInterface.Add(testRec));
|
|
REQUIRE(SMSTemplateRecordInterface.Add(testRec));
|
|
|
|
REQUIRE(SMSTemplateRecordInterface.GetCount() == 4);
|
|
|
|
SECTION("Get entry by ID")
|
|
{
|
|
auto templ = SMSTemplateRecordInterface.GetByID(4);
|
|
REQUIRE(templ.ID == 4);
|
|
REQUIRE(templ.text == testRec.text);
|
|
REQUIRE(templ.lastUsageTimestamp == testRec.lastUsageTimestamp);
|
|
}
|
|
|
|
SECTION("Entry update")
|
|
{
|
|
testRec.ID = 4;
|
|
testRec.text = "New text";
|
|
testRec.lastUsageTimestamp = 200;
|
|
REQUIRE(SMSTemplateRecordInterface.Update(testRec));
|
|
auto templ = SMSTemplateRecordInterface.GetByID(4);
|
|
REQUIRE(templ.ID == 4);
|
|
REQUIRE(templ.text == testRec.text);
|
|
REQUIRE(templ.lastUsageTimestamp == testRec.lastUsageTimestamp);
|
|
}
|
|
|
|
SECTION("Get entry - invalid ID")
|
|
{
|
|
auto templ = SMSTemplateRecordInterface.GetByID(100);
|
|
REQUIRE(templ.ID == DB_ID_NONE);
|
|
REQUIRE(templ.text == "");
|
|
REQUIRE(templ.lastUsageTimestamp == 0);
|
|
}
|
|
|
|
SECTION("Get table rows")
|
|
{
|
|
// Get table rows using valid offset/limit parameters
|
|
auto retOffsetLimit = SMSTemplateRecordInterface.GetLimitOffset(0, 4);
|
|
REQUIRE(retOffsetLimit->size() == 4);
|
|
|
|
// Get table rows using invalid limit parameters(should return 4 elements instead of 100)
|
|
auto retOffsetLimitBigger = SMSTemplateRecordInterface.GetLimitOffset(0, 100);
|
|
REQUIRE(retOffsetLimitBigger->size() == 4);
|
|
|
|
// Get table rows using invalid offset/limit parameters(should return empty object)
|
|
auto retOffsetLimitFailed = SMSTemplateRecordInterface.GetLimitOffset(5, 4);
|
|
REQUIRE(retOffsetLimitFailed->size() == 0);
|
|
}
|
|
|
|
SECTION("Remove entries")
|
|
{
|
|
REQUIRE(SMSTemplateRecordInterface.RemoveByID(2));
|
|
|
|
// Table should have now 3 elements
|
|
REQUIRE(SMSTemplateRecordInterface.GetCount() == 3);
|
|
|
|
// Remove non existing element
|
|
REQUIRE(!SMSTemplateRecordInterface.RemoveByID(100));
|
|
|
|
// Remove all elements from table
|
|
REQUIRE(SMSTemplateRecordInterface.RemoveByID(1));
|
|
REQUIRE(SMSTemplateRecordInterface.RemoveByID(3));
|
|
REQUIRE(SMSTemplateRecordInterface.RemoveByID(4));
|
|
|
|
// Table should be empty now
|
|
REQUIRE(SMSTemplateRecordInterface.GetCount() == 0);
|
|
}
|
|
|
|
Database::deinitialize();
|
|
}
|