Refactor,

Added ContactsTable
This commit is contained in:
Mati committed 2019-05-28 13:27:54 +02:00
1 parent f02517ebfa
commit b9bd4372e7
18 files changed
+691 -96

No files matched your search

+35 -22
View File
@@ -21,6 +21,7 @@
#include <iostream>
#include "../Database/Database.hpp"
#include "../Databases/SmsDB.hpp"
#include "Tables/ThreadsTable.hpp"
@@ -28,9 +29,9 @@ TEST_CASE("Threads Table tests")
{
Database::Initialize();
vfs.remove(ThreadsTable::GetDBName());
ThreadsTable threadstable;
vfs.remove(SmsDB::GetDBName());
SmsDB smsdb;
ThreadsTableRow testRow1 = {.ID=0,
.date=0,
@@ -43,54 +44,66 @@ TEST_CASE("Threads Table tests")
};
// Add 4 elements into table
REQUIRE(threadstable.Add(testRow1));
REQUIRE(threadstable.Add(testRow1));
REQUIRE(threadstable.Add(testRow1));
REQUIRE(threadstable.Add(testRow1));
REQUIRE(smsdb.threads.Add(testRow1));
REQUIRE(smsdb.threads.Add(testRow1));
REQUIRE(smsdb.threads.Add(testRow1));
REQUIRE(smsdb.threads.Add(testRow1));
// Table should have 4 elements
REQUIRE(threadstable.GetCount() == 4);
REQUIRE(smsdb.threads.GetCount() == 4);
// Update existing element in table
testRow1.ID = 4;
testRow1.snippet = "Updated Test snippet";
REQUIRE(threadstable.Update(testRow1));
REQUIRE(smsdb.threads.Update(testRow1));
// Get table row using valid ID & check if it was updated
auto thread = threadstable.GetByID(4);
auto thread = smsdb.threads.GetByID(4);
REQUIRE(thread.snippet == testRow1.snippet);
// Get table row using invalid ID(should return empty SMSTableRow)
auto threadFailed = threadstable.GetByID(100);
auto threadFailed = smsdb.threads.GetByID(100);
REQUIRE(threadFailed.snippet == "");
// Get table rows using valid offset/limit parameters
auto retOffsetLimit = threadstable.GetLimitOffset(0,4);
auto retOffsetLimit = smsdb.threads.GetLimitOffset(0,4);
REQUIRE(retOffsetLimit.size() == 4);
// Get table rows using invalid limit parameters(should return 4 elements instead of 100)
auto retOffsetLimitBigger = threadstable.GetLimitOffset(0,100);
auto retOffsetLimitBigger = smsdb.threads.GetLimitOffset(0,100);
REQUIRE(retOffsetLimitBigger.size() == 4);
// Get table rows using invalid offset/limit parameters(should return empty object)
auto retOffsetLimitFailed = threadstable.GetLimitOffset(5,4);
auto retOffsetLimitFailed = smsdb.threads.GetLimitOffset(5,4);
REQUIRE(retOffsetLimitFailed.size() == 0);
REQUIRE(threadstable.RemoveByID(2));
// Get table rows using valid offset/limit parameters and specific field's ID
REQUIRE(smsdb.threads.GetLimitOffsetByFieldID(0,4,"msg_count",0).size() == 4);
// Get table rows using valid offset/limit parameters and specific field's ID
REQUIRE(smsdb.threads.GetLimitOffsetByFieldID(0,4,"contact_id",5).size() == 0);
// Get count of elements by field's ID
REQUIRE(smsdb.threads.GetCountByFieldID("contact_id",0) == 4);
// Get count of elements by invalid field's ID
REQUIRE(smsdb.threads.GetCountByFieldID("invalid_field",0) == 0);
REQUIRE(smsdb.threads.RemoveByID(2));
// Table should have now 3 elements
REQUIRE(threadstable.GetCount() == 3);
REQUIRE(smsdb.threads.GetCount() == 3);
// Remove non existing element
REQUIRE(threadstable.RemoveByID(100));
REQUIRE(smsdb.threads.RemoveByID(100));
// Remove all elements from table
REQUIRE(threadstable.RemoveByID(1));
REQUIRE(threadstable.RemoveByID(3));
REQUIRE(threadstable.RemoveByID(4));
REQUIRE(smsdb.threads.RemoveByID(1));
REQUIRE(smsdb.threads.RemoveByID(3));
REQUIRE(smsdb.threads.RemoveByID(4));
// Table should have be empty now
REQUIRE(threadstable.GetCount() == 0);
// Table should be empty now
REQUIRE(smsdb.threads.GetCount() == 0);
Database::Deinitialize();
}