#pragma once #include "domain/project_storage.h" #include #include #include #include #include namespace TestSupport { inline void require(bool condition, const std::string &message) { if (!condition) { throw std::runtime_error(message); } } struct TestCase { const char *name; void (*run)(); }; // 每个用例独立记录结果,避免首个失败掩盖同一目标中的其他回归 inline int runTestSuite( const char *suite_name, std::initializer_list test_cases) { std::size_t failed_count = 0U; for (const TestCase &test_case : test_cases) { try { test_case.run(); std::cout << "[PASS] " << test_case.name << '\n'; } catch (const std::exception &error) { ++failed_count; std::cerr << "[FAIL] " << test_case.name << ": " << error.what() << '\n'; } catch (...) { ++failed_count; std::cerr << "[FAIL] " << test_case.name << ": unknown exception\n"; } } const std::size_t passed_count = test_cases.size() - failed_count; std::cout << suite_name << ": " << passed_count << "/" << test_cases.size() << " test cases passed\n"; return failed_count == 0U ? 0 : 1; } // 编辑服务测试只验证内存模型和服务契约,不应依赖真实文件系统 class InMemoryProjectStorage final : public ProjectStorage { public: ProjectSaveResult save(const Project &, const std::string &) override { return {true, ProjectStorageError::None, {}}; } ProjectLoadResult load(const std::string &) override { return {false, {}, ProjectStorageError::FileReadFailed, {}}; } }; } // namespace TestSupport