some tuning, specializations, basic testing
This commit is contained in:
parent
5f90a21fe6
commit
047f96b54a
17 changed files with 370 additions and 508 deletions
22
test/CMakeLists.txt
Normal file
22
test/CMakeLists.txt
Normal file
|
@ -0,0 +1,22 @@
|
|||
enable_testing()
|
||||
find_package(GTest REQUIRED)
|
||||
include_directories(${GTEST_INCLUDE_DIR})
|
||||
|
||||
add_executable(runUnitTests
|
||||
basic.cpp
|
||||
)
|
||||
|
||||
target_compile_options(runUnitTests PRIVATE -fPIC)
|
||||
|
||||
target_include_directories(runUnitTests PRIVATE ${CMAKE_SOURCE_DIR})
|
||||
target_include_directories(runUnitTests PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
|
||||
target_include_directories(runUnitTests PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(
|
||||
runUnitTests
|
||||
GTest::gtest_main
|
||||
storage
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(runUnitTests)
|
66
test/basic.cpp
Normal file
66
test/basic.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue