mostly documentation mostly for Cursor, some corner cases testing
This commit is contained in:
parent
8cb1e97e30
commit
8ff5672655
6 changed files with 368 additions and 22 deletions
|
@ -8,7 +8,8 @@ class StorageCursorTest : public ::testing::Test {
|
|||
protected:
|
||||
StorageCursorTest():
|
||||
::testing::Test(),
|
||||
table (db->getStorage<uint64_t, std::string>("table1")) {}
|
||||
table (db->getStorage<uint64_t, std::string>("table1")),
|
||||
emptyTable (db->getStorage<uint64_t, std::string>("empty")) {}
|
||||
|
||||
~StorageCursorTest() {}
|
||||
|
||||
|
@ -16,6 +17,7 @@ protected:
|
|||
if (db == nullptr) {
|
||||
db = new LMDBAL::Base("testBase");
|
||||
db->addStorage<uint64_t, std::string>("table1");
|
||||
db->addStorage<uint64_t, std::string>("empty");
|
||||
db->open();
|
||||
}
|
||||
}
|
||||
|
@ -25,16 +27,21 @@ protected:
|
|||
db->removeDirectory();
|
||||
delete db;
|
||||
db = nullptr;
|
||||
cursor = nullptr;
|
||||
emptyCursor = nullptr;
|
||||
}
|
||||
|
||||
static LMDBAL::Base* db;
|
||||
static LMDBAL::Cursor<uint64_t, std::string>* cursor;
|
||||
static LMDBAL::Cursor<uint64_t, std::string>* emptyCursor;
|
||||
|
||||
LMDBAL::Storage<uint64_t, std::string>* table;
|
||||
LMDBAL::Storage<uint64_t, std::string>* emptyTable;
|
||||
};
|
||||
|
||||
LMDBAL::Base* StorageCursorTest::db = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* StorageCursorTest::cursor = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* StorageCursorTest::emptyCursor = nullptr;
|
||||
|
||||
static const std::map<uint64_t, std::string> data({
|
||||
{245665783, "bothering nerds"},
|
||||
|
@ -50,13 +57,13 @@ static const std::map<uint64_t, std::string> data({
|
|||
});
|
||||
|
||||
TEST_F(StorageCursorTest, PopulatingTheTable) {
|
||||
|
||||
uint32_t amount = table->addRecords(data);
|
||||
EXPECT_EQ(amount, data.size());
|
||||
}
|
||||
|
||||
TEST_F(StorageCursorTest, Creation) {
|
||||
cursor = table->createCursor();
|
||||
emptyCursor = emptyTable->createCursor();
|
||||
|
||||
EXPECT_THROW(cursor->first(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->last(), LMDBAL::CursorNotReady);
|
||||
|
@ -121,21 +128,7 @@ TEST_F(StorageCursorTest, PrevPrivate) {
|
|||
EXPECT_EQ(element.second, reference->second);
|
||||
}
|
||||
|
||||
TEST_F(StorageCursorTest, Destruction) {
|
||||
cursor->close();
|
||||
|
||||
EXPECT_THROW(cursor->first(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->last(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->current(), LMDBAL::CursorNotReady);
|
||||
}
|
||||
|
||||
TEST_F(StorageCursorTest, CurrentPrivate) {
|
||||
cursor->open();
|
||||
|
||||
EXPECT_THROW(cursor->current(), LMDBAL::Unknown); //yeah, nice thing to write in the doc
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
|
@ -165,3 +158,46 @@ TEST_F(StorageCursorTest, CurrentPrivate) {
|
|||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
}
|
||||
|
||||
TEST_F(StorageCursorTest, Destruction) {
|
||||
cursor->close();
|
||||
|
||||
EXPECT_THROW(cursor->first(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->last(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor->current(), LMDBAL::CursorNotReady);
|
||||
}
|
||||
|
||||
TEST_F(StorageCursorTest, CornerCases) {
|
||||
emptyCursor->open();
|
||||
EXPECT_THROW(emptyCursor->first(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(emptyCursor->last(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(emptyCursor->next(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(emptyCursor->prev(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(emptyCursor->current(), LMDBAL::Unknown);
|
||||
emptyCursor->close();
|
||||
|
||||
cursor->open();
|
||||
EXPECT_THROW(cursor->current(), LMDBAL::Unknown); //yeah, nice thing to write in the doc
|
||||
|
||||
std::map<uint64_t, std::string>::const_reverse_iterator breference = data.rbegin();
|
||||
std::pair<uint64_t, std::string> element(cursor->prev());
|
||||
EXPECT_EQ(element.first, breference->first); //nice thing to write in the doc, again!
|
||||
EXPECT_EQ(element.second, breference->second);
|
||||
element = cursor->current();
|
||||
EXPECT_EQ(element.first, breference->first);
|
||||
EXPECT_EQ(element.second, breference->second);
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::NotFound);
|
||||
cursor->close();
|
||||
|
||||
cursor->open();
|
||||
element = cursor->next();
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
element = cursor->current();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::NotFound);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue