2023-08-17 14:45:11 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "base.h"
|
|
|
|
#include "storage.h"
|
|
|
|
|
|
|
|
class DuplicatesTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
DuplicatesTest():
|
|
|
|
::testing::Test(),
|
2023-08-18 13:31:30 +00:00
|
|
|
tu1(db->getStorage<int16_t, uint16_t>("sameSizeInts")),
|
|
|
|
tu2(db->getStorage<std::string, int8_t>("stringInt")),
|
|
|
|
tu3(db->getStorage<float, float>("floatFloat")),
|
|
|
|
tu4(db->getStorage<uint16_t, double>("intDouble")) {}
|
2023-08-17 14:45:11 +00:00
|
|
|
|
|
|
|
~DuplicatesTest() {}
|
|
|
|
|
2023-08-18 13:31:30 +00:00
|
|
|
uint32_t getTU1Flags() const {return tu1->flags();}
|
|
|
|
uint32_t getTU2Flags() const {return tu2->flags();}
|
|
|
|
uint32_t getTU3Flags() const {return tu3->flags();}
|
|
|
|
uint32_t getTU4Flags() const {return tu4->flags();}
|
2023-08-17 14:45:11 +00:00
|
|
|
|
|
|
|
static void SetUpTestSuite() {
|
|
|
|
if (db == nullptr) {
|
|
|
|
db = new LMDBAL::Base("testBase");
|
2023-08-18 13:31:30 +00:00
|
|
|
db->addStorage<int16_t, uint16_t>("sameSizeInts", true);
|
|
|
|
db->addStorage<std::string, int8_t>("stringInt", true);
|
|
|
|
db->addStorage<float, float>("floatFloat", true);
|
|
|
|
db->addStorage<uint16_t, double>("intDouble", true);
|
2023-08-17 14:45:11 +00:00
|
|
|
|
|
|
|
db->open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestSuite() {
|
|
|
|
db->close();
|
|
|
|
db->removeDirectory();
|
|
|
|
delete db;
|
|
|
|
db = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LMDBAL::Base* db;
|
|
|
|
|
2023-08-18 13:31:30 +00:00
|
|
|
LMDBAL::Storage<int16_t, uint16_t>* tu1;
|
|
|
|
LMDBAL::Storage<std::string, int8_t>* tu2;
|
|
|
|
LMDBAL::Storage<float, float>* tu3;
|
|
|
|
LMDBAL::Storage<uint16_t, double>* tu4;
|
2023-08-17 14:45:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LMDBAL::Base* DuplicatesTest::db = nullptr;
|
|
|
|
|
2023-08-18 13:31:30 +00:00
|
|
|
TEST_F(DuplicatesTest, FlagsUnique) {
|
|
|
|
uint32_t tu1Flags = getTU1Flags();
|
|
|
|
uint32_t tu2Flags = getTU2Flags();
|
|
|
|
uint32_t tu3Flags = getTU3Flags();
|
|
|
|
uint32_t tu4Flags = getTU4Flags();
|
|
|
|
|
|
|
|
EXPECT_TRUE(tu1Flags & MDB_INTEGERKEY);
|
|
|
|
EXPECT_TRUE(tu1Flags & MDB_DUPSORT);
|
|
|
|
EXPECT_TRUE(tu1Flags & MDB_DUPFIXED);
|
|
|
|
EXPECT_FALSE(tu1Flags & MDB_INTEGERDUP);
|
|
|
|
|
|
|
|
EXPECT_FALSE(tu2Flags & MDB_INTEGERKEY);
|
|
|
|
EXPECT_TRUE(tu2Flags & MDB_DUPSORT);
|
|
|
|
EXPECT_FALSE(tu2Flags & MDB_DUPFIXED);
|
|
|
|
EXPECT_TRUE(tu2Flags & MDB_INTEGERDUP);
|
|
|
|
|
|
|
|
EXPECT_FALSE(tu3Flags & MDB_INTEGERKEY);
|
|
|
|
EXPECT_TRUE(tu3Flags & MDB_DUPSORT);
|
|
|
|
EXPECT_TRUE(tu3Flags & MDB_DUPFIXED);
|
|
|
|
EXPECT_FALSE(tu3Flags & MDB_INTEGERDUP);
|
|
|
|
|
|
|
|
EXPECT_TRUE(tu4Flags & MDB_INTEGERKEY);
|
|
|
|
EXPECT_TRUE(tu4Flags & MDB_DUPSORT);
|
|
|
|
EXPECT_TRUE(tu4Flags & MDB_DUPFIXED);
|
|
|
|
EXPECT_FALSE(tu4Flags & MDB_INTEGERDUP);
|
2023-08-17 14:45:11 +00:00
|
|
|
}
|
|
|
|
|
2023-08-18 13:31:30 +00:00
|
|
|
TEST_F(DuplicatesTest, AddingPairUnique) {
|
|
|
|
tu1->addRecord(1, 1);
|
|
|
|
tu1->addRecord(2, 2);
|
|
|
|
tu1->addRecord(2, 1);
|
|
|
|
tu1->addRecord(1, 2);
|
|
|
|
EXPECT_THROW(tu1->addRecord(1, 1), LMDBAL::Exist);
|
|
|
|
EXPECT_THROW(tu1->addRecord(1, 2), LMDBAL::Exist);
|
|
|
|
EXPECT_THROW(tu1->addRecord(2, 2), LMDBAL::Exist);
|
|
|
|
|
|
|
|
EXPECT_EQ(tu1->count(), 4);
|
|
|
|
EXPECT_EQ(tu1->getRecord(1), 1);
|
|
|
|
EXPECT_EQ(tu1->getRecord(2), 1);
|
|
|
|
|
|
|
|
tu2->addRecord("brass boulers", -54);
|
|
|
|
tu2->addRecord("grief ", 61);
|
|
|
|
tu2->addRecord("grief ", 19);
|
|
|
|
tu2->addRecord("grief ", 32);
|
|
|
|
tu2->addRecord("miracles of a lunch", 44);
|
|
|
|
tu2->addRecord("miracles of a lunch", 102);
|
|
|
|
tu2->addRecord("miracles of a lunch", -72);
|
|
|
|
|
|
|
|
EXPECT_THROW(tu2->addRecord("grief ", 19), LMDBAL::Exist);
|
|
|
|
EXPECT_THROW(tu2->addRecord("brass boulers", -54), LMDBAL::Exist);
|
|
|
|
EXPECT_EQ(tu2->count(), 7);
|
|
|
|
EXPECT_EQ(tu2->getRecord("grief "), 19);
|
|
|
|
EXPECT_EQ(tu2->getRecord("miracles of a lunch"), 44); //apparently ints are compared as uints
|
|
|
|
|
|
|
|
tu3->addRecord(7.2, 697);
|
|
|
|
tu3->addRecord(5119, -998.53);
|
|
|
|
tu3->addRecord(7.2001, 4);
|
|
|
|
tu3->addRecord(7.2, -113);
|
|
|
|
tu3->addRecord(7.2, -53.5478);
|
|
|
|
float tu3ds = 0.432924;
|
|
|
|
tu3->addRecord(5119, tu3ds);
|
|
|
|
|
|
|
|
EXPECT_THROW(tu3->addRecord(5119, -998.53), LMDBAL::Exist);
|
|
|
|
EXPECT_THROW(tu3->addRecord(7.2001, 4), LMDBAL::Exist);
|
|
|
|
tu3->addRecord(7.20001, 4.00000001); //not sure how exactly, but it works
|
|
|
|
|
|
|
|
EXPECT_EQ(tu3->count(), 7);
|
|
|
|
EXPECT_EQ(tu3->getRecord(7.2), -113);
|
|
|
|
float tu3dd = tu3->getRecord(5119);
|
|
|
|
EXPECT_TRUE(tu3ds == tu3dd);
|
|
|
|
EXPECT_EQ(tu3ds, tu3dd);
|
|
|
|
|
|
|
|
tu4->addRecord(327, 463.28348);
|
|
|
|
tu4->addRecord(327, 79.624923);
|
|
|
|
tu4->addRecord(172, 0.00001);
|
|
|
|
tu4->addRecord(172, 0.00000001);
|
|
|
|
EXPECT_THROW(tu4->addRecord(172, 0.00000001), LMDBAL::Exist);
|
|
|
|
EXPECT_THROW(tu4->addRecord(172, 0.00001), LMDBAL::Exist);
|
|
|
|
EXPECT_THROW(tu4->addRecord(327, 79.624923), LMDBAL::Exist);
|
|
|
|
|
|
|
|
EXPECT_EQ(tu4->count(), 4);
|
|
|
|
EXPECT_EQ(tu4->getRecord(172), 0.00000001);
|
|
|
|
EXPECT_EQ(tu4->getRecord(327), 463.28348); //since they are not int's they are compared sort of lexicographically
|
2023-08-17 14:45:11 +00:00
|
|
|
}
|