Files
MuditaOS/module-db/tests/ContactsNameTable_tests.cpp
pholat 23df384c55 EGD-3087 SMS Search implemented (#374)
* EGD-3087 WIP adding SMS Querry

* EGD-3087 Added query virtual interface on Service top layer

Service shouldn't implement query logic and should be proxying that.

additionally:
- small fixes in includes
- shared service db name same way as apps and event manager

* EGD-3087 Query - want to work on interface not on db

* EGD-3087 Query gluecode works fine. Our query in SMS search calls getBySMSQuery

Changes cut off before any potential orm interface layer

* EGD-3087 WIP Interface in use

* EGD-3087 Query for SMS search works as designed

* EGD-3087 Query results should be on screen

* EGD-3087 BUG workaround - need to deep refresh display to show data

* EGD-3087 Searching for text from input works fine

* EGD-3087 Showing results / or empty results depending on query

* EGD-3087 Pre PR fixups

* EGD-3087 Empty search - getting back to prewious window ignore current

* EGD-3087 PR applied

* EGD-3087 PR - style fixed

* EGD-3087 Review - DB ListView handling moved to separate function

* EGD-3087 Workaround: crash on use after free fix

* EGD-3087 PR stylistic changes

* EGD-3087 PR cleanup applied

* EGD-3087 Added test for Query interface

* EGD-3087 renamed getByQuery to getQuery & finished tests

* EGD-3087 Post rebase fixup

* EGD-3087 PR - moved ListView request part to separate function

* EGD-3087 PR Fixups

* EGD-3087 Post rebase style fix

* EGD-3087 Added variable for DB service stack & const to getter function
2020-05-27 13:49:50 +02:00

97 lines
3.0 KiB
C++

/*
* @file ContactsNameTable_tests.cpp
* @author Mateusz Piesta (mateusz.piesta@mudita.com)
* @date 28.05.19
* @brief
* @copyright Copyright (C) 2019 mudita.com
* @details
*/
#include "vfs.hpp"
#include "catch.hpp"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include "../Database/Database.hpp"
#include "../Databases/ContactsDB.hpp"
TEST_CASE("Contacts Name Table tests")
{
Database::Initialize();
vfs.remove(ContactsDB::GetDBName());
ContactsDB contactsdb;
REQUIRE(contactsdb.IsInitialized());
ContactsNameTableRow testRow1 = {.ID = 0, .contactID = 0, .namePrimary = "Mateusz", .nameAlternative = "Pati"};
// Add 4 elements into table
REQUIRE(contactsdb.name.Add(testRow1));
REQUIRE(contactsdb.name.Add(testRow1));
REQUIRE(contactsdb.name.Add(testRow1));
REQUIRE(contactsdb.name.Add(testRow1));
// Table should have 4 elements
REQUIRE(contactsdb.name.GetCount() == 4);
// Update existing element in table
testRow1.ID = 4;
testRow1.nameAlternative = "Pateusz";
REQUIRE(contactsdb.name.Update(testRow1));
// Get table row using valid ID & check if it was updated
auto sms = contactsdb.name.GetByID(4);
REQUIRE(sms.nameAlternative == testRow1.nameAlternative);
// Get table row using invalid ID(should return empty contactsdb.nameRow)
auto smsFailed = contactsdb.name.GetByID(100);
REQUIRE(smsFailed.nameAlternative == "");
// Get table rows using valid offset/limit parameters
auto retOffsetLimit = contactsdb.name.GetLimitOffset(0, 4);
REQUIRE(retOffsetLimit.size() == 4);
// Get table rows using valid offset/limit parameters and specific field's ID
REQUIRE(contactsdb.name.GetLimitOffsetByField(0, 4, ContactNameTableFields::NamePrimary, "Mateusz").size() == 4);
// Get table rows using invalid limit parameters(should return 4 elements instead of 100)
auto retOffsetLimitBigger = contactsdb.name.GetLimitOffset(0, 100);
REQUIRE(retOffsetLimitBigger.size() == 4);
// Get table rows using invalid offset/limit parameters(should return empty object)
auto retOffsetLimitFailed = contactsdb.name.GetLimitOffset(5, 4);
REQUIRE(retOffsetLimitFailed.size() == 0);
// Get count of elements by field's ID
REQUIRE(contactsdb.name.GetCountByFieldID("contact_id", 0) == 4);
// Get count of elements by invalid field's ID
REQUIRE(contactsdb.name.GetCountByFieldID("invalid_field", 0) == 0);
REQUIRE(contactsdb.name.RemoveByID(2));
// Table should have now 3 elements
REQUIRE(contactsdb.name.GetCount() == 3);
// Remove non existing element
REQUIRE(contactsdb.name.RemoveByID(100));
// Remove all elements from table
REQUIRE(contactsdb.name.RemoveByID(1));
REQUIRE(contactsdb.name.RemoveByID(3));
REQUIRE(contactsdb.name.RemoveByID(4));
// Table should be empty now
REQUIRE(contactsdb.name.GetCount() == 0);
Database::Deinitialize();
}