Older/UnitTest/DatabaseTest.cpp

32 lines
1.0 KiB
C++
Raw Permalink 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
2024-07-31 22:28:05 +08:00
auto now = std::chrono::system_clock::now();
std::time_t now_time = std::chrono::system_clock::to_time_t(now);
database.setTaskFinished(1, true, now_time);
2024-07-29 00:46:11 +08:00
2024-07-31 22:28:05 +08:00
database.updateVisitCount("/note", "uuid_123", "chrome", now_time);
database.updateVisitCount("/note/1", "uuid_1232", "chrome", now_time);
database.updateVisitCount("/note", "uuid_123", "chrome", now_time);
database.updateVisitCount("/note", "uuid_1234", "chrome", now_time);
2023-12-30 01:19:36 +08:00
}