#ifndef TESTING_UTIL_H #define TESTING_UTIL_H #include #include #include #include #include namespace TestingOpenMW { inline std::filesystem::path outputFilePath(const std::string name) { std::filesystem::path dir("tests_output"); std::filesystem::create_directory(dir); return dir / Misc::StringUtils::stringToU8String(name); } inline std::filesystem::path outputFilePathWithSubDir(const std::filesystem::path& subpath) { std::filesystem::path path("tests_output"); path /= subpath; std::filesystem::create_directories(path.parent_path()); return path; } inline std::filesystem::path temporaryFilePath(const std::string name) { return std::filesystem::temp_directory_path() / name; } class VFSTestFile : public VFS::File { public: explicit VFSTestFile(std::string content) : mContent(std::move(content)) { } Files::IStreamPtr open() override { return std::make_unique(mContent, std::ios_base::in); } std::filesystem::path getPath() override { return "TestFile"; } private: const std::string mContent; }; struct VFSTestData : public VFS::Archive { std::map mFiles; VFSTestData(std::map files) : mFiles(std::move(files)) { } void listResources(std::map& out, char (*normalize_function)(char)) override { out = mFiles; } bool contains(const std::string& file, char (*normalize_function)(char)) const override { return mFiles.count(file) != 0; } std::string getDescription() const override { return "TestData"; } }; inline std::unique_ptr createTestVFS(std::map files) { auto vfs = std::make_unique(true); vfs->addArchive(std::make_unique(std::move(files))); vfs->buildIndex(); return vfs; } #define EXPECT_ERROR(X, ERR_SUBSTR) \ try \ { \ X; \ FAIL() << "Expected error"; \ } \ catch (std::exception & e) \ { \ EXPECT_THAT(e.what(), ::testing::HasSubstr(ERR_SUBSTR)); \ } } #endif // TESTING_UTIL_H