932 lines
38 KiB
C++
932 lines
38 KiB
C++
// WP-P4-34 / P4-47 官方 DXF 插件写能力测试(确定性 mock 宿主 + 真实 C ABI 动态加载)。
|
||
//
|
||
// 覆盖:
|
||
// 1) vde_plugin_query / init / describe:id、能力(read+write)、extensions、ABI;
|
||
// 2) 写出(P4-34):host body_tessellate → ASCII DXF R12 3DFACE(HEADER $ACADVER AC1009、
|
||
// TABLES/ENTITIES、每三角一个 3DFACE,第 4 点=第 3 点);write_file 与 write_memory 字节一致;
|
||
// 3) 分层/颜色(P4-47):每 body 独立 LAYER(默认 BODY_0/BODY_1…,可被 VDE_DXF_BODY_NAMES 覆盖)、
|
||
// ACI 颜色 1–7 循环、LAYER 表记录(70/62/6 CONTINUOUS)、3DFACE 组码 8=layer + 62=color;
|
||
// 名称净化/31 字符截断/重名唯一化;body 数上限 10000;
|
||
// 4) VDE_DXF_WRITE_LAYERS=0 回退旧行为(全部 layer 0、无 62 组码、LAYER 表仅 0);
|
||
// 5) 写后由本插件回读(3DFACE 三角网格)验证往返;读能力保持(read_memory 仍 UNSUPPORTED);
|
||
// 6) 错误路径:空实体、空三角化、tessellate 失败、非法路径、宿主能力缺失、body 数超限、参数校验;
|
||
// 7) 组码结构:pairs 解析校验 SECTION/HEADER/$ACADVER/ENTITIES/EOF 与 3DFACE 坐标组码。
|
||
//
|
||
// 本测试只依赖纯 C ABI(vde_plugin_api.h)+ gtest,不链接内核。
|
||
#include <gtest/gtest.h>
|
||
|
||
#include <algorithm>
|
||
#include <cctype>
|
||
#include <cmath>
|
||
#include <chrono>
|
||
#include <cstdint>
|
||
#include <cstdlib>
|
||
#include <cstring>
|
||
#include <fstream>
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
#if defined(_WIN32)
|
||
#ifndef NOMINMAX
|
||
#define NOMINMAX
|
||
#endif
|
||
#include <windows.h>
|
||
#else
|
||
#include <dlfcn.h>
|
||
#endif
|
||
|
||
#include "vde/plugin/vde_plugin_api.h"
|
||
|
||
#ifndef VDE_PLUGIN_OFFICIAL_DIR
|
||
#define VDE_PLUGIN_OFFICIAL_DIR ""
|
||
#endif
|
||
#ifndef VDE_TEST_TEMP_DIR
|
||
#define VDE_TEST_TEMP_DIR ""
|
||
#endif
|
||
|
||
namespace {
|
||
|
||
constexpr const char* kPluginId = "com.vde.official.dxf";
|
||
constexpr std::size_t kMaxBodyCount = 10000;
|
||
constexpr std::size_t kMaxLayerNameLength = 31;
|
||
|
||
#if defined(_WIN32)
|
||
constexpr const char* kPluginRelativePath = "/dxf/vde_official_dxf.dll";
|
||
#elif defined(__APPLE__)
|
||
constexpr const char* kPluginRelativePath = "/dxf/libvde_official_dxf.dylib";
|
||
#else
|
||
constexpr const char* kPluginRelativePath = "/dxf/libvde_official_dxf.so";
|
||
#endif
|
||
|
||
// ── 动态加载(与宿主相同的纯 C ABI 入口)────────────────────────────
|
||
#if defined(_WIN32)
|
||
using LibraryHandle = HMODULE;
|
||
using RawSymbol = void (*)();
|
||
LibraryHandle open_library(const char* path) { return ::LoadLibraryA(path); }
|
||
RawSymbol find_symbol(LibraryHandle library, const char* name) {
|
||
return reinterpret_cast<RawSymbol>(::GetProcAddress(library, name));
|
||
}
|
||
void close_library(LibraryHandle library) {
|
||
if (library) ::FreeLibrary(library);
|
||
}
|
||
#else
|
||
using LibraryHandle = void*;
|
||
using RawSymbol = void (*)();
|
||
LibraryHandle open_library(const char* path) {
|
||
return ::dlopen(path, RTLD_NOW | RTLD_LOCAL);
|
||
}
|
||
RawSymbol find_symbol(LibraryHandle library, const char* name) {
|
||
return reinterpret_cast<RawSymbol>(::dlsym(library, name));
|
||
}
|
||
void close_library(LibraryHandle library) {
|
||
if (library) ::dlclose(library);
|
||
}
|
||
#endif
|
||
|
||
struct PluginApi {
|
||
LibraryHandle library = nullptr;
|
||
VdePluginQueryFn query = nullptr;
|
||
VdePluginInitFn init = nullptr;
|
||
VdePluginShutdownFn shutdown = nullptr;
|
||
const VdeFormatPlugin* format = nullptr;
|
||
|
||
~PluginApi() { close(); }
|
||
|
||
bool open(std::string* error) {
|
||
const std::string path = std::string(VDE_PLUGIN_OFFICIAL_DIR) + kPluginRelativePath;
|
||
library = open_library(path.c_str());
|
||
if (!library) {
|
||
if (error) *error = "无法加载插件动态库: " + path;
|
||
return false;
|
||
}
|
||
query = reinterpret_cast<VdePluginQueryFn>(find_symbol(library, "vde_plugin_query"));
|
||
init = reinterpret_cast<VdePluginInitFn>(find_symbol(library, "vde_plugin_init"));
|
||
shutdown = reinterpret_cast<VdePluginShutdownFn>(
|
||
find_symbol(library, "vde_plugin_shutdown"));
|
||
if (!query || !init || !shutdown) {
|
||
if (error) *error = "插件缺少 vde_plugin_query/init/shutdown 导出: " + path;
|
||
close();
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void close() {
|
||
if (library) {
|
||
close_library(library);
|
||
library = nullptr;
|
||
}
|
||
query = nullptr;
|
||
init = nullptr;
|
||
shutdown = nullptr;
|
||
format = nullptr;
|
||
}
|
||
};
|
||
|
||
// ── 确定性 mock 宿主 ────────────────────────────────────────────────
|
||
std::string g_last_error;
|
||
int g_live_bodies = 0;
|
||
// P4-65 纯格式化基准:fast_tessellate 复用 body 内缓存 mesh,下列指针由
|
||
// mock_free_buffer 跳过释放(模拟宿主无 tessellate 开销的格式化基准)。
|
||
const void* g_fast_positions = nullptr;
|
||
const void* g_fast_indices = nullptr;
|
||
|
||
struct MockBody {
|
||
std::vector<double> positions; // 3×N
|
||
std::vector<std::uint32_t> indices; // 3×T
|
||
bool fail_tessellate = false;
|
||
bool empty_tessellate = false;
|
||
bool fast_tessellate = false;
|
||
};
|
||
|
||
MockBody* as_mock(VdeBody body) { return reinterpret_cast<MockBody*>(body); }
|
||
|
||
void mock_log(int, const char*) {}
|
||
void mock_set_error(const char* message) { g_last_error = message ? message : ""; }
|
||
void* mock_alloc(std::size_t size) { return std::malloc(size == 0 ? 1 : size); }
|
||
void* mock_realloc(void* pointer, std::size_t size) {
|
||
return std::realloc(pointer, size == 0 ? 1 : size);
|
||
}
|
||
void mock_free(void* pointer) { std::free(pointer); }
|
||
void mock_free_buffer(void* pointer) {
|
||
if (pointer == nullptr) return;
|
||
if (pointer == g_fast_positions || pointer == g_fast_indices) return;
|
||
std::free(pointer);
|
||
}
|
||
|
||
VdeBody mock_body_from_mesh(const double* positions, std::size_t num_vertices,
|
||
const std::uint32_t* indices, std::size_t num_triangles) {
|
||
if (!positions || num_vertices == 0) {
|
||
g_last_error = "mock body_from_mesh: 空网格";
|
||
return nullptr;
|
||
}
|
||
if (num_triangles > 0 && !indices) {
|
||
g_last_error = "mock body_from_mesh: 缺少索引";
|
||
return nullptr;
|
||
}
|
||
for (std::size_t i = 0; i < num_triangles * 3u; ++i) {
|
||
if (static_cast<std::size_t>(indices[i]) >= num_vertices) {
|
||
g_last_error = "mock body_from_mesh: 索引越界";
|
||
return nullptr;
|
||
}
|
||
}
|
||
auto* body = new MockBody();
|
||
body->positions.assign(positions, positions + num_vertices * 3u);
|
||
if (num_triangles > 0) body->indices.assign(indices, indices + num_triangles * 3u);
|
||
++g_live_bodies;
|
||
return reinterpret_cast<VdeBody>(body);
|
||
}
|
||
|
||
void mock_body_destroy(VdeBody handle) {
|
||
auto* body = as_mock(handle);
|
||
if (!body) return;
|
||
delete body;
|
||
--g_live_bodies;
|
||
}
|
||
|
||
int mock_body_tessellate(VdeBody handle, double, VdeMeshData* out) {
|
||
if (!out || !handle) {
|
||
g_last_error = "mock body_tessellate: 参数为空";
|
||
return VDE_PLUGIN_ERR_INVALID_ARG;
|
||
}
|
||
MockBody* body = as_mock(handle);
|
||
out->positions = nullptr;
|
||
out->num_vertices = 0;
|
||
out->indices = nullptr;
|
||
out->num_triangles = 0;
|
||
out->normals = nullptr;
|
||
if (body->fail_tessellate) {
|
||
g_last_error = "mock body_tessellate: 注入失败";
|
||
return VDE_PLUGIN_ERR_INTERNAL;
|
||
}
|
||
if (body->empty_tessellate || body->indices.empty()) return VDE_PLUGIN_OK;
|
||
if (body->fast_tessellate) { // P4-65:返回 body 缓存 mesh,零拷贝/零 tessellate
|
||
out->positions = const_cast<double*>(body->positions.data());
|
||
out->num_vertices = body->positions.size() / 3u;
|
||
out->indices = const_cast<std::uint32_t*>(body->indices.data());
|
||
out->num_triangles = body->indices.size() / 3u;
|
||
return VDE_PLUGIN_OK;
|
||
}
|
||
const std::size_t triangles = body->indices.size() / 3u;
|
||
const std::size_t vertices = triangles * 3u;
|
||
auto* positions = static_cast<double*>(std::malloc(vertices * 3u * sizeof(double)));
|
||
auto* indices = static_cast<std::uint32_t*>(std::malloc(vertices * sizeof(std::uint32_t)));
|
||
if (!positions || !indices) {
|
||
std::free(positions);
|
||
std::free(indices);
|
||
g_last_error = "mock body_tessellate: 内存不足";
|
||
return VDE_PLUGIN_ERR_BUFFER;
|
||
}
|
||
for (std::size_t t = 0; t < triangles; ++t) {
|
||
for (std::size_t k = 0; k < 3; ++k) {
|
||
const std::uint32_t source = body->indices[3u * t + k];
|
||
positions[(3u * t + k) * 3u + 0u] = body->positions[3u * source + 0u];
|
||
positions[(3u * t + k) * 3u + 1u] = body->positions[3u * source + 1u];
|
||
positions[(3u * t + k) * 3u + 2u] = body->positions[3u * source + 2u];
|
||
indices[3u * t + k] = static_cast<std::uint32_t>(3u * t + k);
|
||
}
|
||
}
|
||
out->positions = positions;
|
||
out->num_vertices = vertices;
|
||
out->indices = indices;
|
||
out->num_triangles = triangles;
|
||
return VDE_PLUGIN_OK;
|
||
}
|
||
|
||
VdePluginHost make_mock_host() {
|
||
VdePluginHost host{};
|
||
host.struct_size = static_cast<std::uint32_t>(sizeof(VdePluginHost));
|
||
host.abi_major = VDE_PLUGIN_ABI_MAJOR;
|
||
host.abi_minor = VDE_PLUGIN_ABI_MINOR;
|
||
host.kernel_version = "mock";
|
||
host.alloc = &mock_alloc;
|
||
host.realloc = &mock_realloc;
|
||
host.free = &mock_free;
|
||
host.log = &mock_log;
|
||
host.set_error = &mock_set_error;
|
||
host.body_destroy = &mock_body_destroy;
|
||
host.free_buffer = &mock_free_buffer;
|
||
host.body_from_mesh = &mock_body_from_mesh;
|
||
host.body_tessellate = &mock_body_tessellate;
|
||
return host;
|
||
}
|
||
|
||
// ── 环境变量 / DXF pairs 辅助(测试用)──────────────────────────────
|
||
bool set_env(const char* name, const char* value) {
|
||
#if defined(_WIN32)
|
||
return _putenv_s(name, value != nullptr ? value : "") == 0;
|
||
#else
|
||
return value != nullptr ? (setenv(name, value, 1) == 0) : (unsetenv(name) == 0);
|
||
#endif
|
||
}
|
||
void clear_env(const char* name) { set_env(name, nullptr); }
|
||
|
||
struct DxfPair {
|
||
int code = 0;
|
||
std::string value;
|
||
};
|
||
|
||
std::string trim_test(const std::string& text) {
|
||
std::size_t begin = 0, end = text.size();
|
||
while (begin < end && std::isspace(static_cast<unsigned char>(text[begin]))) ++begin;
|
||
while (end > begin && std::isspace(static_cast<unsigned char>(text[end - 1]))) --end;
|
||
return text.substr(begin, end - begin);
|
||
}
|
||
|
||
std::vector<DxfPair> parse_pairs(const std::string& text) {
|
||
std::vector<DxfPair> pairs;
|
||
std::vector<std::string> lines;
|
||
std::size_t pos = 0;
|
||
while (pos <= text.size()) {
|
||
const std::size_t line_end = text.find('\n', pos);
|
||
if (line_end == std::string::npos) {
|
||
lines.push_back(trim_test(text.substr(pos)));
|
||
break;
|
||
}
|
||
lines.push_back(trim_test(text.substr(pos, line_end - pos)));
|
||
pos = line_end + 1;
|
||
}
|
||
for (std::size_t i = 0; i + 1 < lines.size(); i += 2) {
|
||
DxfPair pair;
|
||
pair.code = std::atoi(lines[i].c_str());
|
||
pair.value = lines[i + 1];
|
||
pairs.push_back(std::move(pair));
|
||
}
|
||
return pairs;
|
||
}
|
||
|
||
std::size_t count_pairs(const std::vector<DxfPair>& pairs, int code,
|
||
const std::string& value) {
|
||
std::size_t count = 0;
|
||
for (const auto& pair : pairs) {
|
||
if (pair.code == code && pair.value == value) ++count;
|
||
}
|
||
return count;
|
||
}
|
||
|
||
bool has_pair(const std::vector<DxfPair>& pairs, int code, const std::string& value) {
|
||
for (const auto& pair : pairs) {
|
||
if (pair.code == code && pair.value == value) return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
std::string pair_value(const std::vector<DxfPair>& pairs, int code) {
|
||
for (const auto& pair : pairs) {
|
||
if (pair.code == code) return pair.value;
|
||
}
|
||
return std::string();
|
||
}
|
||
|
||
/// LAYER 表记录中的图层名(跳过 TABLE 段的 "2/LAYER" 表头)。
|
||
std::vector<std::string> layer_table_names(const std::vector<DxfPair>& pairs) {
|
||
std::vector<std::string> names;
|
||
bool in_layer_table = false;
|
||
for (std::size_t i = 0; i < pairs.size(); ++i) {
|
||
const DxfPair& pair = pairs[i];
|
||
if (pair.code == 0 && pair.value == "TABLE") {
|
||
in_layer_table = (i + 1 < pairs.size() && pairs[i + 1].code == 2 &&
|
||
pairs[i + 1].value == "LAYER");
|
||
continue;
|
||
}
|
||
if (pair.code == 0 && pair.value == "LAYER" && in_layer_table) {
|
||
if (i + 1 < pairs.size() && pairs[i + 1].code == 2)
|
||
names.push_back(pairs[i + 1].value);
|
||
continue;
|
||
}
|
||
if (pair.code == 0 && pair.value == "ENDTAB") in_layer_table = false;
|
||
}
|
||
return names;
|
||
}
|
||
|
||
std::string layer_table_count(const std::vector<DxfPair>& pairs) {
|
||
bool in_layer_table = false;
|
||
for (std::size_t i = 0; i < pairs.size(); ++i) {
|
||
const DxfPair& pair = pairs[i];
|
||
if (pair.code == 0 && pair.value == "TABLE") {
|
||
in_layer_table = (i + 1 < pairs.size() && pairs[i + 1].code == 2 &&
|
||
pairs[i + 1].value == "LAYER");
|
||
continue;
|
||
}
|
||
if (in_layer_table && pair.code == 70) return pair.value;
|
||
}
|
||
return std::string();
|
||
}
|
||
|
||
struct EntityLayer {
|
||
std::string layer;
|
||
std::string color;
|
||
};
|
||
|
||
/// 每个 3DFACE 的图层/颜色(按实体顺序)。
|
||
std::vector<EntityLayer> entity_layers(const std::vector<DxfPair>& pairs) {
|
||
std::vector<EntityLayer> entities;
|
||
bool in_3dface = false;
|
||
EntityLayer current;
|
||
for (const auto& pair : pairs) {
|
||
if (pair.code == 0) {
|
||
if (in_3dface) {
|
||
entities.push_back(current);
|
||
in_3dface = false;
|
||
}
|
||
if (pair.value == "3DFACE") {
|
||
in_3dface = true;
|
||
current = EntityLayer{};
|
||
}
|
||
continue;
|
||
}
|
||
if (in_3dface && pair.code == 8) current.layer = pair.value;
|
||
if (in_3dface && pair.code == 62) current.color = pair.value;
|
||
}
|
||
if (in_3dface) entities.push_back(current);
|
||
return entities;
|
||
}
|
||
|
||
bool is_allowed_layer_name(const std::string& name) {
|
||
if (name.empty() || name.size() > kMaxLayerNameLength) return false;
|
||
for (const char c : name) {
|
||
const bool allowed = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
|
||
(c >= '0' && c <= '9') || c == '_' || c == '-' || c == '.';
|
||
if (!allowed) return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
const char* kProxyDxf =
|
||
"0\nSECTION\n2\nENTITIES\n0\n3DFACE\n8\n0\n"
|
||
"10\n0\n20\n0\n30\n0\n11\n1\n21\n0\n31\n0\n12\n0\n22\n1\n32\n0\n"
|
||
"13\n0\n23\n1\n33\n0\n0\nENDSEC\n0\nEOF\n";
|
||
|
||
std::string temp_path(const char* name) { return std::string(VDE_TEST_TEMP_DIR) + name; }
|
||
|
||
std::string read_text_file(const std::string& path) {
|
||
std::ifstream in(path, std::ios::binary);
|
||
if (!in.good()) return {};
|
||
return std::string((std::istreambuf_iterator<char>(in)),
|
||
std::istreambuf_iterator<char>());
|
||
}
|
||
|
||
void remove_file(const std::string& path) { std::remove(path.c_str()); }
|
||
|
||
// ── 测试夹具 ────────────────────────────────────────────────────────
|
||
class DxfWriteFixture : public ::testing::Test {
|
||
protected:
|
||
void SetUp() override {
|
||
g_last_error.clear();
|
||
g_live_bodies = 0;
|
||
clear_env("VDE_DXF_WRITE_LAYERS");
|
||
clear_env("VDE_DXF_BODY_NAMES");
|
||
host_ = make_mock_host();
|
||
ASSERT_TRUE(api_.open(&load_error_)) << load_error_;
|
||
VdePluginInfo info{};
|
||
info.struct_size = static_cast<std::uint32_t>(sizeof(VdePluginInfo));
|
||
ASSERT_EQ(api_.query(VDE_PLUGIN_ABI_MAJOR, &info), VDE_PLUGIN_OK);
|
||
ASSERT_STREQ(info.id, kPluginId);
|
||
VdePluginRegistration registration{};
|
||
registration.struct_size = static_cast<std::uint32_t>(sizeof(VdePluginRegistration));
|
||
ASSERT_EQ(api_.init(&host_, ®istration), VDE_PLUGIN_OK) << g_last_error;
|
||
ASSERT_EQ(registration.kind, VDE_PLUGIN_KIND_FORMAT);
|
||
ASSERT_NE(registration.format, nullptr);
|
||
format_ = registration.format;
|
||
}
|
||
|
||
void TearDown() override {
|
||
clear_env("VDE_DXF_WRITE_LAYERS");
|
||
clear_env("VDE_DXF_BODY_NAMES");
|
||
if (api_.shutdown) api_.shutdown();
|
||
api_.close();
|
||
EXPECT_EQ(g_live_bodies, 0) << "mock 实体未全部销毁";
|
||
}
|
||
|
||
MockBody make_triangle(double offset = 0.0) {
|
||
MockBody body;
|
||
body.positions = {0.0 + offset, 0.0, 0.0, 1.0 + offset, 0.0, 0.0,
|
||
0.0 + offset, 1.0, 0.0};
|
||
body.indices = {0u, 1u, 2u};
|
||
return body;
|
||
}
|
||
|
||
MockBody make_quad() {
|
||
MockBody body;
|
||
body.positions = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0};
|
||
body.indices = {0u, 1u, 2u, 0u, 2u, 3u};
|
||
return body;
|
||
}
|
||
|
||
VdeBody make_body(const MockBody& source) {
|
||
return host_.body_from_mesh(source.positions.data(),
|
||
source.positions.size() / 3u,
|
||
source.indices.data(), source.indices.size() / 3u);
|
||
}
|
||
|
||
std::vector<VdeBody> make_triangle_bodies(std::size_t count) {
|
||
std::vector<VdeBody> bodies;
|
||
bodies.reserve(count);
|
||
const MockBody triangle = make_triangle();
|
||
for (std::size_t i = 0; i < count; ++i) bodies.push_back(make_body(triangle));
|
||
return bodies;
|
||
}
|
||
|
||
void destroy_bodies(std::vector<VdeBody>& bodies) {
|
||
for (VdeBody body : bodies) host_.body_destroy(body);
|
||
bodies.clear();
|
||
}
|
||
|
||
std::string write_memory_text(const std::vector<VdeBody>& bodies) {
|
||
VdeBuffer buffer{};
|
||
g_last_error.clear();
|
||
EXPECT_EQ(format_->write_memory(&host_, bodies.data(), bodies.size(), &buffer),
|
||
VDE_PLUGIN_OK) << g_last_error;
|
||
if (buffer.data == nullptr) return std::string();
|
||
const std::string text(static_cast<const char*>(buffer.data), buffer.size);
|
||
host_.free(buffer.data);
|
||
return text;
|
||
}
|
||
|
||
MockBody make_grid(std::size_t cells_x, std::size_t cells_y) {
|
||
MockBody body;
|
||
const std::size_t nx = cells_x + 1;
|
||
const std::size_t ny = cells_y + 1;
|
||
body.positions.reserve(nx * ny * 3);
|
||
for (std::size_t y = 0; y < ny; ++y) {
|
||
for (std::size_t x = 0; x < nx; ++x) {
|
||
body.positions.push_back(static_cast<double>(x) * 0.001);
|
||
body.positions.push_back(static_cast<double>(y) * 0.001);
|
||
body.positions.push_back(0.0);
|
||
}
|
||
}
|
||
body.indices.reserve(cells_x * cells_y * 6);
|
||
for (std::size_t y = 0; y < cells_y; ++y) {
|
||
for (std::size_t x = 0; x < cells_x; ++x) {
|
||
const std::uint32_t i0 = static_cast<std::uint32_t>(y * nx + x);
|
||
const std::uint32_t i1 = i0 + 1;
|
||
const std::uint32_t i2 = static_cast<std::uint32_t>((y + 1) * nx + x);
|
||
const std::uint32_t i3 = i2 + 1;
|
||
body.indices.push_back(i0);
|
||
body.indices.push_back(i1);
|
||
body.indices.push_back(i2);
|
||
body.indices.push_back(i1);
|
||
body.indices.push_back(i3);
|
||
body.indices.push_back(i2);
|
||
}
|
||
}
|
||
return body;
|
||
}
|
||
|
||
PluginApi api_;
|
||
std::string load_error_;
|
||
VdePluginHost host_{};
|
||
const VdeFormatPlugin* format_ = nullptr;
|
||
};
|
||
|
||
// P4-63 大模型基准:100k 三角 write_memory/write_file 字节一致 + 宽松时间上限。
|
||
TEST_F(DxfWriteFixture, LargeModelStreamingBytesEqualAndFast) {
|
||
MockBody grid = make_grid(200, 250); // 100,000 三角形
|
||
std::vector<VdeBody> bodies{make_body(grid)};
|
||
ASSERT_NE(bodies[0], nullptr) << g_last_error;
|
||
using Clock = std::chrono::steady_clock;
|
||
const auto memory_begin = Clock::now();
|
||
const std::string memory_text = write_memory_text(bodies);
|
||
const auto memory_end = Clock::now();
|
||
ASSERT_FALSE(memory_text.empty());
|
||
const std::string path = temp_path("p463_dxf_large.dxf");
|
||
const auto file_begin = Clock::now();
|
||
ASSERT_EQ(format_->write_file(&host_, path.c_str(), bodies.data(), bodies.size()),
|
||
VDE_PLUGIN_OK) << g_last_error;
|
||
const auto file_end = Clock::now();
|
||
const std::string file_text = read_text_file(path);
|
||
remove_file(path);
|
||
destroy_bodies(bodies);
|
||
const auto memory_ms =
|
||
std::chrono::duration_cast<std::chrono::milliseconds>(memory_end - memory_begin).count();
|
||
const auto file_ms =
|
||
std::chrono::duration_cast<std::chrono::milliseconds>(file_end - file_begin).count();
|
||
std::cout << "[perf] DXF 100k tris: memory=" << memory_ms << "ms file=" << file_ms
|
||
<< "ms bytes=" << memory_text.size() << std::endl;
|
||
EXPECT_EQ(file_text, memory_text) << "write_file 与 write_memory 大模型字节应一致";
|
||
EXPECT_GT(memory_text.size(), 8u * 1024u * 1024u);
|
||
EXPECT_LT(memory_ms, 20000);
|
||
EXPECT_LT(file_ms, 20000);
|
||
}
|
||
|
||
// P4-65 纯格式化基准(排除 host tessellate):fast_tessellate 直接返回缓存 mesh。
|
||
TEST_F(DxfWriteFixture, PureFormattingBenchmarkExcludingTessellate) {
|
||
MockBody grid = make_grid(158, 158); // 49,928 三角形
|
||
std::vector<VdeBody> bodies{make_body(grid)};
|
||
ASSERT_NE(bodies[0], nullptr) << g_last_error;
|
||
MockBody* mock = as_mock(bodies[0]);
|
||
mock->fast_tessellate = true;
|
||
g_fast_positions = mock->positions.data();
|
||
g_fast_indices = mock->indices.data();
|
||
using Clock = std::chrono::steady_clock;
|
||
const auto memory_begin = Clock::now();
|
||
const std::string memory_text = write_memory_text(bodies);
|
||
const auto memory_end = Clock::now();
|
||
const std::string path = temp_path("p465_dxf_pure.dxf");
|
||
const auto file_begin = Clock::now();
|
||
ASSERT_EQ(format_->write_file(&host_, path.c_str(), bodies.data(), bodies.size()),
|
||
VDE_PLUGIN_OK) << g_last_error;
|
||
const auto file_end = Clock::now();
|
||
const std::string file_text = read_text_file(path);
|
||
remove_file(path);
|
||
g_fast_positions = nullptr;
|
||
g_fast_indices = nullptr;
|
||
destroy_bodies(bodies);
|
||
const auto memory_ms =
|
||
std::chrono::duration_cast<std::chrono::milliseconds>(memory_end - memory_begin).count();
|
||
const auto file_ms =
|
||
std::chrono::duration_cast<std::chrono::milliseconds>(file_end - file_begin).count();
|
||
std::cout << "[perf-pure] DXF 50k tris: memory=" << memory_ms << "ms file=" << file_ms
|
||
<< "ms bytes=" << memory_text.size() << std::endl;
|
||
EXPECT_EQ(file_text, memory_text) << "纯格式化路径 write_file 与 write_memory 字节应一致";
|
||
EXPECT_GT(memory_text.size(), 1024u * 1024u);
|
||
EXPECT_LT(memory_ms, 20000);
|
||
EXPECT_LT(file_ms, 20000);
|
||
}
|
||
|
||
} // namespace
|
||
|
||
// ── 1. 元信息 / 注册 ───────────────────────────────────────────────
|
||
TEST_F(DxfWriteFixture, QueryAndRegistrationMetadata) {
|
||
VdePluginInfo info{};
|
||
info.struct_size = static_cast<std::uint32_t>(sizeof(VdePluginInfo));
|
||
ASSERT_EQ(api_.query(VDE_PLUGIN_ABI_MAJOR, &info), VDE_PLUGIN_OK);
|
||
EXPECT_STREQ(info.id, "com.vde.official.dxf");
|
||
EXPECT_EQ(info.kind, VDE_PLUGIN_KIND_FORMAT);
|
||
EXPECT_EQ(info.abi_major, VDE_PLUGIN_ABI_MAJOR);
|
||
EXPECT_STREQ(info.capabilities, "format:dxf.read;format:dxf.write");
|
||
ASSERT_NE(format_, nullptr);
|
||
EXPECT_STREQ(format_->format_id, "dxf");
|
||
EXPECT_STREQ(format_->extensions, ".dxf");
|
||
EXPECT_NE(format_->probe, nullptr);
|
||
EXPECT_NE(format_->read_file, nullptr);
|
||
EXPECT_NE(format_->write_file, nullptr);
|
||
EXPECT_NE(format_->write_memory, nullptr);
|
||
ASSERT_NE(format_->describe, nullptr);
|
||
const std::string describe = format_->describe();
|
||
EXPECT_NE(describe.find("write"), std::string::npos) << describe;
|
||
EXPECT_NE(describe.find("3DFACE"), std::string::npos) << describe;
|
||
EXPECT_NE(describe.find("layer"), std::string::npos) << describe;
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, ProbeStillWorks) {
|
||
EXPECT_EQ(format_->probe(kProxyDxf, std::strlen(kProxyDxf)), 90);
|
||
const char* non_dxf = "hello world";
|
||
EXPECT_EQ(format_->probe(non_dxf, std::strlen(non_dxf)), 0);
|
||
EXPECT_EQ(format_->probe(nullptr, 0), 0);
|
||
}
|
||
|
||
// ── 2. 写出结构 ────────────────────────────────────────────────────
|
||
TEST_F(DxfWriteFixture, WriteMemorySingleTriangleStructure) {
|
||
std::vector<VdeBody> bodies{make_body(make_triangle())};
|
||
ASSERT_NE(bodies[0], nullptr) << g_last_error;
|
||
const std::string text = write_memory_text(bodies);
|
||
ASSERT_FALSE(text.empty());
|
||
destroy_bodies(bodies);
|
||
|
||
const std::vector<DxfPair> pairs = parse_pairs(text);
|
||
ASSERT_FALSE(pairs.empty());
|
||
EXPECT_EQ(pairs[0].code, 0);
|
||
EXPECT_EQ(pairs[0].value, "SECTION");
|
||
EXPECT_EQ(pairs[1].code, 2);
|
||
EXPECT_EQ(pairs[1].value, "HEADER");
|
||
EXPECT_TRUE(has_pair(pairs, 9, "$ACADVER"));
|
||
EXPECT_TRUE(has_pair(pairs, 1, "AC1009"));
|
||
EXPECT_TRUE(has_pair(pairs, 2, "TABLES"));
|
||
const std::vector<std::string> layer_names = layer_table_names(pairs);
|
||
ASSERT_EQ(layer_names.size(), 2u) << "应为 LAYER 0 + BODY_0";
|
||
EXPECT_EQ(layer_names[0], "0");
|
||
EXPECT_EQ(layer_names[1], "BODY_0");
|
||
EXPECT_EQ(layer_table_count(pairs), "2");
|
||
const std::vector<EntityLayer> entities = entity_layers(pairs);
|
||
ASSERT_EQ(entities.size(), 1u);
|
||
EXPECT_EQ(entities[0].layer, "BODY_0");
|
||
EXPECT_EQ(entities[0].color, "1");
|
||
EXPECT_EQ(count_pairs(pairs, 0, "3DFACE"), 1u);
|
||
EXPECT_EQ(count_pairs(pairs, 0, "EOF"), 1u);
|
||
EXPECT_EQ(pairs.back().code, 0);
|
||
EXPECT_EQ(pairs.back().value, "EOF");
|
||
for (int code : {10, 20, 30, 11, 21, 31, 12, 22, 32, 13, 23, 33}) {
|
||
bool found = false;
|
||
for (const auto& pair : pairs)
|
||
if (pair.code == code) found = true;
|
||
EXPECT_TRUE(found) << "缺少 3DFACE 组码 " << code;
|
||
}
|
||
EXPECT_EQ(pair_value(pairs, 13), pair_value(pairs, 12));
|
||
EXPECT_EQ(pair_value(pairs, 23), pair_value(pairs, 22));
|
||
EXPECT_EQ(pair_value(pairs, 33), pair_value(pairs, 32));
|
||
EXPECT_EQ(pair_value(pairs, 10), "0");
|
||
EXPECT_EQ(pair_value(pairs, 11), "1");
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, WriteMemoryMultipleBodiesLayersAndColors) {
|
||
std::vector<VdeBody> bodies{make_body(make_triangle()), make_body(make_quad())};
|
||
ASSERT_NE(bodies[0], nullptr);
|
||
ASSERT_NE(bodies[1], nullptr);
|
||
const std::string text = write_memory_text(bodies);
|
||
destroy_bodies(bodies);
|
||
const std::vector<DxfPair> pairs = parse_pairs(text);
|
||
|
||
EXPECT_EQ(count_pairs(pairs, 0, "3DFACE"), 3u);
|
||
EXPECT_EQ(count_pairs(pairs, 2, "ENTITIES"), 1u);
|
||
const std::vector<std::string> layer_names = layer_table_names(pairs);
|
||
ASSERT_EQ(layer_names.size(), 3u);
|
||
EXPECT_EQ(layer_names[0], "0");
|
||
EXPECT_EQ(layer_names[1], "BODY_0");
|
||
EXPECT_EQ(layer_names[2], "BODY_1");
|
||
EXPECT_EQ(layer_table_count(pairs), "3");
|
||
const std::vector<EntityLayer> entities = entity_layers(pairs);
|
||
ASSERT_EQ(entities.size(), 3u);
|
||
EXPECT_EQ(entities[0].layer, "BODY_0");
|
||
EXPECT_EQ(entities[1].layer, "BODY_1");
|
||
EXPECT_EQ(entities[2].layer, "BODY_1");
|
||
EXPECT_EQ(entities[0].color, "1");
|
||
EXPECT_EQ(entities[1].color, "2");
|
||
EXPECT_EQ(entities[2].color, "2");
|
||
EXPECT_EQ(count_pairs(pairs, 6, "CONTINUOUS"), 3u);
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, AciColorsCycleOneToSeven) {
|
||
std::vector<VdeBody> bodies = make_triangle_bodies(9);
|
||
for (const VdeBody body : bodies) ASSERT_NE(body, nullptr) << g_last_error;
|
||
const std::string text = write_memory_text(bodies);
|
||
destroy_bodies(bodies);
|
||
const std::vector<DxfPair> pairs = parse_pairs(text);
|
||
const std::vector<EntityLayer> entities = entity_layers(pairs);
|
||
ASSERT_EQ(entities.size(), 9u);
|
||
for (std::size_t i = 0; i < entities.size(); ++i) {
|
||
EXPECT_EQ(entities[i].color, std::to_string(1 + (i % 7))) << "body " << i;
|
||
EXPECT_EQ(entities[i].layer, "BODY_" + std::to_string(i));
|
||
}
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, WriteFileEqualsWriteMemory) {
|
||
std::vector<VdeBody> bodies{make_body(make_triangle())};
|
||
ASSERT_NE(bodies[0], nullptr);
|
||
const std::string memory_text = write_memory_text(bodies);
|
||
ASSERT_FALSE(memory_text.empty());
|
||
const std::string path = temp_path("p447_write_equals.dxf");
|
||
g_last_error.clear();
|
||
ASSERT_EQ(format_->write_file(&host_, path.c_str(), bodies.data(), bodies.size()),
|
||
VDE_PLUGIN_OK) << g_last_error;
|
||
EXPECT_EQ(read_text_file(path), memory_text) << "write_file 与 write_memory 字节应一致";
|
||
remove_file(path);
|
||
destroy_bodies(bodies);
|
||
}
|
||
|
||
// ── 3. 增强开关 / 名称净化 ─────────────────────────────────────────
|
||
TEST_F(DxfWriteFixture, DisableEnhancementFallsBackToLayerZero) {
|
||
ASSERT_TRUE(set_env("VDE_DXF_WRITE_LAYERS", "0"));
|
||
std::vector<VdeBody> bodies{make_body(make_triangle()), make_body(make_quad())};
|
||
ASSERT_NE(bodies[0], nullptr);
|
||
ASSERT_NE(bodies[1], nullptr);
|
||
const std::string text = write_memory_text(bodies);
|
||
destroy_bodies(bodies);
|
||
ASSERT_FALSE(text.empty());
|
||
const std::vector<DxfPair> pairs = parse_pairs(text);
|
||
const std::vector<std::string> layer_names = layer_table_names(pairs);
|
||
ASSERT_EQ(layer_names.size(), 1u) << "回退旧行为应仅有 LAYER 0";
|
||
EXPECT_EQ(layer_names[0], "0");
|
||
EXPECT_EQ(layer_table_count(pairs), "1");
|
||
const std::vector<EntityLayer> entities = entity_layers(pairs);
|
||
ASSERT_EQ(entities.size(), 3u);
|
||
for (const auto& entity : entities) {
|
||
EXPECT_EQ(entity.layer, "0");
|
||
EXPECT_TRUE(entity.color.empty()) << "旧行为 3DFACE 不含 62 颜色组码";
|
||
}
|
||
EXPECT_FALSE(has_pair(pairs, 2, "BODY_0"));
|
||
EXPECT_EQ(count_pairs(pairs, 62, "7"), 1u); // 仅 LAYER 0 表记录的 62
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, EnvBodyNamesSanitizedTruncatedAndUnique) {
|
||
ASSERT_TRUE(set_env(
|
||
"VDE_DXF_BODY_NAMES",
|
||
"Part A, Very Long Name/with<bad>chars and way more than thirty one chars,,"
|
||
"dup,dup"));
|
||
std::vector<VdeBody> bodies = make_triangle_bodies(5);
|
||
for (const VdeBody body : bodies) ASSERT_NE(body, nullptr) << g_last_error;
|
||
const std::string text = write_memory_text(bodies);
|
||
destroy_bodies(bodies);
|
||
const std::vector<DxfPair> pairs = parse_pairs(text);
|
||
const std::vector<std::string> layer_names = layer_table_names(pairs);
|
||
ASSERT_EQ(layer_names.size(), 6u) << "LAYER 0 + 5 body layers";
|
||
EXPECT_EQ(layer_names[0], "0");
|
||
EXPECT_EQ(layer_names[1], "Part_A");
|
||
EXPECT_EQ(layer_names[2].size(), kMaxLayerNameLength);
|
||
EXPECT_EQ(layer_names[2].rfind("Very_Long_Name", 0), 0u) << layer_names[2];
|
||
EXPECT_TRUE(is_allowed_layer_name(layer_names[2])) << layer_names[2];
|
||
EXPECT_EQ(layer_names[3], "BODY_2");
|
||
EXPECT_EQ(layer_names[4], "dup");
|
||
EXPECT_EQ(layer_names[5], "dup_1");
|
||
for (const auto& name : layer_names) EXPECT_TRUE(is_allowed_layer_name(name)) << name;
|
||
std::vector<std::string> sorted = layer_names;
|
||
std::sort(sorted.begin(), sorted.end());
|
||
EXPECT_EQ(std::adjacent_find(sorted.begin(), sorted.end()), sorted.end());
|
||
const std::vector<EntityLayer> entities = entity_layers(pairs);
|
||
ASSERT_EQ(entities.size(), 5u);
|
||
for (std::size_t i = 0; i < entities.size(); ++i) {
|
||
EXPECT_EQ(entities[i].layer, layer_names[i + 1]) << "body " << i;
|
||
EXPECT_EQ(entities[i].color, std::to_string(1 + (i % 7)));
|
||
}
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, InvalidEnvBodyNamesFallBackToGenerated) {
|
||
ASSERT_TRUE(set_env("VDE_DXF_BODY_NAMES", ",,,"));
|
||
std::vector<VdeBody> bodies = make_triangle_bodies(3);
|
||
for (const VdeBody body : bodies) ASSERT_NE(body, nullptr);
|
||
const std::string text = write_memory_text(bodies);
|
||
destroy_bodies(bodies);
|
||
const std::vector<DxfPair> pairs = parse_pairs(text);
|
||
const std::vector<std::string> layer_names = layer_table_names(pairs);
|
||
ASSERT_EQ(layer_names.size(), 4u);
|
||
EXPECT_EQ(layer_names[1], "BODY_0");
|
||
EXPECT_EQ(layer_names[2], "BODY_1");
|
||
EXPECT_EQ(layer_names[3], "BODY_2");
|
||
}
|
||
|
||
// ── 4. 上限 / 错误路径 ─────────────────────────────────────────────
|
||
TEST_F(DxfWriteFixture, BodyCountLimitRejected) {
|
||
std::vector<VdeBody> bodies = make_triangle_bodies(kMaxBodyCount + 1);
|
||
for (const VdeBody body : bodies) ASSERT_NE(body, nullptr);
|
||
VdeBuffer buffer{};
|
||
g_last_error.clear();
|
||
EXPECT_EQ(format_->write_memory(&host_, bodies.data(), bodies.size(), &buffer),
|
||
VDE_PLUGIN_ERR_INVALID_ARG);
|
||
EXPECT_EQ(buffer.data, nullptr);
|
||
EXPECT_NE(g_last_error.find("上限"), std::string::npos) << g_last_error;
|
||
const std::string path = temp_path("p447_limit.dxf");
|
||
EXPECT_EQ(format_->write_file(&host_, path.c_str(), bodies.data(), bodies.size()),
|
||
VDE_PLUGIN_ERR_INVALID_ARG);
|
||
remove_file(path);
|
||
destroy_bodies(bodies);
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, EmptyAndInvalidWriteArguments) {
|
||
VdeBuffer buffer{};
|
||
EXPECT_EQ(format_->write_memory(&host_, nullptr, 0, &buffer),
|
||
VDE_PLUGIN_ERR_INVALID_ARG);
|
||
EXPECT_EQ(buffer.data, nullptr);
|
||
|
||
std::vector<VdeBody> bodies{make_body(make_triangle())};
|
||
ASSERT_NE(bodies[0], nullptr);
|
||
EXPECT_EQ(format_->write_memory(&host_, bodies.data(), 0, &buffer),
|
||
VDE_PLUGIN_ERR_INVALID_ARG);
|
||
EXPECT_EQ(format_->write_memory(&host_, bodies.data(), bodies.size(), nullptr),
|
||
VDE_PLUGIN_ERR_INVALID_ARG);
|
||
EXPECT_EQ(format_->write_file(&host_, nullptr, bodies.data(), bodies.size()),
|
||
VDE_PLUGIN_ERR_INVALID_ARG);
|
||
EXPECT_EQ(format_->write_file(&host_, temp_path("p447_nodata.dxf").c_str(), nullptr, 0),
|
||
VDE_PLUGIN_ERR_INVALID_ARG);
|
||
destroy_bodies(bodies);
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, EmptyOrFailedTessellationRejected) {
|
||
MockBody triangle = make_triangle();
|
||
std::vector<VdeBody> empty_body{make_body(triangle)};
|
||
ASSERT_NE(empty_body[0], nullptr);
|
||
as_mock(empty_body[0])->empty_tessellate = true;
|
||
VdeBuffer buffer{};
|
||
g_last_error.clear();
|
||
EXPECT_NE(format_->write_memory(&host_, empty_body.data(), empty_body.size(), &buffer),
|
||
VDE_PLUGIN_OK);
|
||
EXPECT_EQ(buffer.data, nullptr);
|
||
EXPECT_FALSE(g_last_error.empty());
|
||
destroy_bodies(empty_body);
|
||
|
||
std::vector<VdeBody> failing{make_body(triangle)};
|
||
ASSERT_NE(failing[0], nullptr);
|
||
as_mock(failing[0])->fail_tessellate = true;
|
||
g_last_error.clear();
|
||
EXPECT_NE(format_->write_memory(&host_, failing.data(), failing.size(), &buffer),
|
||
VDE_PLUGIN_OK);
|
||
EXPECT_EQ(buffer.data, nullptr);
|
||
EXPECT_FALSE(g_last_error.empty());
|
||
destroy_bodies(failing);
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, MissingHostWriteServicesRejected) {
|
||
std::vector<VdeBody> bodies{make_body(make_triangle())};
|
||
ASSERT_NE(bodies[0], nullptr);
|
||
VdePluginHost no_tessellate = host_;
|
||
no_tessellate.body_tessellate = nullptr;
|
||
VdeBuffer buffer{};
|
||
EXPECT_EQ(format_->write_memory(&no_tessellate, bodies.data(), bodies.size(), &buffer),
|
||
VDE_PLUGIN_ERR_UNSUPPORTED);
|
||
VdePluginHost no_free_buffer = host_;
|
||
no_free_buffer.free_buffer = nullptr;
|
||
EXPECT_EQ(format_->write_memory(&no_free_buffer, bodies.data(), bodies.size(), &buffer),
|
||
VDE_PLUGIN_ERR_UNSUPPORTED);
|
||
destroy_bodies(bodies);
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, NullAndBadEntryArguments) {
|
||
VdePluginInfo info{};
|
||
info.struct_size = static_cast<std::uint32_t>(sizeof(VdePluginInfo));
|
||
EXPECT_EQ(api_.query(VDE_PLUGIN_ABI_MAJOR + 1u, &info), VDE_PLUGIN_ERR_ABI);
|
||
EXPECT_EQ(api_.query(VDE_PLUGIN_ABI_MAJOR, nullptr), VDE_PLUGIN_ERR_ABI);
|
||
|
||
VdePluginRegistration registration{};
|
||
registration.struct_size = static_cast<std::uint32_t>(sizeof(VdePluginRegistration));
|
||
EXPECT_EQ(api_.init(nullptr, ®istration), VDE_PLUGIN_ERR_INVALID_ARG);
|
||
EXPECT_EQ(api_.init(&host_, nullptr), VDE_PLUGIN_ERR_ABI);
|
||
registration.struct_size = 1u;
|
||
EXPECT_EQ(api_.init(&host_, ®istration), VDE_PLUGIN_ERR_ABI);
|
||
}
|
||
|
||
// ── 5. 写后回读 ────────────────────────────────────────────────────
|
||
TEST_F(DxfWriteFixture, ReadMemoryStillUnsupported) {
|
||
VdeBody* bodies = nullptr;
|
||
std::size_t count = 0;
|
||
EXPECT_EQ(format_->read_memory(&host_, kProxyDxf, std::strlen(kProxyDxf), &bodies,
|
||
&count),
|
||
VDE_PLUGIN_ERR_UNSUPPORTED);
|
||
EXPECT_EQ(bodies, nullptr);
|
||
EXPECT_EQ(count, 0u);
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, WriteThenReadBackTriangleMesh) {
|
||
MockBody triangle = make_triangle();
|
||
std::vector<VdeBody> bodies{make_body(triangle)};
|
||
ASSERT_NE(bodies[0], nullptr);
|
||
const std::string path = temp_path("p447_roundtrip.dxf");
|
||
ASSERT_EQ(format_->write_file(&host_, path.c_str(), bodies.data(), bodies.size()),
|
||
VDE_PLUGIN_OK) << g_last_error;
|
||
destroy_bodies(bodies);
|
||
|
||
VdeBody* read_bodies = nullptr;
|
||
std::size_t read_count = 0;
|
||
g_last_error.clear();
|
||
ASSERT_EQ(format_->read_file(&host_, path.c_str(), &read_bodies, &read_count),
|
||
VDE_PLUGIN_OK) << g_last_error;
|
||
ASSERT_EQ(read_count, 1u);
|
||
const MockBody* read_body = as_mock(read_bodies[0]);
|
||
ASSERT_NE(read_body, nullptr);
|
||
EXPECT_EQ(read_body->indices.size(), 3u);
|
||
EXPECT_EQ(read_body->positions.size(), 9u);
|
||
host_.body_destroy(read_bodies[0]);
|
||
host_.free(read_bodies);
|
||
remove_file(path);
|
||
}
|
||
|
||
TEST_F(DxfWriteFixture, WriteMultiBodiesThenReadBackMerges) {
|
||
std::vector<VdeBody> bodies{make_body(make_triangle()), make_body(make_quad())};
|
||
ASSERT_NE(bodies[0], nullptr);
|
||
ASSERT_NE(bodies[1], nullptr);
|
||
const std::string path = temp_path("p447_roundtrip_multi.dxf");
|
||
ASSERT_EQ(format_->write_file(&host_, path.c_str(), bodies.data(), bodies.size()),
|
||
VDE_PLUGIN_OK) << g_last_error;
|
||
destroy_bodies(bodies);
|
||
|
||
VdeBody* read_bodies = nullptr;
|
||
std::size_t read_count = 0;
|
||
ASSERT_EQ(format_->read_file(&host_, path.c_str(), &read_bodies, &read_count),
|
||
VDE_PLUGIN_OK) << g_last_error;
|
||
ASSERT_EQ(read_count, 1u) << "读插件把多个 3DFACE 合并为单个实体";
|
||
const MockBody* read_body = as_mock(read_bodies[0]);
|
||
ASSERT_NE(read_body, nullptr);
|
||
EXPECT_EQ(read_body->indices.size(), 9u);
|
||
host_.body_destroy(read_bodies[0]);
|
||
host_.free(read_bodies);
|
||
remove_file(path);
|
||
}
|