diff --git a/tests/dCommonTests/CMakeLists.txt b/tests/dCommonTests/CMakeLists.txt index 0b40aaea9..db44c3db9 100644 --- a/tests/dCommonTests/CMakeLists.txt +++ b/tests/dCommonTests/CMakeLists.txt @@ -50,7 +50,7 @@ if(APPLE) endif() # Link needed libraries -target_link_libraries(dCommonTests ${COMMON_LIBRARIES} GTest::gtest_main) +target_link_libraries(dCommonTests ${COMMON_LIBRARIES} MD5 GTest::gtest_main) # SpareBackoff.h (header only) target_include_directories(dCommonTests PRIVATE "${PROJECT_SOURCE_DIR}/dMasterServer") diff --git a/tests/dCommonTests/ClientZoneFilesTests.cpp b/tests/dCommonTests/ClientZoneFilesTests.cpp index a53ccb383..7b4a15ad1 100644 --- a/tests/dCommonTests/ClientZoneFilesTests.cpp +++ b/tests/dCommonTests/ClientZoneFilesTests.cpp @@ -11,6 +11,7 @@ #include "dCommonDependencies.h" #include "LevelFile.h" +#include "MD5.h" #include "Sd0.h" #include "ZoneFile.h" @@ -26,11 +27,17 @@ namespace { return {}; } - // Files on disk that are damaged themselves, not misread + // Files on disk that are damaged themselves, not misread, by the MD5 of their bytes const std::set DAMAGED_FILES = { "72895c754d511a92335abae03400ac0b", // MD5 of a scene file that claims 81 objects in 910 bytes }; + bool IsDamaged(const std::filesystem::path& path) { + std::ifstream file(path, std::ios::binary); + const std::string bytes{ std::istreambuf_iterator(file), std::istreambuf_iterator() }; + return DAMAGED_FILES.contains(MD5(bytes).hexdigest()); + } + std::vector FilesWithExtension(const std::string& extension) { std::vector files; const auto dir = ClientsDir(); @@ -41,7 +48,7 @@ namespace { if (!it->is_regular_file(error) || it->file_size(error) == 0) continue; auto fileExtension = it->path().extension().string(); std::ranges::transform(fileExtension, fileExtension.begin(), ::tolower); - if (fileExtension == extension && !DAMAGED_FILES.contains(it->path().filename().string())) files.push_back(it->path()); + if (fileExtension == extension && !IsDamaged(it->path())) files.push_back(it->path()); } std::ranges::sort(files); return files;