2022-09-15 21:34:39 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
#include "base.h"
|
2023-03-20 15:37:13 +00:00
|
|
|
#include "storage.h"
|
2022-09-20 17:16:48 +00:00
|
|
|
#include "cache.h"
|
2022-09-15 21:34:39 +00:00
|
|
|
|
|
|
|
#include <QString>
|
2023-10-15 14:19:53 +00:00
|
|
|
#include <QVariant>
|
2022-09-15 21:34:39 +00:00
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
class BaseTest : public ::testing::Test {
|
2022-09-15 21:34:39 +00:00
|
|
|
protected:
|
2023-03-21 11:05:54 +00:00
|
|
|
BaseTest():
|
2022-09-15 21:34:39 +00:00
|
|
|
::testing::Test(),
|
2023-03-26 18:42:52 +00:00
|
|
|
t1(db->getStorage<uint32_t, uint32_t>("table1")),
|
|
|
|
t2(db->getStorage<QString, QString>("table2")),
|
2023-10-15 14:10:27 +00:00
|
|
|
c1(db->getCache<int8_t, std::string>("cache1")),
|
|
|
|
c2(db->getCache<std::string, QVariant>("cache2")) {}
|
2022-09-15 21:34:39 +00:00
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
~BaseTest() {}
|
2022-09-15 21:34:39 +00:00
|
|
|
|
2023-08-15 18:48:19 +00:00
|
|
|
uint32_t getT1Flags() const {return t1->flags();}
|
|
|
|
uint32_t getT2Flags() const {return t2->flags();}
|
|
|
|
uint32_t getC1Flags() const {return c1->flags();}
|
2023-10-15 14:10:27 +00:00
|
|
|
uint32_t getC2Flags() const {return c2->flags();}
|
2023-08-15 18:48:19 +00:00
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
static void SetUpTestSuite() {
|
|
|
|
if (db == nullptr) {
|
2023-03-21 11:05:54 +00:00
|
|
|
db = new LMDBAL::Base("testBase");
|
2023-03-26 18:42:52 +00:00
|
|
|
db->addStorage<uint32_t, uint32_t>("table1");
|
|
|
|
db->addStorage<QString, QString>("table2");
|
2022-09-20 17:16:48 +00:00
|
|
|
db->addCache<int8_t, std::string>("cache1");
|
2023-10-15 14:10:27 +00:00
|
|
|
db->addCache<std::string, QVariant>("cache2");
|
2022-09-15 21:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestSuite() {
|
|
|
|
db->close();
|
|
|
|
db->removeDirectory();
|
|
|
|
delete db;
|
|
|
|
db = nullptr;
|
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
static LMDBAL::Base* db;
|
2022-09-15 21:34:39 +00:00
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
LMDBAL::Storage<uint32_t, uint32_t>* t1;
|
|
|
|
LMDBAL::Storage<QString, QString>* t2;
|
|
|
|
LMDBAL::Cache<int8_t, std::string>* c1;
|
2023-10-15 14:10:27 +00:00
|
|
|
LMDBAL::Cache<std::string, QVariant>* c2;
|
2022-09-15 21:34:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
LMDBAL::Base* BaseTest::db = nullptr;
|
2022-09-15 21:34:39 +00:00
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, RemovingDirectory) {
|
2022-09-15 21:34:39 +00:00
|
|
|
EXPECT_EQ(db->removeDirectory(), true);
|
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, OpeningClosingDatabase) {
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(db->ready(), false);
|
|
|
|
db->open();
|
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
db->close();
|
|
|
|
EXPECT_EQ(db->ready(), false);
|
2022-09-15 21:34:39 +00:00
|
|
|
db->open();
|
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
}
|
|
|
|
|
2023-08-15 18:48:19 +00:00
|
|
|
TEST_F(BaseTest, Flags) {
|
|
|
|
uint32_t t1Flags = getT1Flags();
|
|
|
|
uint32_t t2Flags = getT2Flags();
|
|
|
|
uint32_t c1Flags = getC1Flags();
|
2023-10-15 14:10:27 +00:00
|
|
|
uint32_t c2Flags = getC2Flags();
|
2023-08-15 18:48:19 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(t1Flags & MDB_INTEGERKEY);
|
|
|
|
EXPECT_FALSE(t1Flags & MDB_DUPSORT);
|
|
|
|
EXPECT_FALSE(t1Flags & MDB_DUPFIXED);
|
|
|
|
EXPECT_FALSE(t1Flags & MDB_INTEGERDUP);
|
|
|
|
|
|
|
|
EXPECT_FALSE(t2Flags & MDB_INTEGERKEY);
|
|
|
|
EXPECT_FALSE(t2Flags & MDB_DUPSORT);
|
|
|
|
EXPECT_FALSE(t2Flags & MDB_DUPFIXED);
|
|
|
|
EXPECT_FALSE(t2Flags & MDB_INTEGERDUP);
|
|
|
|
|
|
|
|
EXPECT_TRUE(c1Flags & MDB_INTEGERKEY);
|
|
|
|
EXPECT_FALSE(c1Flags & MDB_DUPSORT);
|
|
|
|
EXPECT_FALSE(c1Flags & MDB_DUPFIXED);
|
|
|
|
EXPECT_FALSE(c1Flags & MDB_INTEGERDUP);
|
2023-10-15 14:10:27 +00:00
|
|
|
|
|
|
|
EXPECT_FALSE(c2Flags & MDB_INTEGERKEY);
|
|
|
|
EXPECT_FALSE(c2Flags & MDB_DUPSORT);
|
|
|
|
EXPECT_FALSE(c2Flags & MDB_DUPFIXED);
|
|
|
|
EXPECT_FALSE(c2Flags & MDB_INTEGERDUP);
|
2023-08-15 18:48:19 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, AddingIntegerKey) {
|
2022-09-15 21:34:39 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
t1->addRecord(1, 2);
|
2022-09-17 12:31:58 +00:00
|
|
|
t1->addRecord(2, 2);
|
|
|
|
t1->addRecord(3, 15);
|
2022-09-15 21:34:39 +00:00
|
|
|
EXPECT_EQ(t1->getRecord(1), 2);
|
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, AddingQStringKey) {
|
2022-09-15 21:34:39 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
t2->addRecord("hello", "world");
|
2022-09-17 12:31:58 +00:00
|
|
|
t2->addRecord("aaa", "gagdfsdf");
|
|
|
|
t2->addRecord("sdfhga", "DSFFDG");
|
|
|
|
t2->addRecord("sdfsda", "shgsdgfa");
|
2022-09-15 21:34:39 +00:00
|
|
|
EXPECT_EQ(t2->getRecord("hello"), "world");
|
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, AddingKeysToCache) {
|
2022-10-09 14:03:30 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
c1->addRecord(2, "blah balah");
|
|
|
|
c1->addRecord(-4, "testing goes brrr");
|
2024-10-06 17:11:44 +00:00
|
|
|
c1->addRecord(40, "whatever");
|
2022-10-09 14:03:30 +00:00
|
|
|
c1->addRecord(-37, "aaaaa tss tsss tsss tsss aaaaaaa");
|
2024-10-06 17:11:44 +00:00
|
|
|
EXPECT_EQ(c1->getRecord(40), "whatever");
|
2022-10-09 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 14:10:27 +00:00
|
|
|
TEST_F(BaseTest, AddingKeysToVariableCache) {
|
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
c2->addRecord("regrets", "blah balah");
|
|
|
|
c2->addRecord("fossil fingers", 842);
|
|
|
|
c2->addRecord("preloaded cut", 539.75);
|
|
|
|
c2->addRecord("dihotomy", false);
|
|
|
|
|
|
|
|
EXPECT_EQ(c2->getRecord("regrets"), "blah balah");
|
|
|
|
EXPECT_EQ(c2->getRecord("fossil fingers"), 842);
|
|
|
|
EXPECT_EQ(c2->getRecord("preloaded cut"), 539.75);
|
|
|
|
EXPECT_EQ(c2->getRecord("dihotomy"), false);
|
|
|
|
}
|
|
|
|
|
2023-04-07 23:27:53 +00:00
|
|
|
TEST_F(BaseTest, AddingRepeatingKey) {
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
2023-04-07 23:27:53 +00:00
|
|
|
|
|
|
|
EXPECT_THROW(t1->addRecord(3, 24), LMDBAL::Exist);
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(t1->getRecord(3), 15);
|
|
|
|
|
2023-04-07 23:27:53 +00:00
|
|
|
EXPECT_THROW(t2->addRecord("sdfhga", "world"), LMDBAL::Exist);
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(t2->getRecord("sdfhga"), "DSFFDG");
|
|
|
|
|
2023-04-07 23:27:53 +00:00
|
|
|
EXPECT_THROW(c1->addRecord(-4, "world"), LMDBAL::Exist);
|
2022-10-09 14:03:30 +00:00
|
|
|
EXPECT_EQ(c1->getRecord(-4), "testing goes brrr");
|
2023-10-15 14:10:27 +00:00
|
|
|
|
|
|
|
EXPECT_THROW(c2->addRecord("dihotomy", "pired"), LMDBAL::Exist);
|
|
|
|
EXPECT_EQ(c2->getRecord("dihotomy"), false);
|
2022-10-09 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, GettingNotExistingKeys) {
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
2022-10-09 14:03:30 +00:00
|
|
|
|
2023-04-07 23:27:53 +00:00
|
|
|
EXPECT_THROW(t2->getRecord("almonds"), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(t1->getRecord(64), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(c1->getRecord(21), LMDBAL::NotFound);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_THROW(c2->getRecord("praising"), LMDBAL::NotFound);
|
2022-09-17 12:31:58 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, Persistence) {
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
2023-08-13 16:30:17 +00:00
|
|
|
uint32_t t1Size = t1->count();
|
|
|
|
uint32_t t2Size = t2->count();
|
|
|
|
uint32_t c1Size = c1->count();
|
2023-10-15 14:10:27 +00:00
|
|
|
uint32_t c2Size = c2->count();
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
db->close();
|
2022-09-17 12:31:58 +00:00
|
|
|
delete db;
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
db = new LMDBAL::Base("testBase");
|
2023-03-26 18:42:52 +00:00
|
|
|
t1 = db->addStorage<uint32_t, uint32_t>("table1");
|
|
|
|
t2 = db->addStorage<QString, QString>("table2");
|
2022-09-20 17:16:48 +00:00
|
|
|
c1 = db->addCache<int8_t, std::string>("cache1");
|
2023-10-15 14:10:27 +00:00
|
|
|
c2 = db->addCache<std::string, QVariant>("cache2");
|
2022-09-17 12:31:58 +00:00
|
|
|
db->open();
|
|
|
|
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(t1->count(), t1Size);
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(t1->getRecord(3), 15);
|
|
|
|
EXPECT_EQ(t1->getRecord(1), 2);
|
|
|
|
EXPECT_EQ(t1->getRecord(2), 2);
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(t1->count(), t1Size);
|
|
|
|
|
2022-10-09 14:03:30 +00:00
|
|
|
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(t2->count(), t2Size);
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(t2->getRecord("hello"), "world");
|
|
|
|
EXPECT_EQ(t2->getRecord("aaa"), "gagdfsdf");
|
|
|
|
EXPECT_EQ(t2->getRecord("sdfhga"), "DSFFDG");
|
|
|
|
EXPECT_EQ(t2->getRecord("sdfsda"), "shgsdgfa");
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(t2->count(), t2Size);
|
2022-09-17 12:31:58 +00:00
|
|
|
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(c1->count(), c1Size);
|
2024-10-06 17:11:44 +00:00
|
|
|
EXPECT_EQ(c1->checkRecord(40), true);
|
|
|
|
EXPECT_EQ(c1->getRecord(40), "whatever");
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(c1->checkRecord(-4), true);
|
2022-10-09 14:03:30 +00:00
|
|
|
EXPECT_EQ(c1->getRecord(-4), "testing goes brrr");
|
|
|
|
EXPECT_EQ(c1->getRecord(-4), "testing goes brrr");
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(c1->checkRecord(-4), true);
|
|
|
|
EXPECT_EQ(c1->count(), c1Size);
|
2022-10-09 14:03:30 +00:00
|
|
|
EXPECT_EQ(c1->getRecord(-37), "aaaaa tss tsss tsss tsss aaaaaaa");
|
|
|
|
EXPECT_EQ(c1->getRecord(2), "blah balah");
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(c1->count(), c1Size);
|
2022-10-09 14:03:30 +00:00
|
|
|
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->count(), c2Size);
|
|
|
|
EXPECT_EQ(c2->getRecord("regrets"), "blah balah");
|
|
|
|
EXPECT_EQ(c2->getRecord("fossil fingers"), 842);
|
|
|
|
EXPECT_EQ(c2->getRecord("preloaded cut"), 539.75);
|
|
|
|
EXPECT_EQ(c2->getRecord("dihotomy"), false);
|
|
|
|
|
2023-04-07 23:27:53 +00:00
|
|
|
EXPECT_THROW(t2->getRecord("cats"), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(t1->getRecord(7893), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(c1->getRecord(89), LMDBAL::NotFound);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_THROW(c2->getRecord("marathons"), LMDBAL::NotFound);
|
2022-09-15 21:34:39 +00:00
|
|
|
}
|
2022-09-17 12:31:58 +00:00
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, CountAndDrop) {
|
2022-09-17 12:31:58 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
EXPECT_EQ(t1->count(), 3);
|
|
|
|
EXPECT_EQ(t2->count(), 4);
|
2022-10-09 14:03:30 +00:00
|
|
|
EXPECT_EQ(c1->count(), 4);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->count(), 4);
|
2022-09-17 12:31:58 +00:00
|
|
|
db->drop();
|
|
|
|
|
|
|
|
EXPECT_EQ(t1->count(), 0);
|
|
|
|
EXPECT_EQ(t2->count(), 0);
|
2022-10-09 14:03:30 +00:00
|
|
|
EXPECT_EQ(c1->count(), 0);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->count(), 0);
|
2022-09-17 12:31:58 +00:00
|
|
|
|
|
|
|
t1->addRecord(2, 2);
|
|
|
|
t2->addRecord("sdfhga", "world");
|
2022-10-09 14:03:30 +00:00
|
|
|
c1->addRecord(15, "world");
|
|
|
|
c1->addRecord(12, "grr grr");
|
2023-10-15 14:10:27 +00:00
|
|
|
c2->addRecord("blues", -749);
|
2022-09-17 12:31:58 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(t1->count(), 1);
|
|
|
|
EXPECT_EQ(t2->count(), 1);
|
2022-10-09 14:03:30 +00:00
|
|
|
EXPECT_EQ(c1->count(), 2);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->count(), 1);
|
2022-09-17 12:31:58 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, Change) {
|
2023-03-09 19:50:53 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
EXPECT_EQ(t1->count(), 1);
|
|
|
|
EXPECT_EQ(t2->count(), 1);
|
|
|
|
EXPECT_EQ(c1->count(), 2);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->count(), 1);
|
2023-03-09 19:50:53 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(t1->getRecord(2), 2);
|
|
|
|
EXPECT_EQ(t2->getRecord("sdfhga"), "world");
|
|
|
|
EXPECT_EQ(c1->getRecord(15), "world");
|
|
|
|
EXPECT_EQ(c1->getRecord(12), "grr grr");
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->getRecord("blues"), -749);
|
2023-03-09 19:50:53 +00:00
|
|
|
|
|
|
|
t1->addRecord(58, 39);
|
|
|
|
t2->addRecord("lawfirm", "stumble");
|
|
|
|
c1->addRecord(89, "answer");
|
2023-10-15 14:10:27 +00:00
|
|
|
c2->addRecord("wielders", QStringList({"calcium", "eagles"}));
|
2023-03-09 19:50:53 +00:00
|
|
|
|
|
|
|
t1->changeRecord(2, 49);
|
|
|
|
t2->changeRecord("sdfhga", "void");
|
|
|
|
c1->changeRecord(15, "recording");
|
|
|
|
c1->changeRecord(12, "thermal");
|
2023-10-15 14:10:27 +00:00
|
|
|
c2->changeRecord("blues", true);
|
2023-03-09 19:50:53 +00:00
|
|
|
|
2023-04-07 23:27:53 +00:00
|
|
|
EXPECT_THROW(t1->changeRecord(37, 49), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(t2->changeRecord("precision", "cryoplastics"), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(c1->changeRecord(-62, "sharks"), LMDBAL::NotFound);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_THROW(c2->changeRecord("visions", 90), LMDBAL::NotFound);
|
2023-04-07 23:27:53 +00:00
|
|
|
|
2023-03-09 19:50:53 +00:00
|
|
|
EXPECT_EQ(t1->getRecord(2), 49);
|
|
|
|
EXPECT_EQ(t2->getRecord("sdfhga"), "void");
|
|
|
|
EXPECT_EQ(c1->getRecord(15), "recording");
|
|
|
|
EXPECT_EQ(c1->getRecord(12), "thermal");
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->getRecord("blues"), true);
|
2023-03-09 19:50:53 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(t1->getRecord(58), 39);
|
|
|
|
EXPECT_EQ(t2->getRecord("lawfirm"), "stumble");
|
|
|
|
EXPECT_EQ(c1->getRecord(89), "answer");
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->getRecord("wielders"), QStringList({"calcium", "eagles"}));
|
2023-03-09 19:50:53 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(t1->count(), 2);
|
|
|
|
EXPECT_EQ(t2->count(), 2);
|
|
|
|
EXPECT_EQ(c1->count(), 3);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->count(), 2);
|
2023-03-09 19:50:53 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 11:05:54 +00:00
|
|
|
TEST_F(BaseTest, Force) {
|
2023-03-09 19:50:53 +00:00
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
|
2023-04-01 14:45:20 +00:00
|
|
|
EXPECT_EQ(t1->forceRecord(58, 35), false); //changing
|
|
|
|
EXPECT_EQ(t1->forceRecord(68, 36), true); //adding
|
|
|
|
EXPECT_EQ(t2->forceRecord("prophecy", "dumpling"), true); //adding
|
|
|
|
EXPECT_EQ(t2->forceRecord("lawfirm", "paracetamol"), false); //changing
|
|
|
|
EXPECT_EQ(c1->forceRecord(89, "canine"), false); //changing
|
|
|
|
EXPECT_EQ(c1->forceRecord(98, "duration"), true); //adding
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->forceRecord("wielders", "charm"), false); //changing
|
|
|
|
EXPECT_EQ(c2->forceRecord("tedious", 5732.89), true); //adding
|
2023-03-09 19:50:53 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(t1->getRecord(2), 49);
|
|
|
|
EXPECT_EQ(t1->getRecord(58), 35);
|
|
|
|
EXPECT_EQ(t1->getRecord(68), 36);
|
2023-10-15 14:10:27 +00:00
|
|
|
|
2023-03-09 19:50:53 +00:00
|
|
|
EXPECT_EQ(t2->getRecord("sdfhga"), "void");
|
|
|
|
EXPECT_EQ(t2->getRecord("prophecy"), "dumpling");
|
|
|
|
EXPECT_EQ(t2->getRecord("lawfirm"), "paracetamol");
|
2023-10-15 14:10:27 +00:00
|
|
|
|
2023-03-09 19:50:53 +00:00
|
|
|
EXPECT_EQ(c1->getRecord(15), "recording");
|
|
|
|
EXPECT_EQ(c1->getRecord(12), "thermal");
|
|
|
|
EXPECT_EQ(c1->getRecord(89), "canine");
|
|
|
|
EXPECT_EQ(c1->getRecord(98), "duration");
|
|
|
|
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->getRecord("blues"), true);
|
|
|
|
EXPECT_EQ(c2->getRecord("tedious"), 5732.89);
|
|
|
|
EXPECT_EQ(c2->getRecord("wielders"), "charm");
|
|
|
|
|
2023-03-09 19:50:53 +00:00
|
|
|
EXPECT_EQ(t1->count(), 3);
|
|
|
|
EXPECT_EQ(t2->count(), 3);
|
|
|
|
EXPECT_EQ(c1->count(), 4);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->count(), 3);
|
2023-03-09 19:50:53 +00:00
|
|
|
}
|
2023-04-01 14:45:20 +00:00
|
|
|
|
|
|
|
TEST_F(BaseTest, ReadAll) {
|
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
|
|
|
|
std::map<uint32_t, uint32_t> m1 = t1->readAll();
|
|
|
|
std::map<QString, QString> m2 = t2->readAll();
|
|
|
|
std::map<int8_t, std::string> m3 = c1->readAll();
|
2023-10-15 14:10:27 +00:00
|
|
|
std::map<std::string, QVariant> m4 = c2->readAll();
|
2023-04-01 14:45:20 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(m1.at(2), 49);
|
|
|
|
EXPECT_EQ(m1.at(58), 35);
|
|
|
|
EXPECT_EQ(m1.at(68), 36);
|
2023-10-15 14:10:27 +00:00
|
|
|
|
2023-04-01 14:45:20 +00:00
|
|
|
EXPECT_EQ(m2.at("sdfhga"), "void");
|
|
|
|
EXPECT_EQ(m2.at("prophecy"), "dumpling");
|
|
|
|
EXPECT_EQ(m2.at("lawfirm"), "paracetamol");
|
2023-10-15 14:10:27 +00:00
|
|
|
|
2023-04-01 14:45:20 +00:00
|
|
|
EXPECT_EQ(m3.at(15), "recording");
|
|
|
|
EXPECT_EQ(m3.at(12), "thermal");
|
|
|
|
EXPECT_EQ(m3.at(89), "canine");
|
|
|
|
EXPECT_EQ(m3.at(98), "duration");
|
|
|
|
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(m4.at("blues"), true);
|
|
|
|
EXPECT_EQ(m4.at("tedious"), 5732.89);
|
|
|
|
EXPECT_EQ(m4.at("wielders"), "charm");
|
|
|
|
|
2023-04-01 14:45:20 +00:00
|
|
|
EXPECT_EQ(m1.size(), 3);
|
|
|
|
EXPECT_EQ(m2.size(), 3);
|
|
|
|
EXPECT_EQ(m3.size(), 4);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(m4.size(), 3);
|
2023-04-01 14:45:20 +00:00
|
|
|
}
|
2023-04-06 23:51:45 +00:00
|
|
|
|
|
|
|
TEST_F(BaseTest, ReplaceAll) {
|
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
|
|
|
|
t1->replaceAll({
|
|
|
|
{7, 48},
|
|
|
|
{194, 582},
|
|
|
|
{857, 39},
|
|
|
|
{9717, 8}
|
|
|
|
});
|
|
|
|
t2->replaceAll({
|
|
|
|
{"bringin", "keyboard"},
|
|
|
|
{"cluster", "throttle"},
|
|
|
|
{"ronin", "cheese"}
|
|
|
|
});
|
|
|
|
c1->replaceAll({});
|
2023-10-15 14:10:27 +00:00
|
|
|
c2->replaceAll({
|
|
|
|
{"kind", 73}
|
|
|
|
});
|
2023-04-06 23:51:45 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(t1->count(), 4);
|
|
|
|
EXPECT_EQ(t2->count(), 3);
|
|
|
|
EXPECT_EQ(c1->count(), 0);
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->count(), 1);
|
2023-04-06 23:51:45 +00:00
|
|
|
|
|
|
|
EXPECT_FALSE(t1->checkRecord(2));
|
|
|
|
EXPECT_FALSE(t1->checkRecord(58));
|
|
|
|
EXPECT_FALSE(t1->checkRecord(68));
|
|
|
|
|
|
|
|
EXPECT_FALSE(t2->checkRecord("sdfhga"));
|
|
|
|
EXPECT_FALSE(t2->checkRecord("prophecy"));
|
|
|
|
EXPECT_FALSE(t2->checkRecord("lawfirm"));
|
|
|
|
|
|
|
|
EXPECT_FALSE(c1->checkRecord(15));
|
|
|
|
EXPECT_FALSE(c1->checkRecord(12));
|
|
|
|
EXPECT_FALSE(c1->checkRecord(89));
|
|
|
|
EXPECT_FALSE(c1->checkRecord(98));
|
|
|
|
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_FALSE(c2->checkRecord("blues"));
|
|
|
|
EXPECT_FALSE(c2->checkRecord("tedious"));
|
|
|
|
EXPECT_FALSE(c2->checkRecord("wielders"));
|
|
|
|
|
2023-04-06 23:51:45 +00:00
|
|
|
EXPECT_EQ(t1->getRecord(7), 48);
|
|
|
|
EXPECT_EQ(t1->getRecord(194), 582);
|
|
|
|
EXPECT_EQ(t1->getRecord(857), 39);
|
|
|
|
EXPECT_EQ(t1->getRecord(9717), 8);
|
|
|
|
|
|
|
|
EXPECT_EQ(t2->getRecord("bringin"), "keyboard");
|
|
|
|
EXPECT_EQ(t2->getRecord("cluster"), "throttle");
|
|
|
|
EXPECT_EQ(t2->getRecord("ronin"), "cheese");
|
|
|
|
|
2023-10-15 14:10:27 +00:00
|
|
|
EXPECT_EQ(c2->getRecord("kind"), 73);
|
|
|
|
|
2023-04-06 23:51:45 +00:00
|
|
|
c1->replaceAll({
|
|
|
|
{68, "quality"},
|
|
|
|
{31, "ridgid body"},
|
|
|
|
{16, "fermentation on your kind"},
|
|
|
|
{22, "pseudo"},
|
|
|
|
{-117, "lance of Michael"},
|
|
|
|
});
|
|
|
|
EXPECT_EQ(c1->count(), 5);
|
|
|
|
|
|
|
|
EXPECT_EQ(c1->getRecord(68), "quality");
|
|
|
|
EXPECT_EQ(c1->getRecord(31), "ridgid body");
|
|
|
|
EXPECT_EQ(c1->getRecord(16), "fermentation on your kind");
|
|
|
|
EXPECT_EQ(c1->getRecord(22), "pseudo");
|
|
|
|
EXPECT_EQ(c1->getRecord(-117), "lance of Michael");
|
|
|
|
}
|
2023-04-07 23:27:53 +00:00
|
|
|
|
|
|
|
TEST_F(BaseTest, AddRecords) {
|
|
|
|
EXPECT_EQ(db->ready(), true);
|
|
|
|
|
|
|
|
LMDBAL::SizeType s1 = t1->addRecords({
|
|
|
|
{5, 3},
|
|
|
|
{800, 9}
|
|
|
|
});
|
|
|
|
EXPECT_EQ(s1, 6);
|
|
|
|
EXPECT_EQ(t1->getRecord(7), 48);
|
|
|
|
EXPECT_EQ(t1->getRecord(194), 582);
|
|
|
|
EXPECT_EQ(t1->getRecord(857), 39);
|
|
|
|
EXPECT_EQ(t1->getRecord(9717), 8);
|
|
|
|
EXPECT_EQ(t1->getRecord(5), 3);
|
|
|
|
EXPECT_EQ(t1->getRecord(800), 9);
|
|
|
|
s1 = t1->addRecords({
|
|
|
|
{194, 371},
|
|
|
|
{808, 487},
|
|
|
|
{807, 0}
|
|
|
|
}, true);
|
|
|
|
EXPECT_EQ(s1, 8);
|
|
|
|
EXPECT_EQ(t1->count(), 8);
|
|
|
|
EXPECT_EQ(t1->getRecord(7), 48);
|
|
|
|
EXPECT_EQ(t1->getRecord(194), 371);
|
|
|
|
EXPECT_EQ(t1->getRecord(857), 39);
|
|
|
|
EXPECT_EQ(t1->getRecord(9717), 8);
|
|
|
|
EXPECT_EQ(t1->getRecord(5), 3);
|
|
|
|
EXPECT_EQ(t1->getRecord(800), 9);
|
|
|
|
EXPECT_EQ(t1->getRecord(808), 487);
|
|
|
|
EXPECT_EQ(t1->getRecord(807), 0);
|
|
|
|
EXPECT_THROW(
|
|
|
|
s1 = t1->addRecords({
|
|
|
|
{194, 371},
|
|
|
|
{808, 487},
|
|
|
|
{807, 0}
|
|
|
|
}), LMDBAL::Exist
|
|
|
|
);
|
|
|
|
EXPECT_EQ(t1->count(), 8);
|
|
|
|
|
|
|
|
LMDBAL::SizeType s2 = t2->addRecords({
|
|
|
|
{"lama", "not quite"},
|
|
|
|
{"by the shadow", "leech"},
|
|
|
|
{"summertime", "curses"}
|
|
|
|
});
|
|
|
|
EXPECT_EQ(s2, 6);
|
|
|
|
EXPECT_EQ(t2->count(), 6);
|
|
|
|
EXPECT_EQ(t2->getRecord("bringin"), "keyboard");
|
|
|
|
EXPECT_EQ(t2->getRecord("cluster"), "throttle");
|
|
|
|
EXPECT_EQ(t2->getRecord("ronin"), "cheese");
|
|
|
|
EXPECT_EQ(t2->getRecord("lama"), "not quite");
|
|
|
|
EXPECT_EQ(t2->getRecord("by the shadow"), "leech");
|
|
|
|
EXPECT_EQ(t2->getRecord("summertime"), "curses");
|
|
|
|
s2 = t2->addRecords({
|
|
|
|
{"worry not", "for shall you"},
|
|
|
|
{"by the shadow", "face the inevitable"},
|
|
|
|
{"cluster", "sobing over those"}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
EXPECT_EQ(s2, 7);
|
|
|
|
EXPECT_EQ(t2->count(), 7);
|
|
|
|
EXPECT_EQ(t2->getRecord("bringin"), "keyboard");
|
|
|
|
EXPECT_EQ(t2->getRecord("cluster"), "sobing over those");
|
|
|
|
EXPECT_EQ(t2->getRecord("ronin"), "cheese");
|
|
|
|
EXPECT_EQ(t2->getRecord("lama"), "not quite");
|
|
|
|
EXPECT_EQ(t2->getRecord("by the shadow"), "face the inevitable");
|
|
|
|
EXPECT_EQ(t2->getRecord("summertime"), "curses");
|
|
|
|
EXPECT_EQ(t2->getRecord("worry not"), "for shall you");
|
|
|
|
|
|
|
|
EXPECT_THROW(
|
|
|
|
s2 = t2->addRecords({
|
|
|
|
{"within reasonable limits", "occasion"},
|
|
|
|
{"ronin", "crest of violence"},
|
|
|
|
{"permanent", "of your kind"}
|
|
|
|
}), LMDBAL::Exist
|
|
|
|
);
|
|
|
|
EXPECT_EQ(t2->count(), 7);
|
|
|
|
|
|
|
|
LMDBAL::SizeType s3 = c1->addRecords({
|
|
|
|
{19, "menace"},
|
|
|
|
{-7, "failure driven sorrow"},
|
|
|
|
{82, "lungache"},
|
|
|
|
{4, "drowsy"},
|
|
|
|
{44, "pressure"},
|
|
|
|
});
|
|
|
|
|
|
|
|
EXPECT_EQ(c1->count(), 10);
|
|
|
|
EXPECT_EQ(s3, 10);
|
|
|
|
|
|
|
|
EXPECT_EQ(c1->getRecord(68), "quality");
|
|
|
|
EXPECT_EQ(c1->getRecord(31), "ridgid body");
|
|
|
|
EXPECT_EQ(c1->getRecord(16), "fermentation on your kind");
|
|
|
|
EXPECT_EQ(c1->getRecord(22), "pseudo");
|
|
|
|
EXPECT_EQ(c1->getRecord(-117), "lance of Michael");
|
|
|
|
EXPECT_EQ(c1->getRecord(19), "menace");
|
|
|
|
EXPECT_EQ(c1->getRecord(-7), "failure driven sorrow");
|
|
|
|
EXPECT_EQ(c1->getRecord(82), "lungache");
|
|
|
|
EXPECT_EQ(c1->getRecord(4), "drowsy");
|
|
|
|
EXPECT_EQ(c1->getRecord(44), "pressure");
|
|
|
|
|
|
|
|
EXPECT_THROW(
|
|
|
|
s3 = c1->addRecords({
|
|
|
|
{-72, "amber"},
|
|
|
|
{-9, "going swinging of paleopathy"},
|
|
|
|
{82, "regret"}
|
|
|
|
}), LMDBAL::Exist
|
|
|
|
);
|
|
|
|
EXPECT_EQ(c1->count(), 10);
|
|
|
|
|
|
|
|
s3 = c1->addRecords({
|
|
|
|
{19, "to replicated being"},
|
|
|
|
{123, "horibly unforseen"},
|
|
|
|
{-32, "stitched"},
|
|
|
|
{31, "overall"}
|
|
|
|
}, true);
|
|
|
|
EXPECT_EQ(c1->count(), 12);
|
|
|
|
EXPECT_EQ(s3, 12);
|
|
|
|
EXPECT_EQ(c1->getRecord(68), "quality");
|
|
|
|
EXPECT_EQ(c1->getRecord(31), "overall");
|
|
|
|
EXPECT_EQ(c1->getRecord(16), "fermentation on your kind");
|
|
|
|
EXPECT_EQ(c1->getRecord(22), "pseudo");
|
|
|
|
EXPECT_EQ(c1->getRecord(-117), "lance of Michael");
|
|
|
|
EXPECT_EQ(c1->getRecord(19), "to replicated being");
|
|
|
|
EXPECT_EQ(c1->getRecord(-7), "failure driven sorrow");
|
|
|
|
EXPECT_EQ(c1->getRecord(82), "lungache");
|
|
|
|
EXPECT_EQ(c1->getRecord(4), "drowsy");
|
|
|
|
EXPECT_EQ(c1->getRecord(44), "pressure");
|
|
|
|
EXPECT_EQ(c1->getRecord(-32), "stitched");
|
|
|
|
EXPECT_EQ(c1->getRecord(123), "horibly unforseen");
|
|
|
|
|
2023-10-15 14:10:27 +00:00
|
|
|
LMDBAL::SizeType s4 = c2->addRecords({
|
|
|
|
{"and wholesome", "preaching"},
|
|
|
|
{"ginger", false}
|
|
|
|
});
|
|
|
|
|
|
|
|
EXPECT_EQ(c2->count(), 3);
|
|
|
|
EXPECT_EQ(s4, 3);
|
|
|
|
|
|
|
|
EXPECT_THROW(
|
|
|
|
s4 = c2->addRecords({
|
|
|
|
{"returning favor", 'c'},
|
|
|
|
{"ginger", 23},
|
|
|
|
{"frames", true}
|
|
|
|
}), LMDBAL::Exist
|
|
|
|
);
|
|
|
|
EXPECT_EQ(c2->count(), 3);
|
|
|
|
|
|
|
|
s4 = c2->addRecords({
|
|
|
|
{"and wholesome", -1},
|
|
|
|
{"orcid", 89.9}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
EXPECT_EQ(c2->count(), 4);
|
|
|
|
EXPECT_EQ(s4, 4);
|
|
|
|
|
|
|
|
EXPECT_EQ(c2->getRecord("and wholesome"), -1);
|
|
|
|
EXPECT_EQ(c2->getRecord("orcid"), 89.9);
|
|
|
|
EXPECT_EQ(c2->getRecord("ginger"), false);
|
|
|
|
EXPECT_EQ(c2->getRecord("kind"), 73);
|
2023-04-07 23:27:53 +00:00
|
|
|
}
|