one more test for adding multiple entries, fix of leaking cursor, Storage::change method rework, beginning of documentation
This commit is contained in:
parent
064277fa6e
commit
6d21ecc155
3 changed files with 334 additions and 81 deletions
223
test/basic.cpp
223
test/basic.cpp
|
@ -83,67 +83,25 @@ TEST_F(BaseTest, AddingKeysToCache) {
|
|||
EXPECT_EQ(c1->getRecord(-116), "whatever");
|
||||
}
|
||||
|
||||
TEST_F(BaseTest, AddingRepeatingIntegerKey) {
|
||||
TEST_F(BaseTest, AddingRepeatingKey) {
|
||||
EXPECT_EQ(db->ready(), true);
|
||||
bool thrown = false;
|
||||
try {
|
||||
t1->addRecord(3, 24);
|
||||
} catch (const LMDBAL::Exist e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
|
||||
EXPECT_THROW(t1->addRecord(3, 24), LMDBAL::Exist);
|
||||
EXPECT_EQ(t1->getRecord(3), 15);
|
||||
}
|
||||
|
||||
TEST_F(BaseTest, AddingRepeatingStringKey) {
|
||||
EXPECT_EQ(db->ready(), true);
|
||||
bool thrown = false;
|
||||
try {
|
||||
t2->addRecord("sdfhga", "world");
|
||||
} catch (const LMDBAL::Exist e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
EXPECT_THROW(t2->addRecord("sdfhga", "world"), LMDBAL::Exist);
|
||||
EXPECT_EQ(t2->getRecord("sdfhga"), "DSFFDG");
|
||||
}
|
||||
|
||||
TEST_F(BaseTest, AddingRepeatingCacheKey) {
|
||||
EXPECT_EQ(db->ready(), true);
|
||||
bool thrown = false;
|
||||
try {
|
||||
c1->addRecord(-4, "world");
|
||||
} catch (const LMDBAL::Exist e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
EXPECT_THROW(c1->addRecord(-4, "world"), LMDBAL::Exist);
|
||||
EXPECT_EQ(c1->getRecord(-4), "testing goes brrr");
|
||||
}
|
||||
|
||||
TEST_F(BaseTest, GettingNotExistingKeys) {
|
||||
EXPECT_EQ(db->ready(), true);
|
||||
bool thrown = false;
|
||||
try {
|
||||
QString wrong = t2->getRecord("almonds");
|
||||
} catch (const LMDBAL::NotFound e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
|
||||
thrown = false;
|
||||
try {
|
||||
uint32_t wrong = t1->getRecord(64);
|
||||
} catch (const LMDBAL::NotFound e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
|
||||
thrown = false;
|
||||
try {
|
||||
std::string wrong = c1->getRecord(21);
|
||||
} catch (const LMDBAL::NotFound e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
EXPECT_THROW(t2->getRecord("almonds"), LMDBAL::NotFound);
|
||||
EXPECT_THROW(t1->getRecord(64), LMDBAL::NotFound);
|
||||
EXPECT_THROW(c1->getRecord(21), LMDBAL::NotFound);
|
||||
}
|
||||
|
||||
TEST_F(BaseTest, Persistence) {
|
||||
|
@ -172,29 +130,9 @@ TEST_F(BaseTest, Persistence) {
|
|||
EXPECT_EQ(c1->getRecord(-37), "aaaaa tss tsss tsss tsss aaaaaaa");
|
||||
EXPECT_EQ(c1->getRecord(2), "blah balah");
|
||||
|
||||
bool thrown = false;
|
||||
try {
|
||||
QString wrong = t2->getRecord("cats");
|
||||
} catch (const LMDBAL::NotFound e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
|
||||
thrown = false;
|
||||
try {
|
||||
uint32_t wrong = t1->getRecord(7893);
|
||||
} catch (const LMDBAL::NotFound e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
|
||||
thrown = false;
|
||||
try {
|
||||
std::string wrong = c1->getRecord(89);
|
||||
} catch (const LMDBAL::NotFound e) {
|
||||
thrown = true;
|
||||
}
|
||||
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
|
||||
EXPECT_THROW(t2->getRecord("cats"), LMDBAL::NotFound);
|
||||
EXPECT_THROW(t1->getRecord(7893), LMDBAL::NotFound);
|
||||
EXPECT_THROW(c1->getRecord(89), LMDBAL::NotFound);
|
||||
}
|
||||
|
||||
TEST_F(BaseTest, CountAndDrop) {
|
||||
|
@ -239,6 +177,10 @@ TEST_F(BaseTest, Change) {
|
|||
c1->changeRecord(15, "recording");
|
||||
c1->changeRecord(12, "thermal");
|
||||
|
||||
EXPECT_THROW(t1->changeRecord(37, 49), LMDBAL::NotFound);
|
||||
EXPECT_THROW(t2->changeRecord("precision", "cryoplastics"), LMDBAL::NotFound);
|
||||
EXPECT_THROW(c1->changeRecord(-62, "sharks"), LMDBAL::NotFound);
|
||||
|
||||
EXPECT_EQ(t1->getRecord(2), 49);
|
||||
EXPECT_EQ(t2->getRecord("sdfhga"), "void");
|
||||
EXPECT_EQ(c1->getRecord(15), "recording");
|
||||
|
@ -302,8 +244,6 @@ TEST_F(BaseTest, ReadAll) {
|
|||
EXPECT_EQ(m3.size(), 4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_F(BaseTest, ReplaceAll) {
|
||||
EXPECT_EQ(db->ready(), true);
|
||||
|
||||
|
@ -346,7 +286,6 @@ TEST_F(BaseTest, ReplaceAll) {
|
|||
EXPECT_EQ(t2->getRecord("cluster"), "throttle");
|
||||
EXPECT_EQ(t2->getRecord("ronin"), "cheese");
|
||||
|
||||
|
||||
c1->replaceAll({
|
||||
{68, "quality"},
|
||||
{31, "ridgid body"},
|
||||
|
@ -362,3 +301,135 @@ TEST_F(BaseTest, ReplaceAll) {
|
|||
EXPECT_EQ(c1->getRecord(22), "pseudo");
|
||||
EXPECT_EQ(c1->getRecord(-117), "lance of Michael");
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_F(BaseTest, AddRecords) {
|
||||
EXPECT_EQ(db->ready(), true);
|
||||
|
||||
LMDBAL::SizeType s1 = t1->addRecords({
|
||||
{5, 3},
|
||||
{800, 9}
|
||||
});
|
||||
EXPECT_EQ(s1, 6);
|
||||
EXPECT_EQ(t1->getRecord(7), 48);
|
||||
EXPECT_EQ(t1->getRecord(194), 582);
|
||||
EXPECT_EQ(t1->getRecord(857), 39);
|
||||
EXPECT_EQ(t1->getRecord(9717), 8);
|
||||
EXPECT_EQ(t1->getRecord(5), 3);
|
||||
EXPECT_EQ(t1->getRecord(800), 9);
|
||||
s1 = t1->addRecords({
|
||||
{194, 371},
|
||||
{808, 487},
|
||||
{807, 0}
|
||||
}, true);
|
||||
EXPECT_EQ(s1, 8);
|
||||
EXPECT_EQ(t1->count(), 8);
|
||||
EXPECT_EQ(t1->getRecord(7), 48);
|
||||
EXPECT_EQ(t1->getRecord(194), 371);
|
||||
EXPECT_EQ(t1->getRecord(857), 39);
|
||||
EXPECT_EQ(t1->getRecord(9717), 8);
|
||||
EXPECT_EQ(t1->getRecord(5), 3);
|
||||
EXPECT_EQ(t1->getRecord(800), 9);
|
||||
EXPECT_EQ(t1->getRecord(808), 487);
|
||||
EXPECT_EQ(t1->getRecord(807), 0);
|
||||
EXPECT_THROW(
|
||||
s1 = t1->addRecords({
|
||||
{194, 371},
|
||||
{808, 487},
|
||||
{807, 0}
|
||||
}), LMDBAL::Exist
|
||||
);
|
||||
EXPECT_EQ(t1->count(), 8);
|
||||
|
||||
LMDBAL::SizeType s2 = t2->addRecords({
|
||||
{"lama", "not quite"},
|
||||
{"by the shadow", "leech"},
|
||||
{"summertime", "curses"}
|
||||
});
|
||||
EXPECT_EQ(s2, 6);
|
||||
EXPECT_EQ(t2->count(), 6);
|
||||
EXPECT_EQ(t2->getRecord("bringin"), "keyboard");
|
||||
EXPECT_EQ(t2->getRecord("cluster"), "throttle");
|
||||
EXPECT_EQ(t2->getRecord("ronin"), "cheese");
|
||||
EXPECT_EQ(t2->getRecord("lama"), "not quite");
|
||||
EXPECT_EQ(t2->getRecord("by the shadow"), "leech");
|
||||
EXPECT_EQ(t2->getRecord("summertime"), "curses");
|
||||
s2 = t2->addRecords({
|
||||
{"worry not", "for shall you"},
|
||||
{"by the shadow", "face the inevitable"},
|
||||
{"cluster", "sobing over those"}
|
||||
}, true);
|
||||
|
||||
EXPECT_EQ(s2, 7);
|
||||
EXPECT_EQ(t2->count(), 7);
|
||||
EXPECT_EQ(t2->getRecord("bringin"), "keyboard");
|
||||
EXPECT_EQ(t2->getRecord("cluster"), "sobing over those");
|
||||
EXPECT_EQ(t2->getRecord("ronin"), "cheese");
|
||||
EXPECT_EQ(t2->getRecord("lama"), "not quite");
|
||||
EXPECT_EQ(t2->getRecord("by the shadow"), "face the inevitable");
|
||||
EXPECT_EQ(t2->getRecord("summertime"), "curses");
|
||||
EXPECT_EQ(t2->getRecord("worry not"), "for shall you");
|
||||
|
||||
EXPECT_THROW(
|
||||
s2 = t2->addRecords({
|
||||
{"within reasonable limits", "occasion"},
|
||||
{"ronin", "crest of violence"},
|
||||
{"permanent", "of your kind"}
|
||||
}), LMDBAL::Exist
|
||||
);
|
||||
EXPECT_EQ(t2->count(), 7);
|
||||
|
||||
LMDBAL::SizeType s3 = c1->addRecords({
|
||||
{19, "menace"},
|
||||
{-7, "failure driven sorrow"},
|
||||
{82, "lungache"},
|
||||
{4, "drowsy"},
|
||||
{44, "pressure"},
|
||||
});
|
||||
|
||||
EXPECT_EQ(c1->count(), 10);
|
||||
EXPECT_EQ(s3, 10);
|
||||
|
||||
EXPECT_EQ(c1->getRecord(68), "quality");
|
||||
EXPECT_EQ(c1->getRecord(31), "ridgid body");
|
||||
EXPECT_EQ(c1->getRecord(16), "fermentation on your kind");
|
||||
EXPECT_EQ(c1->getRecord(22), "pseudo");
|
||||
EXPECT_EQ(c1->getRecord(-117), "lance of Michael");
|
||||
EXPECT_EQ(c1->getRecord(19), "menace");
|
||||
EXPECT_EQ(c1->getRecord(-7), "failure driven sorrow");
|
||||
EXPECT_EQ(c1->getRecord(82), "lungache");
|
||||
EXPECT_EQ(c1->getRecord(4), "drowsy");
|
||||
EXPECT_EQ(c1->getRecord(44), "pressure");
|
||||
|
||||
EXPECT_THROW(
|
||||
s3 = c1->addRecords({
|
||||
{-72, "amber"},
|
||||
{-9, "going swinging of paleopathy"},
|
||||
{82, "regret"}
|
||||
}), LMDBAL::Exist
|
||||
);
|
||||
EXPECT_EQ(c1->count(), 10);
|
||||
|
||||
s3 = c1->addRecords({
|
||||
{19, "to replicated being"},
|
||||
{123, "horibly unforseen"},
|
||||
{-32, "stitched"},
|
||||
{31, "overall"}
|
||||
}, true);
|
||||
EXPECT_EQ(c1->count(), 12);
|
||||
EXPECT_EQ(s3, 12);
|
||||
EXPECT_EQ(c1->getRecord(68), "quality");
|
||||
EXPECT_EQ(c1->getRecord(31), "overall");
|
||||
EXPECT_EQ(c1->getRecord(16), "fermentation on your kind");
|
||||
EXPECT_EQ(c1->getRecord(22), "pseudo");
|
||||
EXPECT_EQ(c1->getRecord(-117), "lance of Michael");
|
||||
EXPECT_EQ(c1->getRecord(19), "to replicated being");
|
||||
EXPECT_EQ(c1->getRecord(-7), "failure driven sorrow");
|
||||
EXPECT_EQ(c1->getRecord(82), "lungache");
|
||||
EXPECT_EQ(c1->getRecord(4), "drowsy");
|
||||
EXPECT_EQ(c1->getRecord(44), "pressure");
|
||||
EXPECT_EQ(c1->getRecord(-32), "stitched");
|
||||
EXPECT_EQ(c1->getRecord(123), "horibly unforseen");
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue