some more primitive specializations, counting rows, dropping tables, tests

This commit is contained in:
Blue 2022-09-17 15:31:58 +03:00
parent 047f96b54a
commit 2f34fa69e8
Signed by: blue
GPG key ID: 9B203B252A63EE38
22 changed files with 667 additions and 28 deletions

View file

@ -12,8 +12,7 @@ protected:
t1(db->getTable<uint32_t, uint32_t>("table1")),
t2(db->getTable<QString, QString>("table2")) {}
~DataBaseTest() {
}
~DataBaseTest() {}
static void SetUpTestSuite() {
if (db == nullptr) {
@ -43,7 +42,12 @@ TEST_F(DataBaseTest, RemovingDirectory) {
EXPECT_EQ(db->removeDirectory(), true);
}
TEST_F(DataBaseTest, OpeningDatabase) {
TEST_F(DataBaseTest, OpeningClosingDatabase) {
EXPECT_EQ(db->ready(), false);
db->open();
EXPECT_EQ(db->ready(), true);
db->close();
EXPECT_EQ(db->ready(), false);
db->open();
EXPECT_EQ(db->ready(), true);
}
@ -51,16 +55,112 @@ TEST_F(DataBaseTest, OpeningDatabase) {
TEST_F(DataBaseTest, AddingIntegerKey) {
EXPECT_EQ(db->ready(), true);
t1->addRecord(1, 2);
t1->addRecord(2, 2);
t1->addRecord(3, 15);
EXPECT_EQ(t1->getRecord(1), 2);
}
TEST_F(DataBaseTest, AddingQStringKey) {
EXPECT_EQ(db->ready(), true);
t2->addRecord("hello", "world");
t2->addRecord("aaa", "gagdfsdf");
t2->addRecord("sdfhga", "DSFFDG");
t2->addRecord("sdfsda", "shgsdgfa");
EXPECT_EQ(t2->getRecord("hello"), "world");
}
TEST_F(DataBaseTest, ClosingDatabase) {
db->close();
EXPECT_EQ(db->ready(), false);
TEST_F(DataBaseTest, AddingRepeatingIntegerKey) {
EXPECT_EQ(db->ready(), true);
bool thrown = false;
try {
t1->addRecord(3, 24);
} catch (const DataBase::Exist e) {
thrown = true;
}
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
EXPECT_EQ(t1->getRecord(3), 15);
}
TEST_F(DataBaseTest, AddingRepeatingStringKey) {
EXPECT_EQ(db->ready(), true);
bool thrown = false;
try {
t2->addRecord("sdfhga", "world");
} catch (const DataBase::Exist e) {
thrown = true;
}
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
EXPECT_EQ(t2->getRecord("sdfhga"), "DSFFDG");
}
TEST_F(DataBaseTest, GettingNotExistingKeys) {
EXPECT_EQ(db->ready(), true);
bool thrown = false;
try {
QString wrong = t2->getRecord("almonds");
} catch (const DataBase::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 DataBase::NotFound e) {
thrown = true;
}
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
}
TEST_F(DataBaseTest, Persistence) {
EXPECT_EQ(db->ready(), true);
db->close();
delete db;
db = new DataBase("testBase");
t1 = db->addTable<uint32_t, uint32_t>("table1");
t2 = db->addTable<QString, QString>("table2");
db->open();
EXPECT_EQ(t1->getRecord(3), 15);
EXPECT_EQ(t1->getRecord(1), 2);
EXPECT_EQ(t1->getRecord(2), 2);
EXPECT_EQ(t2->getRecord("hello"), "world");
EXPECT_EQ(t2->getRecord("aaa"), "gagdfsdf");
EXPECT_EQ(t2->getRecord("sdfhga"), "DSFFDG");
EXPECT_EQ(t2->getRecord("sdfsda"), "shgsdgfa");
bool thrown = false;
try {
QString wrong = t2->getRecord("cats");
} catch (const DataBase::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 DataBase::NotFound e) {
thrown = true;
}
ASSERT_EQ(thrown, true) << "The expected behaviour is to throw exception on duplicate, but it didn't happened";
}
TEST_F(DataBaseTest, CountAndDrop) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(t1->count(), 3);
EXPECT_EQ(t2->count(), 4);
db->drop();
EXPECT_EQ(t1->count(), 0);
EXPECT_EQ(t2->count(), 0);
t1->addRecord(2, 2);
t2->addRecord("sdfhga", "world");
EXPECT_EQ(t1->count(), 1);
EXPECT_EQ(t2->count(), 1);
}