Older/UnitTest/DatabaseTest.cpp

26 lines
753 B
C++
Raw Normal View History

2023-12-30 01:19:36 +08:00
#include "Database.h"
#include "BoostLog.h"
#include <boost/test/unit_test.hpp>
2024-07-10 22:37:40 +08:00
#include <filesystem>
2023-12-30 01:19:36 +08:00
static constexpr auto path = "build/database.sqlite";
using namespace std::chrono;
BOOST_AUTO_TEST_CASE(DatabaseTest) {
2024-07-10 22:37:40 +08:00
if (std::filesystem::exists(path)) {
std::filesystem::remove(path);
}
2023-12-30 01:19:36 +08:00
Database database;
BOOST_TEST(database.open(path));
database.addTask(1234, "Hello");
2024-07-10 22:37:40 +08:00
database.addTask(1234, "这是一个测试", "", true);
database.addHomeBoxItem("手机", "抽屉", 1499);
auto items = database.homeBoxItems();
BOOST_CHECK_EQUAL(items.size(), 1);
2023-12-30 01:19:36 +08:00
auto now = duration_cast<seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
database.setTaskFinished(1, true, now);
}