91 lines
2.7 KiB
C++
91 lines
2.7 KiB
C++
|
#include <gtest/gtest.h>
|
||
|
|
||
|
#include "base.h"
|
||
|
#include "storage.h"
|
||
|
|
||
|
class DuplicatesTest : public ::testing::Test {
|
||
|
protected:
|
||
|
DuplicatesTest():
|
||
|
::testing::Test(),
|
||
|
t1(db->getStorage<int16_t, uint16_t>("sameSizeInts")),
|
||
|
t2(db->getStorage<std::string, int8_t>("stringInt")),
|
||
|
t3(db->getStorage<int64_t, int8_t>("differentSizeInts")),
|
||
|
t4(db->getStorage<uint16_t, double>("intDouble")) {}
|
||
|
|
||
|
~DuplicatesTest() {}
|
||
|
|
||
|
uint32_t getT1Flags() const {return t1->flags();}
|
||
|
uint32_t getT2Flags() const {return t2->flags();}
|
||
|
uint32_t getT3Flags() const {return t3->flags();}
|
||
|
uint32_t getT4Flags() const {return t4->flags();}
|
||
|
|
||
|
static void SetUpTestSuite() {
|
||
|
if (db == nullptr) {
|
||
|
db = new LMDBAL::Base("testBase");
|
||
|
db->addStorage<int16_t, uint16_t>("sameSizeInts", LMDBAL::uniquePair);
|
||
|
db->addStorage<std::string, int8_t>("stringInt", LMDBAL::uniquePair);
|
||
|
db->addStorage<int64_t, int8_t>("differentSizeInts", LMDBAL::uniquePair);
|
||
|
db->addStorage<uint16_t, double>("intDouble", LMDBAL::uniquePair);
|
||
|
|
||
|
db->open();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void TearDownTestSuite() {
|
||
|
db->close();
|
||
|
db->removeDirectory();
|
||
|
delete db;
|
||
|
db = nullptr;
|
||
|
}
|
||
|
|
||
|
static LMDBAL::Base* db;
|
||
|
|
||
|
LMDBAL::Storage<int16_t, uint16_t>* t1;
|
||
|
LMDBAL::Storage<std::string, int8_t>* t2;
|
||
|
LMDBAL::Storage<int64_t, int8_t>* t3;
|
||
|
LMDBAL::Storage<uint16_t, double>* t4;
|
||
|
};
|
||
|
|
||
|
LMDBAL::Base* DuplicatesTest::db = nullptr;
|
||
|
|
||
|
TEST_F(DuplicatesTest, Flags) {
|
||
|
uint32_t t1Flags = getT1Flags();
|
||
|
uint32_t t2Flags = getT2Flags();
|
||
|
uint32_t t3Flags = getT3Flags();
|
||
|
uint32_t t4Flags = getT4Flags();
|
||
|
|
||
|
EXPECT_TRUE(t1Flags & MDB_INTEGERKEY);
|
||
|
EXPECT_TRUE(t1Flags & MDB_DUPSORT);
|
||
|
EXPECT_TRUE(t1Flags & MDB_DUPFIXED);
|
||
|
EXPECT_FALSE(t1Flags & MDB_INTEGERDUP);
|
||
|
|
||
|
EXPECT_FALSE(t2Flags & MDB_INTEGERKEY);
|
||
|
EXPECT_TRUE(t2Flags & MDB_DUPSORT);
|
||
|
EXPECT_FALSE(t2Flags & MDB_DUPFIXED);
|
||
|
EXPECT_TRUE(t2Flags & MDB_INTEGERDUP);
|
||
|
|
||
|
EXPECT_TRUE(t3Flags & MDB_INTEGERKEY);
|
||
|
EXPECT_TRUE(t3Flags & MDB_DUPSORT);
|
||
|
EXPECT_TRUE(t3Flags & MDB_DUPFIXED);
|
||
|
EXPECT_FALSE(t3Flags & MDB_INTEGERDUP);
|
||
|
|
||
|
EXPECT_TRUE(t4Flags & MDB_INTEGERKEY);
|
||
|
EXPECT_TRUE(t4Flags & MDB_DUPSORT);
|
||
|
EXPECT_TRUE(t4Flags & MDB_DUPFIXED);
|
||
|
EXPECT_FALSE(t4Flags & MDB_INTEGERDUP);
|
||
|
}
|
||
|
|
||
|
TEST_F(DuplicatesTest, Adding) {
|
||
|
t1->addRecord(1, 1);
|
||
|
t1->addRecord(2, 2);
|
||
|
t1->addRecord(2, 1);
|
||
|
t1->addRecord(1, 2);
|
||
|
EXPECT_THROW(t1->addRecord(1, 1), LMDBAL::Exist);
|
||
|
EXPECT_THROW(t1->addRecord(1, 2), LMDBAL::Exist);
|
||
|
EXPECT_THROW(t1->addRecord(2, 2), LMDBAL::Exist);
|
||
|
|
||
|
EXPECT_EQ(t1->count(), 4);
|
||
|
EXPECT_EQ(t1->getRecord(1), 1);
|
||
|
EXPECT_EQ(t1->getRecord(2), 1);
|
||
|
}
|