geopro/tests/data/store/test_chunked_volume_store.cpp

44 lines
1.7 KiB
C++

#include "data/store/ChunkedVolumeStore.hpp"
#include "core/algo/GprVolumeBuilder.hpp"
#include <gtest/gtest.h>
#include <filesystem>
#include <cstdint>
using namespace geopro::data;
namespace {
geopro::core::BuiltI16 makeBuilt(int n) {
geopro::core::BuiltI16 b;
b.vol = geopro::core::ScalarVolumeI16(n,n,n);
for (auto& v : b.vol.data()) v = 7; // 常量→高压缩比
b.quant = {1.0, 0.0}; b.origin={{0,0,0}}; b.spacing={{1,1,1}};
b.vminPhys=0; b.vmaxPhys=7;
return b;
}
}
TEST(ChunkedVolumeStore, RoundTripBrickAndCompresses) {
auto dir = (std::filesystem::temp_directory_path() / "gpr_store_test").string();
std::filesystem::remove_all(dir);
auto b = makeBuilt(128);
ChunkedVolumeStore::write(dir, b, 64);
auto m = ChunkedVolumeStore::readMeta(dir);
EXPECT_EQ(m.nx, 128); EXPECT_EQ(m.brick, 64);
ChunkedVolumeStore s(dir);
EXPECT_EQ(s.bricksX(), 2);
auto blk = s.readBrick(0,0,0);
EXPECT_EQ(blk.size(), 64u*64*64);
EXPECT_EQ(blk[0], 7);
auto dataSize = std::filesystem::file_size(std::filesystem::path(dir)/"data.bin");
EXPECT_LT(dataSize, 128u*128*128*2); // 压缩生效
std::filesystem::remove_all(dir);
}
TEST(ChunkedVolumeStore, EdgeBrickPartial) {
auto dir = (std::filesystem::temp_directory_path() / "gpr_store_edge").string();
std::filesystem::remove_all(dir);
auto b = makeBuilt(100); // 100 不整除 64 → 边缘块 36
ChunkedVolumeStore::write(dir, b, 64);
ChunkedVolumeStore s(dir);
EXPECT_EQ(s.bricksX(), 2); // ceil(100/64)=2
auto edge = s.readBrick(1,0,0); // x 方向边缘块,bw=36
EXPECT_EQ(edge.size(), 36u*64*64);
std::filesystem::remove_all(dir);
}