A52 (IGES face orientation closure, importer/exporter symmetric): - importer: apply_shell_orientation derives face.reversed = (514 ORIENTATION==0) XOR (186 SHELLFLAG==0); token_is_pure_int guards legacy "0HNAME"; convert_face reads 510 OUTERLOOPFLAG, convert_loop reads 508 ORIENTATION (diagnostics only); empty/void shells use their own SHELLFLAG - exporter: 514 writes per-face ORIENTATION (0 when reversed), 510 OUTERLOOPFLAG=1, 508 ORIENTATION from edge.reversed; 144 counts reversed trimmed faces only (no orientation field); 186 keeps "1,0" - test_iges_export 34 -> 43 tests (T1-T8, real corpus round-trips): occ__bug25415 vol_rel 0.9697 -> 8.30e-12, occ__bug22821_test 2.0 -> 0, PWB/31000/28366 stay ~0 A53 (IGES import zero-copy caches): - curve_cache_/surface_cache_ become unordered_map<int, shared_ptr<const NurbsCurve/NurbsSurface>>; hits share pointers, misses make_shared<const T>(std::move(...)); composite curves return pointers - split_params/params_of return std::string_view (zero-copy token slicing; tokens are substrings) - import_iges reads the file in one sized binary read (chunked fallback for >16GB or tellg failure) - V8 Motor_1.igs 3.40 -> 1.346 s, moteur_v8_asm.igs 9.27 -> 3.284 s; topology/model hashes unchanged A54/A55 (UTF-8 path leftovers): - A54: 13 foundation files, 17 open sites -> open_ifstream_utf8/open_ofstream_utf8; 9 UTF-8 cases - A55: 13 infra/plugin/capi/core files, 24+ sites (11 user-path sites in plugin_manager); 12 UTF-8 cases - Linux-only fixed paths (/sys,/proc,/etc/machine-id) and platform.cpp fopen wrapper intentionally kept Verification: 23 suites 918 passed / 0 failed; PR gate 1067/1067 (81.44 s); four KPI windows bit-identical (fixed 196/36, auto 196/36, band 8/0 and 8/0); 35 extra suites green; redline identical.
115 lines
3.7 KiB
C++
115 lines
3.7 KiB
C++
#include <gtest/gtest.h>
|
||
#include "vde/foundation/serializer.h"
|
||
#include "vde/foundation/utf8_path.h"
|
||
#include "vde/mesh/halfedge_mesh.h"
|
||
#include <cstdio>
|
||
#include <filesystem>
|
||
#include <stdexcept>
|
||
#include <string>
|
||
|
||
using namespace vde::foundation;
|
||
using namespace vde::mesh;
|
||
|
||
TEST(SerializerTest, SerializeDeserializeRoundtrip) {
|
||
HalfedgeMesh mesh;
|
||
mesh.add_vertex({0, 0, 0});
|
||
mesh.add_vertex({1, 0, 0});
|
||
mesh.add_vertex({0, 1, 0});
|
||
mesh.add_face({0, 1, 2});
|
||
|
||
auto data = BinarySerializer::serialize(mesh);
|
||
EXPECT_GT(data.size(), 0u);
|
||
|
||
auto restored = BinarySerializer::deserialize(data);
|
||
EXPECT_EQ(restored.num_vertices(), 3u);
|
||
EXPECT_EQ(restored.num_faces(), 1u);
|
||
}
|
||
|
||
TEST(SerializerTest, WriteReadFile) {
|
||
HalfedgeMesh mesh;
|
||
mesh.add_vertex({0, 0, 0});
|
||
mesh.add_vertex({1, 0, 0});
|
||
mesh.add_vertex({0, 1, 0});
|
||
mesh.add_face({0, 1, 2});
|
||
|
||
const std::string path = VDE_TEST_TEMP_DIR "test_vde_serializer.bin";
|
||
EXPECT_TRUE(BinarySerializer::write_file(path, mesh));
|
||
|
||
auto restored = BinarySerializer::read_file(path);
|
||
EXPECT_GT(restored.num_faces(), 0u);
|
||
EXPECT_GT(restored.num_vertices(), 0u);
|
||
|
||
std::remove(path.c_str());
|
||
}
|
||
|
||
TEST(SerializerTest, ReadFileNonexistentThrows) {
|
||
// VDE-1195: 缺失文件不得静默返回空网格
|
||
EXPECT_THROW(BinarySerializer::read_file(VDE_TEST_TEMP_DIR "no_such_vde_mesh.bin"),
|
||
std::runtime_error);
|
||
}
|
||
|
||
TEST(SerializerTest, DeserializeRejectsBadMagic) {
|
||
std::vector<uint8_t> junk(32, 0xAB);
|
||
EXPECT_THROW(BinarySerializer::deserialize(junk), std::runtime_error);
|
||
}
|
||
|
||
TEST(SerializerTest, DeserializeRejectsTruncatedBuffer) {
|
||
HalfedgeMesh mesh;
|
||
mesh.add_vertex({0, 0, 0});
|
||
mesh.add_vertex({1, 0, 0});
|
||
mesh.add_vertex({0, 1, 0});
|
||
mesh.add_face({0, 1, 2});
|
||
auto data = BinarySerializer::serialize(mesh);
|
||
data.resize(data.size() / 2); // 截断载荷
|
||
EXPECT_THROW(BinarySerializer::deserialize(data), std::runtime_error);
|
||
}
|
||
|
||
TEST(SerializerTest, SerializeEmptyMesh) {
|
||
HalfedgeMesh mesh;
|
||
auto data = BinarySerializer::serialize(mesh);
|
||
EXPECT_GT(data.size(), 0u); // at minimum has magic + header
|
||
}
|
||
|
||
TEST(SerializerTest, MagicAndVersion) {
|
||
EXPECT_NE(VDE_MAGIC, 0u);
|
||
EXPECT_EQ(VDE_FORMAT_VERSION, 1u);
|
||
}
|
||
|
||
TEST(SerializerTest, SerializedMeshStruct) {
|
||
SerializedMesh sm;
|
||
sm.vertex_count = 3;
|
||
sm.face_count = 1;
|
||
sm.vertices = {0, 0, 0, 1, 0, 0, 0, 1, 0};
|
||
sm.face_indices = {0, 1, 2};
|
||
sm.face_valence = {3};
|
||
|
||
EXPECT_EQ(sm.vertex_count, 3u);
|
||
EXPECT_EQ(sm.face_count, 1u);
|
||
EXPECT_EQ(sm.vertices.size(), 9u);
|
||
}
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// Wave21 A54:UTF-8(中文/非 ASCII)路径写读往返
|
||
// ═══════════════════════════════════════════════════════════
|
||
TEST(SerializerTest, Utf8PathWriteReadFile) {
|
||
HalfedgeMesh mesh;
|
||
mesh.add_vertex({0, 0, 0});
|
||
mesh.add_vertex({1, 0, 0});
|
||
mesh.add_vertex({0, 1, 0});
|
||
mesh.add_face({0, 1, 2});
|
||
|
||
const std::string path = std::string(VDE_TEST_TEMP_DIR) + "test_vde_网格_①.bin";
|
||
std::error_code ec;
|
||
std::filesystem::remove(path_from_utf8(path), ec);
|
||
|
||
ASSERT_TRUE(BinarySerializer::write_file(path, mesh));
|
||
EXPECT_TRUE(std::filesystem::exists(path_from_utf8(path)));
|
||
|
||
const HalfedgeMesh restored = BinarySerializer::read_file(path);
|
||
EXPECT_EQ(restored.num_vertices(), 3u);
|
||
EXPECT_EQ(restored.num_faces(), 1u);
|
||
|
||
std::filesystem::remove(path_from_utf8(path), ec);
|
||
EXPECT_FALSE(std::filesystem::exists(path_from_utf8(path)));
|
||
}
|