67 lines
1.4 KiB
C++
67 lines
1.4 KiB
C++
|
#include <gtest/gtest.h>
|
||
|
|
||
|
#include "database.h"
|
||
|
#include "table.h"
|
||
|
|
||
|
#include <QString>
|
||
|
|
||
|
class DataBaseTest : public ::testing::Test {
|
||
|
protected:
|
||
|
DataBaseTest():
|
||
|
::testing::Test(),
|
||
|
t1(db->getTable<uint32_t, uint32_t>("table1")),
|
||
|
t2(db->getTable<QString, QString>("table2")) {}
|
||
|
|
||
|
~DataBaseTest() {
|
||
|
}
|
||
|
|
||
|
static void SetUpTestSuite() {
|
||
|
if (db == nullptr) {
|
||
|
db = new DataBase("testBase");
|
||
|
db->addTable<uint32_t, uint32_t>("table1");
|
||
|
db->addTable<QString, QString>("table2");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void TearDownTestSuite() {
|
||
|
db->close();
|
||
|
db->removeDirectory();
|
||
|
delete db;
|
||
|
db = nullptr;
|
||
|
}
|
||
|
|
||
|
static DataBase* db;
|
||
|
|
||
|
DataBase::Table<uint32_t, uint32_t>* t1;
|
||
|
DataBase::Table<QString, QString>* t2;
|
||
|
};
|
||
|
|
||
|
|
||
|
DataBase* DataBaseTest::db = nullptr;
|
||
|
|
||
|
TEST_F(DataBaseTest, RemovingDirectory) {
|
||
|
EXPECT_EQ(db->removeDirectory(), true);
|
||
|
}
|
||
|
|
||
|
TEST_F(DataBaseTest, OpeningDatabase) {
|
||
|
db->open();
|
||
|
EXPECT_EQ(db->ready(), true);
|
||
|
}
|
||
|
|
||
|
TEST_F(DataBaseTest, AddingIntegerKey) {
|
||
|
EXPECT_EQ(db->ready(), true);
|
||
|
t1->addRecord(1, 2);
|
||
|
EXPECT_EQ(t1->getRecord(1), 2);
|
||
|
}
|
||
|
|
||
|
TEST_F(DataBaseTest, AddingQStringKey) {
|
||
|
EXPECT_EQ(db->ready(), true);
|
||
|
t2->addRecord("hello", "world");
|
||
|
EXPECT_EQ(t2->getRecord("hello"), "world");
|
||
|
}
|
||
|
|
||
|
TEST_F(DataBaseTest, ClosingDatabase) {
|
||
|
db->close();
|
||
|
EXPECT_EQ(db->ready(), false);
|
||
|
}
|