tests, set method, tests for set method
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 46s
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 46s
This commit is contained in:
parent
96d7d9ef64
commit
3307860ca6
7 changed files with 316 additions and 15 deletions
|
@ -23,7 +23,12 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
int getCacheCursorsSize() const {
|
||||
return cache->cursors.size();
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
cursor.drop();
|
||||
transaction.terminate();
|
||||
db->close();
|
||||
db->removeDirectory();
|
||||
|
@ -62,7 +67,9 @@ TEST_F(CacheCursorTest, PopulatingTheTable) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, Creation) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 0);
|
||||
cursor = cache->createCursor();
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
|
||||
EXPECT_THROW(cursor.first(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor.last(), LMDBAL::CursorNotReady);
|
||||
|
@ -74,6 +81,7 @@ TEST_F(CacheCursorTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, FirstPrivate) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
|
@ -85,6 +93,7 @@ TEST_F(CacheCursorTest, FirstPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, NextPrivate) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
reference++;
|
||||
|
@ -107,6 +116,7 @@ TEST_F(CacheCursorTest, NextPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, LastPrivate) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
EXPECT_EQ(cache->count(), data.size());
|
||||
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
|
@ -118,6 +128,7 @@ TEST_F(CacheCursorTest, LastPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, PrevPrivate) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
||||
|
||||
reference++;
|
||||
|
@ -140,6 +151,7 @@ TEST_F(CacheCursorTest, PrevPrivate) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, CurrentPrivate) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
|
@ -172,8 +184,42 @@ TEST_F(CacheCursorTest, CurrentPrivate) {
|
|||
EXPECT_EQ(cache->count(), data.size());
|
||||
}
|
||||
|
||||
TEST_F(CacheCursorTest, SettingPrivate) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
|
||||
EXPECT_FALSE(cursor.set(6684));
|
||||
EXPECT_EQ(cursor.current().second, "tanned inmate");
|
||||
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
std::advance(reference, 5);
|
||||
EXPECT_TRUE(cursor.set(reference->first));
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
++reference;
|
||||
cursor.next();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
++reference;
|
||||
cursor.next();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
--reference;
|
||||
cursor.prev();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
--reference;
|
||||
cursor.prev();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
--reference;
|
||||
cursor.prev();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
}
|
||||
|
||||
TEST_F(CacheCursorTest, Destruction) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
cursor.close();
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
|
||||
EXPECT_THROW(cursor.first(), LMDBAL::CursorNotReady);
|
||||
EXPECT_THROW(cursor.last(), LMDBAL::CursorNotReady);
|
||||
|
@ -182,11 +228,14 @@ TEST_F(CacheCursorTest, Destruction) {
|
|||
EXPECT_THROW(cursor.current(), LMDBAL::CursorNotReady);
|
||||
|
||||
cursor = LMDBAL::Cursor<uint64_t, std::string>();
|
||||
EXPECT_EQ(getCacheCursorsSize(), 0);
|
||||
|
||||
cursor = cache->createCursor();
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
}
|
||||
|
||||
TEST_F(CacheCursorTest, FirstPublic) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
transaction = db->beginTransaction();
|
||||
|
||||
cursor.open(transaction);
|
||||
|
@ -199,6 +248,7 @@ TEST_F(CacheCursorTest, FirstPublic) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, NextPublic) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
reference++;
|
||||
|
@ -220,6 +270,7 @@ TEST_F(CacheCursorTest, NextPublic) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, LastPublic) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
std::pair<uint64_t, std::string> element = cursor.last();
|
||||
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
||||
|
||||
|
@ -229,6 +280,7 @@ TEST_F(CacheCursorTest, LastPublic) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, PrevPublic) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
||||
|
||||
reference++;
|
||||
|
@ -250,6 +302,7 @@ TEST_F(CacheCursorTest, PrevPublic) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, CurrentPublic) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
std::pair<uint64_t, std::string> element = cursor.first();
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
|
||||
|
@ -282,6 +335,71 @@ TEST_F(CacheCursorTest, CurrentPublic) {
|
|||
EXPECT_EQ(cache->count(), data.size());
|
||||
}
|
||||
|
||||
TEST_F(CacheCursorTest, SettingPublic) {
|
||||
EXPECT_EQ(getCacheCursorsSize(), 1);
|
||||
|
||||
EXPECT_FALSE(cursor.set(557));
|
||||
EXPECT_EQ(cursor.current().second, "resilent pick forefront");
|
||||
|
||||
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
||||
std::advance(reference, 3);
|
||||
EXPECT_TRUE(cursor.set(reference->first));
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
++reference;
|
||||
cursor.next();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
++reference;
|
||||
cursor.next();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
--reference;
|
||||
cursor.prev();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
--reference;
|
||||
cursor.prev();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
|
||||
--reference;
|
||||
cursor.prev();
|
||||
EXPECT_EQ(cursor.current().second, reference->second);
|
||||
}
|
||||
|
||||
TEST_F(CacheCursorTest, CursorRAIIBehaviour) {
|
||||
int initialiCursorsAmount = getCacheCursorsSize();
|
||||
{
|
||||
LMDBAL::Cursor<uint64_t, std::string> cur = cache->createCursor();
|
||||
EXPECT_EQ(initialiCursorsAmount + 1, getCacheCursorsSize());
|
||||
cur.open(transaction);
|
||||
EXPECT_NO_THROW(cur.first());
|
||||
}
|
||||
|
||||
EXPECT_EQ(initialiCursorsAmount, getCacheCursorsSize());
|
||||
LMDBAL::Cursor<uint64_t, std::string> cur;
|
||||
EXPECT_EQ(initialiCursorsAmount, getCacheCursorsSize());
|
||||
EXPECT_EQ(cur.empty(), true);
|
||||
cur = cache->createCursor();
|
||||
EXPECT_EQ(cur.empty(), false);
|
||||
EXPECT_EQ(initialiCursorsAmount + 1, getCacheCursorsSize());
|
||||
EXPECT_THROW(emptyCache->destroyCursor(cur), LMDBAL::Unknown);
|
||||
cache->destroyCursor(cur);
|
||||
EXPECT_EQ(cur.empty(), true);
|
||||
EXPECT_EQ(initialiCursorsAmount, getCacheCursorsSize());
|
||||
|
||||
cur = cache->createCursor();
|
||||
EXPECT_EQ(initialiCursorsAmount + 1, getCacheCursorsSize());
|
||||
EXPECT_EQ(cur.empty(), false);
|
||||
|
||||
cur.drop();
|
||||
EXPECT_EQ(cur.empty(), true);
|
||||
EXPECT_EQ(initialiCursorsAmount, getCacheCursorsSize());
|
||||
|
||||
EXPECT_NO_THROW(cur.drop());
|
||||
EXPECT_THROW(cache->destroyCursor(cur), LMDBAL::Unknown);
|
||||
}
|
||||
|
||||
TEST_F(CacheCursorTest, CornerCases) {
|
||||
transaction.terminate();
|
||||
EXPECT_THROW(cursor.current(), LMDBAL::Unknown);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue