First attempt to make RAII cursors, no tests yet
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s
This commit is contained in:
parent
a0eebc978d
commit
96d7d9ef64
12 changed files with 374 additions and 233 deletions
|
@ -29,13 +29,10 @@ 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;
|
||||
static LMDBAL::Cursor<uint64_t, std::string> cursor;
|
||||
static LMDBAL::Transaction transaction;
|
||||
|
||||
LMDBAL::Cache<uint64_t, std::string>* cache;
|
||||
|
@ -43,8 +40,7 @@ protected:
|
|||
};
|
||||
|
||||
LMDBAL::Base* CacheCursorTest::db = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* CacheCursorTest::cursor = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* CacheCursorTest::emptyCursor = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string> CacheCursorTest::cursor;
|
||||
LMDBAL::Transaction CacheCursorTest::transaction;
|
||||
|
||||
static const std::map<uint64_t, std::string> data({
|
||||
|
@ -67,21 +63,20 @@ TEST_F(CacheCursorTest, PopulatingTheTable) {
|
|||
|
||||
TEST_F(CacheCursorTest, Creation) {
|
||||
cursor = cache->createCursor();
|
||||
emptyCursor = emptyCache->createCursor();
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
cursor->open();
|
||||
cursor.open();
|
||||
}
|
||||
|
||||
TEST_F(CacheCursorTest, FirstPrivate) {
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -94,16 +89,16 @@ TEST_F(CacheCursorTest, NextPrivate) {
|
|||
|
||||
reference++;
|
||||
for (; reference != data.end(); ++reference) {
|
||||
std::pair<uint64_t, std::string> element = cursor->next();
|
||||
std::pair<uint64_t, std::string> element = cursor.next();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
}
|
||||
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
reference = data.begin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -114,7 +109,7 @@ TEST_F(CacheCursorTest, NextPrivate) {
|
|||
TEST_F(CacheCursorTest, LastPrivate) {
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->last();
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -127,16 +122,16 @@ TEST_F(CacheCursorTest, PrevPrivate) {
|
|||
|
||||
reference++;
|
||||
for (; reference != data.rend(); ++reference) {
|
||||
std::pair<uint64_t, std::string> element = cursor->prev();
|
||||
std::pair<uint64_t, std::string> element = cursor.prev();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
}
|
||||
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->last();
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
reference = data.rbegin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -145,29 +140,29 @@ TEST_F(CacheCursorTest, PrevPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, CurrentPrivate) {
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
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();
|
||||
element = cursor.current();
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
|
||||
cursor->next();
|
||||
element = cursor->current();
|
||||
cursor.next();
|
||||
element = cursor.current();
|
||||
++reference;
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
|
||||
cursor->next();
|
||||
cursor->next();
|
||||
cursor->prev();
|
||||
element = cursor->current();
|
||||
cursor.next();
|
||||
cursor.next();
|
||||
cursor.prev();
|
||||
element = cursor.current();
|
||||
++reference;
|
||||
++reference;
|
||||
--reference;
|
||||
|
@ -178,16 +173,15 @@ TEST_F(CacheCursorTest, CurrentPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, Destruction) {
|
||||
cursor->close();
|
||||
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);
|
||||
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);
|
||||
|
||||
EXPECT_THROW(emptyCache->destroyCursor(cursor), LMDBAL::Unknown);
|
||||
cache->destroyCursor(cursor);
|
||||
cursor = LMDBAL::Cursor<uint64_t, std::string>();
|
||||
|
||||
cursor = cache->createCursor();
|
||||
}
|
||||
|
@ -195,8 +189,8 @@ TEST_F(CacheCursorTest, Destruction) {
|
|||
TEST_F(CacheCursorTest, FirstPublic) {
|
||||
transaction = db->beginTransaction();
|
||||
|
||||
cursor->open(transaction);
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
cursor.open(transaction);
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -209,16 +203,16 @@ TEST_F(CacheCursorTest, NextPublic) {
|
|||
|
||||
reference++;
|
||||
for (; reference != data.end(); ++reference) {
|
||||
std::pair<uint64_t, std::string> element = cursor->next();
|
||||
std::pair<uint64_t, std::string> element = cursor.next();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
}
|
||||
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
reference = data.begin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -226,7 +220,7 @@ TEST_F(CacheCursorTest, NextPublic) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, LastPublic) {
|
||||
std::pair<uint64_t, std::string> element = cursor->last();
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -239,15 +233,15 @@ TEST_F(CacheCursorTest, PrevPublic) {
|
|||
|
||||
reference++;
|
||||
for (; reference != data.rend(); ++reference) {
|
||||
std::pair<uint64_t, std::string> element = cursor->prev();
|
||||
std::pair<uint64_t, std::string> element = cursor.prev();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
}
|
||||
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->last();
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
reference = data.rbegin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -256,29 +250,29 @@ TEST_F(CacheCursorTest, PrevPublic) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, CurrentPublic) {
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
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();
|
||||
element = cursor.current();
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
|
||||
cursor->next();
|
||||
element = cursor->current();
|
||||
cursor.next();
|
||||
element = cursor.current();
|
||||
++reference;
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
|
||||
cursor->next();
|
||||
cursor->next();
|
||||
cursor->prev();
|
||||
element = cursor->current();
|
||||
cursor.next();
|
||||
cursor.next();
|
||||
cursor.prev();
|
||||
element = cursor.current();
|
||||
++reference;
|
||||
++reference;
|
||||
--reference;
|
||||
|
@ -290,38 +284,39 @@ TEST_F(CacheCursorTest, CurrentPublic) {
|
|||
|
||||
TEST_F(CacheCursorTest, CornerCases) {
|
||||
transaction.terminate();
|
||||
EXPECT_THROW(cursor->current(), LMDBAL::Unknown);
|
||||
cursor->close();
|
||||
EXPECT_THROW(cursor.current(), LMDBAL::Unknown);
|
||||
cursor.close();
|
||||
|
||||
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();
|
||||
LMDBAL::Cursor<uint64_t, std::string> emptyCursor = emptyCache->createCursor();
|
||||
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
|
||||
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());
|
||||
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();
|
||||
element = cursor.current();
|
||||
EXPECT_EQ(element.first, breference->first);
|
||||
EXPECT_EQ(element.second, breference->second);
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::NotFound);
|
||||
cursor->close();
|
||||
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
||||
cursor.close();
|
||||
|
||||
cursor->open();
|
||||
element = cursor->next();
|
||||
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();
|
||||
element = cursor.current();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
||||
}
|
||||
|
||||
|
|
|
@ -337,15 +337,15 @@ TEST_F(DuplicatesTest, GettingAllRecords) {
|
|||
|
||||
std::map<int16_t, uint16_t> m1;
|
||||
std::set<int16_t> k1;
|
||||
LMDBAL::Cursor<int16_t, uint16_t>* c1 = tu1->createCursor();
|
||||
LMDBAL::Cursor<int16_t, uint16_t> c1 = tu1->createCursor();
|
||||
tu1->readAll(m1, txn);
|
||||
c1->open(txn);
|
||||
c1.open(txn);
|
||||
|
||||
cycle = false;
|
||||
iterations = 0;
|
||||
do {
|
||||
try {
|
||||
std::pair<int16_t, uint16_t> pair = c1->next();
|
||||
std::pair<int16_t, uint16_t> pair = c1.next();
|
||||
cycle = true;
|
||||
std::pair<std::set<int16_t>::const_iterator, bool> probe = k1.insert(pair.first);
|
||||
if (probe.second) {
|
||||
|
@ -359,25 +359,25 @@ TEST_F(DuplicatesTest, GettingAllRecords) {
|
|||
cycle = false;
|
||||
}
|
||||
} while (cycle);
|
||||
tu1->destroyCursor(c1);
|
||||
|
||||
EXPECT_EQ(iterations, tu1->count(txn));
|
||||
EXPECT_EQ(k1.size(), m1.size());
|
||||
EXPECT_NE(iterations, 0);
|
||||
EXPECT_NE(k1.size(), 0);
|
||||
c1.drop();
|
||||
|
||||
|
||||
std::map<std::string, int8_t> m2;
|
||||
std::set<std::string> k2;
|
||||
LMDBAL::Cursor<std::string, int8_t>* c2 = tu2->createCursor();
|
||||
LMDBAL::Cursor<std::string, int8_t> c2 = tu2->createCursor();
|
||||
tu2->readAll(m2, txn);
|
||||
c2->open(txn);
|
||||
c2.open(txn);
|
||||
|
||||
cycle = false;
|
||||
iterations = 0;
|
||||
do {
|
||||
try {
|
||||
std::pair<std::string, int8_t> pair = c2->next();
|
||||
std::pair<std::string, int8_t> pair = c2.next();
|
||||
cycle = true;
|
||||
std::pair<std::set<std::string>::const_iterator, bool> probe = k2.insert(pair.first);
|
||||
if (probe.second) {
|
||||
|
@ -391,25 +391,25 @@ TEST_F(DuplicatesTest, GettingAllRecords) {
|
|||
cycle = false;
|
||||
}
|
||||
} while (cycle);
|
||||
tu2->destroyCursor(c2);
|
||||
|
||||
EXPECT_EQ(iterations, tu2->count(txn));
|
||||
EXPECT_EQ(k2.size(), m2.size());
|
||||
EXPECT_NE(iterations, 0);
|
||||
EXPECT_NE(k2.size(), 0);
|
||||
c2.drop();
|
||||
|
||||
|
||||
std::map<float, float> m3;
|
||||
std::set<float> k3;
|
||||
LMDBAL::Cursor<float, float>* c3 = tu3->createCursor();
|
||||
LMDBAL::Cursor<float, float> c3 = tu3->createCursor();
|
||||
tu3->readAll(m3, txn);
|
||||
c3->open(txn);
|
||||
c3.open(txn);
|
||||
|
||||
cycle = false;
|
||||
iterations = 0;
|
||||
do {
|
||||
try {
|
||||
std::pair<float, float> pair = c3->next();
|
||||
std::pair<float, float> pair = c3.next();
|
||||
cycle = true;
|
||||
std::pair<std::set<float>::const_iterator, bool> probe = k3.insert(pair.first);
|
||||
if (probe.second) {
|
||||
|
@ -423,25 +423,25 @@ TEST_F(DuplicatesTest, GettingAllRecords) {
|
|||
cycle = false;
|
||||
}
|
||||
} while (cycle);
|
||||
tu3->destroyCursor(c3);
|
||||
|
||||
EXPECT_EQ(iterations, tu3->count(txn));
|
||||
EXPECT_EQ(k3.size(), m3.size());
|
||||
EXPECT_NE(iterations, 0);
|
||||
EXPECT_NE(k3.size(), 0);
|
||||
c3.drop();
|
||||
|
||||
|
||||
std::map<uint16_t, double> m4;
|
||||
std::set<uint16_t> k4;
|
||||
LMDBAL::Cursor<uint16_t, double>* c4 = tu4->createCursor();
|
||||
LMDBAL::Cursor<uint16_t, double> c4 = tu4->createCursor();
|
||||
tu4->readAll(m4, txn);
|
||||
c4->open(txn);
|
||||
c4.open(txn);
|
||||
|
||||
cycle = false;
|
||||
iterations = 0;
|
||||
do {
|
||||
try {
|
||||
std::pair<uint16_t, double> pair = c4->next();
|
||||
std::pair<uint16_t, double> pair = c4.next();
|
||||
cycle = true;
|
||||
std::pair<std::set<uint16_t>::const_iterator, bool> probe = k4.insert(pair.first);
|
||||
if (probe.second) {
|
||||
|
@ -455,7 +455,7 @@ TEST_F(DuplicatesTest, GettingAllRecords) {
|
|||
cycle = false;
|
||||
}
|
||||
} while (cycle);
|
||||
tu4->destroyCursor(c4);
|
||||
c4.drop();
|
||||
|
||||
EXPECT_EQ(iterations, tu4->count(txn));
|
||||
EXPECT_EQ(k4.size(), m4.size());
|
||||
|
|
|
@ -28,13 +28,10 @@ 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;
|
||||
static LMDBAL::Cursor<uint64_t, std::string> cursor;
|
||||
static LMDBAL::Transaction transaction;
|
||||
|
||||
LMDBAL::Storage<uint64_t, std::string>* table;
|
||||
|
@ -42,8 +39,7 @@ protected:
|
|||
};
|
||||
|
||||
LMDBAL::Base* StorageCursorTest::db = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* StorageCursorTest::cursor = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* StorageCursorTest::emptyCursor = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string> StorageCursorTest::cursor;
|
||||
LMDBAL::Transaction StorageCursorTest::transaction = LMDBAL::Transaction();
|
||||
|
||||
static const std::map<uint64_t, std::string> data({
|
||||
|
@ -66,19 +62,18 @@ TEST_F(StorageCursorTest, PopulatingTheTable) {
|
|||
|
||||
TEST_F(StorageCursorTest, Creation) {
|
||||
cursor = table->createCursor();
|
||||
emptyCursor = emptyTable->createCursor();
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
cursor->open();
|
||||
cursor.open();
|
||||
}
|
||||
|
||||
TEST_F(StorageCursorTest, FirstPrivate) {
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -90,14 +85,14 @@ TEST_F(StorageCursorTest, NextPrivate) {
|
|||
|
||||
reference++;
|
||||
for (; reference != data.end(); ++reference) {
|
||||
std::pair<uint64_t, std::string> element = cursor->next();
|
||||
std::pair<uint64_t, std::string> element = cursor.next();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
}
|
||||
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
reference = data.begin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -105,7 +100,7 @@ TEST_F(StorageCursorTest, NextPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(StorageCursorTest, LastPrivate) {
|
||||
std::pair<uint64_t, std::string> element = cursor->last();
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -117,14 +112,14 @@ TEST_F(StorageCursorTest, PrevPrivate) {
|
|||
|
||||
reference++;
|
||||
for (; reference != data.rend(); ++reference) {
|
||||
std::pair<uint64_t, std::string> element = cursor->prev();
|
||||
std::pair<uint64_t, std::string> element = cursor.prev();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
}
|
||||
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->last();
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
reference = data.rbegin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -132,28 +127,28 @@ TEST_F(StorageCursorTest, PrevPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(StorageCursorTest, CurrentPrivate) {
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
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();
|
||||
element = cursor.current();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
|
||||
cursor->next();
|
||||
element = cursor->current();
|
||||
cursor.next();
|
||||
element = cursor.current();
|
||||
++reference;
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
|
||||
cursor->next();
|
||||
cursor->next();
|
||||
cursor->prev();
|
||||
element = cursor->current();
|
||||
cursor.next();
|
||||
cursor.next();
|
||||
cursor.prev();
|
||||
element = cursor.current();
|
||||
++reference;
|
||||
++reference;
|
||||
--reference;
|
||||
|
@ -163,16 +158,15 @@ TEST_F(StorageCursorTest, CurrentPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(StorageCursorTest, Destruction) {
|
||||
cursor->close();
|
||||
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);
|
||||
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);
|
||||
|
||||
EXPECT_THROW(emptyTable->destroyCursor(cursor), LMDBAL::Unknown);
|
||||
table->destroyCursor(cursor);
|
||||
cursor = LMDBAL::Cursor<uint64_t, std::string>();
|
||||
|
||||
cursor = table->createCursor();
|
||||
}
|
||||
|
@ -180,8 +174,8 @@ TEST_F(StorageCursorTest, Destruction) {
|
|||
TEST_F(StorageCursorTest, FirstPublic) {
|
||||
transaction = db->beginReadOnlyTransaction();
|
||||
|
||||
cursor->open(transaction);
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
cursor.open(transaction);
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -193,14 +187,14 @@ TEST_F(StorageCursorTest, NextPublic) {
|
|||
|
||||
reference++;
|
||||
for (; reference != data.end(); ++reference) {
|
||||
std::pair<uint64_t, std::string> element = cursor->next();
|
||||
std::pair<uint64_t, std::string> element = cursor.next();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
}
|
||||
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
reference = data.begin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -208,7 +202,7 @@ TEST_F(StorageCursorTest, NextPublic) {
|
|||
}
|
||||
|
||||
TEST_F(StorageCursorTest, LastPublic) {
|
||||
std::pair<uint64_t, std::string> element = cursor->last();
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -220,14 +214,14 @@ TEST_F(StorageCursorTest, PrevPublic) {
|
|||
|
||||
reference++;
|
||||
for (; reference != data.rend(); ++reference) {
|
||||
std::pair<uint64_t, std::string> element = cursor->prev();
|
||||
std::pair<uint64_t, std::string> element = cursor.prev();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
}
|
||||
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor->last();
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
reference = data.rbegin();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
|
@ -235,28 +229,28 @@ TEST_F(StorageCursorTest, PrevPublic) {
|
|||
}
|
||||
|
||||
TEST_F(StorageCursorTest, CurrentPublic) {
|
||||
std::pair<uint64_t, std::string> element = cursor->first();
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
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();
|
||||
element = cursor.current();
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
|
||||
cursor->next();
|
||||
element = cursor->current();
|
||||
cursor.next();
|
||||
element = cursor.current();
|
||||
++reference;
|
||||
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
|
||||
cursor->next();
|
||||
cursor->next();
|
||||
cursor->prev();
|
||||
element = cursor->current();
|
||||
cursor.next();
|
||||
cursor.next();
|
||||
cursor.prev();
|
||||
element = cursor.current();
|
||||
++reference;
|
||||
++reference;
|
||||
--reference;
|
||||
|
@ -267,37 +261,38 @@ TEST_F(StorageCursorTest, CurrentPublic) {
|
|||
|
||||
TEST_F(StorageCursorTest, CornerCases) {
|
||||
transaction.terminate();
|
||||
EXPECT_THROW(cursor->current(), LMDBAL::Unknown);
|
||||
cursor->close();
|
||||
EXPECT_THROW(cursor.current(), LMDBAL::Unknown);
|
||||
cursor.close();
|
||||
|
||||
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();
|
||||
LMDBAL::Cursor<uint64_t, std::string> emptyCursor = emptyTable->createCursor();
|
||||
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
|
||||
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());
|
||||
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();
|
||||
element = cursor.current();
|
||||
EXPECT_EQ(element.first, breference->first);
|
||||
EXPECT_EQ(element.second, breference->second);
|
||||
EXPECT_THROW(cursor->next(), LMDBAL::NotFound);
|
||||
cursor->close();
|
||||
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
||||
cursor.close();
|
||||
|
||||
cursor->open();
|
||||
element = cursor->next();
|
||||
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();
|
||||
element = cursor.current();
|
||||
EXPECT_EQ(element.first, reference->first);
|
||||
EXPECT_EQ(element.second, reference->second);
|
||||
EXPECT_THROW(cursor->prev(), LMDBAL::NotFound);
|
||||
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue