Files
ViewDesignEngine/tests/plugin/test_official_io_batch_mesh.cpp
T

615 lines
26 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// P4-33/P4-38 官方 IO_BATCH 网格转换插件测试(确定性 mock 宿主 + 真实 C ABI 动态加载;ABI 1.6 run_v2)。
//
// 覆盖:
// 1) query/init/describe/batch_id/能力与 struct_size;
// 2) STL(ASCII)/OBJ/PLY(ASCII) 批量互转(3 项一次请求),输出文件可读、triangles=1;
// 2b) P4-56:OFF(ASCII v/f)与 PLY binary_little_endian(float/double + 索引类型)读写、
// 混合格式矩阵、partial/坏输入/上限/确定性;
// 3) STL binary 读取 → OBJ 写出;
// 4) 混合成功/失败:合法项 + 不存在输入 + 不支持格式 → status=-4(PARTIAL)/processed/failed
// 逐项记录,响应 JSON 诊断;
// 5) 非法 options(flags)/畸形 request/空 items/非法 options.format;
// 6) 坏输入文件(非 STL)→ 单项失败,不产生输出。
//
// 注:shared CMake 由 Lead 注册;本文件按现有官方插件测试模式编写(纯 C ABI,不链接内核)。
#include <gtest/gtest.h>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#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.io_batch.mesh";
constexpr const char* kBatchId = "io_batch.mesh";
#if defined(_WIN32)
constexpr const char* kPluginRelativePath = "/io_batch_mesh/vde_official_io_batch_mesh.dll";
#elif defined(__APPLE__)
constexpr const char* kPluginRelativePath = "/io_batch_mesh/libvde_official_io_batch_mesh.dylib";
#else
constexpr const char* kPluginRelativePath = "/io_batch_mesh/libvde_official_io_batch_mesh.so";
#endif
#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
std::string g_last_error;
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_log(int, const char*) {}
void mock_set_error(const char* message) { g_last_error = message ? message : ""; }
void mock_body_destroy(VdeBody) {}
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;
return host;
}
std::string env_or_macro(const char* macro_value, const char* env_name) {
if (macro_value && macro_value[0] != '\0') return std::string(macro_value);
const char* env = std::getenv(env_name);
return env ? std::string(env) : std::string();
}
std::string official_dir() {
return env_or_macro(VDE_PLUGIN_OFFICIAL_DIR, "VDE_PLUGIN_OFFICIAL_DIR");
}
std::string temp_dir() {
return env_or_macro(VDE_TEST_TEMP_DIR, "VDE_TEST_TEMP_DIR");
}
// 每个测试进程使用独立临时目录,避免 CTest 并行时共享路径互相覆盖。
std::string g_temp_dir;
std::string temp_path(const char* name) {
if (!g_temp_dir.empty()) return g_temp_dir + "/" + name;
return temp_dir() + name;
}
bool write_file(const std::string& path, const std::string& data) {
std::ofstream out(path, std::ios::binary | std::ios::trunc);
if (!out.good()) return false;
out.write(data.data(), static_cast<std::streamsize>(data.size()));
return out.good();
}
std::string read_file(const std::string& path) {
std::ifstream in(path, std::ios::binary);
return std::string((std::istreambuf_iterator<char>(in)),
std::istreambuf_iterator<char>());
}
bool contains(const std::string& text, const std::string& needle) {
return text.find(needle) != std::string::npos;
}
const char* kStlAscii =
"solid tri\n"
" facet normal 0 0 1\n"
" outer loop\n"
" vertex 0 0 0\n"
" vertex 1 0 0\n"
" vertex 0 1 0\n"
" endloop\n"
" endfacet\n"
"endsolid tri\n";
const char* kObj =
"# obj test\n"
"v 0 0 0\nv 1 0 0\nv 0 1 0\n"
"f 1 2 3\n";
const char* kPly =
"ply\n"
"format ascii 1.0\n"
"element vertex 3\n"
"property float x\nproperty float y\nproperty float z\n"
"element face 1\n"
"property list uchar int vertex_indices\n"
"end_header\n"
"0 0 0\n1 0 0\n0 1 0\n"
"3 0 1 2\n";
const char* kOff =
"OFF\n"
"3 1 0\n"
"0 0 0\n1 0 0\n0 1 0\n"
"3 0 1 2\n";
void append_float_le(std::string* out, float value) {
unsigned char bytes[4];
std::memcpy(bytes, &value, 4);
out->append(reinterpret_cast<const char*>(bytes), 4);
}
void append_double_le(std::string* out, double value) {
unsigned char bytes[8];
std::memcpy(bytes, &value, 8);
out->append(reinterpret_cast<const char*>(bytes), 8);
}
void append_uint_le(std::string* out, std::uint64_t value, std::size_t width) {
unsigned char bytes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
for (std::size_t i = 0; i < width; ++i)
bytes[i] = static_cast<unsigned char>((value >> (8 * i)) & 0xFFu);
out->append(reinterpret_cast<const char*>(bytes), width);
}
std::string binary_ply_float_int() {
std::string out =
"ply\nformat binary_little_endian 1.0\n"
"element vertex 3\nproperty float x\nproperty float y\nproperty float z\n"
"element face 1\nproperty list uchar int vertex_indices\nend_header\n";
const float vertices[3][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}};
for (const auto& vertex : vertices)
for (float value : vertex) append_float_le(&out, value);
append_uint_le(&out, 3, 1);
append_uint_le(&out, 0, 4);
append_uint_le(&out, 1, 4);
append_uint_le(&out, 2, 4);
return out;
}
std::string binary_ply_double_ushort() {
std::string out =
"ply\nformat binary_little_endian 1.0\n"
"element vertex 4\nproperty double x\nproperty double y\nproperty double z\n"
"property uchar red\n"
"element face 1\nproperty list ushort ushort vertex_indices\nend_header\n";
const double vertices[4][3] = {{0, 0, 0}, {2, 0, 0}, {2, 1, 0}, {0, 1, 0}};
for (const auto& vertex : vertices) {
for (double value : vertex) append_double_le(&out, value);
out.push_back(static_cast<char>(7));
}
append_uint_le(&out, 4, 2);
for (std::uint64_t index : {0ull, 1ull, 2ull, 3ull}) append_uint_le(&out, index, 2);
return out;
}
std::string binary_stl_one_triangle() {
std::string data(80, '\0');
const std::uint32_t count = 1;
data.append(reinterpret_cast<const char*>(&count), sizeof(count));
const float vertices[3][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}};
const float normal[3] = {0, 0, 1};
data.append(reinterpret_cast<const char*>(normal), 12);
for (const auto& vertex : vertices) {
data.append(reinterpret_cast<const char*>(vertex), 12);
}
const char attributes[2] = {0, 0};
data.append(attributes, 2);
return data;
}
class IoBatchMeshFixture : public ::testing::Test {
protected:
void SetUp() override {
g_last_error.clear();
host_ = make_mock_host();
path_ = official_dir() + kPluginRelativePath;
library_ = open_library(path_.c_str());
ASSERT_NE(library_, nullptr) << "无法加载插件: " << path_;
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"));
ASSERT_NE(query_, nullptr);
ASSERT_NE(init_, nullptr);
VdePluginInfo info{};
info.struct_size = static_cast<std::uint32_t>(sizeof(VdePluginInfo));
ASSERT_EQ(query_(VDE_PLUGIN_ABI_MAJOR, &info), VDE_PLUGIN_OK);
VdePluginRegistration registration{};
registration.struct_size =
static_cast<std::uint32_t>(sizeof(VdePluginRegistration));
ASSERT_EQ(init_(&host_, &registration), VDE_PLUGIN_OK) << g_last_error;
ASSERT_EQ(registration.kind, VDE_PLUGIN_KIND_IO_BATCH);
ASSERT_NE(registration.io_batch, nullptr);
batch_ = registration.io_batch;
ASSERT_EQ(std::string(batch_->batch_id), kBatchId);
const auto unique = std::chrono::high_resolution_clock::now().time_since_epoch().count();
g_temp_dir = (std::filesystem::path(temp_dir()) /
("io_batch_mesh_" + std::to_string(unique))).string();
temp_dir_ = std::filesystem::path(g_temp_dir);
std::filesystem::create_directories(temp_dir_);
write_file(temp_path("tri.stl"), kStlAscii);
write_file(temp_path("tri.obj"), kObj);
write_file(temp_path("tri.ply"), kPly);
write_file(temp_path("tri.off"), kOff);
write_file(temp_path("tri_binary.plyb"), binary_ply_float_int());
write_file(temp_path("tri_double.plyb"), binary_ply_double_ushort());
write_file(temp_path("tri_binary.stl"), binary_stl_one_triangle());
}
void TearDown() override {
if (shutdown_) shutdown_();
if (library_) close_library(library_);
if (!g_temp_dir.empty()) std::filesystem::remove_all(g_temp_dir);
}
int run(const std::string& options, const std::string& request, std::string* response,
std::string* error) {
VdeBuffer buffer{};
char error_message[512] = {};
g_last_error.clear();
if (response) response->clear();
if (error) error->clear();
const int rc = batch_->run(&host_, options.empty() ? nullptr : options.c_str(),
request.data(), request.size(), &buffer, error_message,
sizeof(error_message));
if (buffer.data && buffer.size > 0) {
if (response) response->assign(static_cast<const char*>(buffer.data),
buffer.size);
host_.free_buffer(buffer.data);
}
if (error) *error = error_message;
return rc;
}
int run_v2_batch(const std::string& options, const std::string& request,
VdeIoBatchResult* result, std::string* response, std::string* error) {
VdeBuffer buffer{};
char error_message[512] = {};
result->struct_size = static_cast<std::uint32_t>(sizeof(VdeIoBatchResult));
result->status = static_cast<std::uint32_t>(VDE_IO_BATCH_ERR_INTERNAL);
result->processed = 0;
result->failed = 0;
g_last_error.clear();
if (response) response->clear();
if (error) error->clear();
const int rc = batch_->run_v2(&host_, options.empty() ? nullptr : options.c_str(),
request.data(), request.size(), result, &buffer,
error_message, sizeof(error_message));
if (buffer.data && buffer.size > 0) {
if (response) response->assign(static_cast<const char*>(buffer.data),
buffer.size);
host_.free_buffer(buffer.data);
}
if (error) *error = error_message;
return rc;
}
VdePluginHost host_{};
LibraryHandle library_ = nullptr;
VdePluginQueryFn query_ = nullptr;
VdePluginInitFn init_ = nullptr;
VdePluginShutdownFn shutdown_ = nullptr;
const VdeIoBatchPlugin* batch_ = nullptr;
std::string path_;
std::filesystem::path temp_dir_;
};
TEST_F(IoBatchMeshFixture, MetadataAndRegistration) {
VdePluginInfo info{};
info.struct_size = static_cast<std::uint32_t>(sizeof(VdePluginInfo));
ASSERT_EQ(query_(VDE_PLUGIN_ABI_MAJOR, &info), VDE_PLUGIN_OK);
EXPECT_STREQ(info.id, kPluginId);
EXPECT_EQ(info.kind, VDE_PLUGIN_KIND_IO_BATCH);
EXPECT_EQ(info.abi_major, VDE_PLUGIN_ABI_MAJOR);
EXPECT_EQ(info.abi_minor, VDE_PLUGIN_ABI_MINOR);
EXPECT_STREQ(info.capabilities, "io_batch:mesh_convert");
ASSERT_NE(batch_, nullptr);
EXPECT_STREQ(batch_->batch_id, kBatchId);
EXPECT_GE(batch_->struct_size, sizeof(VdeIoBatchPlugin));
EXPECT_NE(batch_->run_v2, nullptr);
ASSERT_NE(batch_->capabilities_json, nullptr);
EXPECT_NE(std::string(batch_->capabilities_json).find("\"stl\""), std::string::npos);
}
TEST_F(IoBatchMeshFixture, BatchConvertsStlObjPly) {
const std::string request =
"{\"items\":["
"{\"input\":\"" + temp_path("tri.stl") + "\",\"output\":\"" + temp_path("a.obj") +
"\",\"from\":\"stl\",\"to\":\"obj\"},"
"{\"input\":\"" + temp_path("tri.obj") + "\",\"output\":\"" + temp_path("b.ply") +
"\",\"from\":\"obj\",\"to\":\"ply\"},"
"{\"input\":\"" + temp_path("tri.ply") + "\",\"output\":\"" + temp_path("c.stl") +
"\",\"from\":\"ply\",\"to\":\"stl\"}]}";
std::string response;
std::string error;
const int rc = run("", request, &response, &error);
ASSERT_EQ(rc, VDE_PLUGIN_OK) << error << g_last_error;
EXPECT_TRUE(contains(response, "\"batch_id\":\"io_batch.mesh\""));
EXPECT_TRUE(contains(response, "\"ok\":true"));
EXPECT_TRUE(contains(response, "\"processed\":3")) << response;
EXPECT_TRUE(contains(response, "\"failed\":0"));
EXPECT_TRUE(contains(response, "\"triangles\":1"));
const std::string obj = read_file(temp_path("a.obj"));
EXPECT_TRUE(contains(obj, "v "));
EXPECT_TRUE(contains(obj, "f "));
const std::string ply = read_file(temp_path("b.ply"));
EXPECT_TRUE(ply.rfind("ply", 0) == 0);
EXPECT_TRUE(contains(ply, "element vertex 3"));
const std::string stl = read_file(temp_path("c.stl"));
EXPECT_TRUE(stl.rfind("solid", 0) == 0);
}
TEST_F(IoBatchMeshFixture, ReadsBinaryStl) {
const std::string request =
"{\"items\":[{\"input\":\"" + temp_path("tri_binary.stl") + "\",\"output\":\"" +
temp_path("binary.obj") + "\",\"from\":\"stl\",\"to\":\"obj\"}]}";
std::string response;
std::string error;
ASSERT_EQ(run("", request, &response, &error), VDE_PLUGIN_OK) << error;
EXPECT_TRUE(contains(response, "\"triangles\":1"));
const std::string obj = read_file(temp_path("binary.obj"));
EXPECT_TRUE(contains(obj, "v "));
EXPECT_TRUE(contains(obj, "f 1 2 3"));
}
TEST_F(IoBatchMeshFixture, PartialFailureReportsAndContinues) {
const std::string request =
"{\"items\":["
"{\"input\":\"" + temp_path("tri.stl") + "\",\"output\":\"" + temp_path("ok.obj") +
"\",\"from\":\"stl\",\"to\":\"obj\"},"
"{\"input\":\"" + temp_path("missing.stl") + "\",\"output\":\"" +
temp_path("missing.obj") + "\",\"from\":\"stl\",\"to\":\"obj\"},"
"{\"input\":\"" + temp_path("tri.obj") + "\",\"output\":\"" + temp_path("bad.xyz") +
"\",\"from\":\"obj\",\"to\":\"xyz\"}]}";
std::string response;
std::string error;
ASSERT_EQ(run("", request, &response, &error), VDE_PLUGIN_OK) << error;
EXPECT_TRUE(contains(response, "\"status\":-4"));
EXPECT_TRUE(contains(response, "\"ok\":false"));
EXPECT_TRUE(contains(response, "\"processed\":1"));
EXPECT_TRUE(contains(response, "\"failed\":2"));
EXPECT_TRUE(contains(response, "读取失败"));
EXPECT_TRUE(contains(response, "不支持的 to"));
EXPECT_TRUE(std::filesystem::exists(temp_path("ok.obj")));
EXPECT_FALSE(std::filesystem::exists(temp_path("missing.obj")));
EXPECT_FALSE(std::filesystem::exists(temp_path("bad.xyz")));
}
TEST_F(IoBatchMeshFixture, InvalidOptionsAndRequestsRejected) {
std::string response;
std::string error;
EXPECT_EQ(run("{\"flags\":1}", "{\"items\":[]}", &response, &error),
VDE_PLUGIN_ERR_INVALID_ARG);
EXPECT_EQ(run("", "{bad json", &response, &error), VDE_PLUGIN_ERR_INVALID_ARG);
EXPECT_EQ(run("", "{\"items\":[]}", &response, &error), VDE_PLUGIN_ERR_INVALID_ARG);
EXPECT_EQ(run("{\"format\":\"step\"}", "{\"items\":[]}", &response, &error),
VDE_PLUGIN_ERR_INVALID_ARG);
EXPECT_EQ(run("", "", &response, &error), VDE_PLUGIN_ERR_INVALID_ARG);
}
TEST_F(IoBatchMeshFixture, MalformedInputItemFailsWithoutOutput) {
write_file(temp_path("broken.stl"), "not a stl file\n");
const std::string request =
"{\"items\":[{\"input\":\"" + temp_path("broken.stl") + "\",\"output\":\"" +
temp_path("broken.obj") + "\",\"from\":\"stl\",\"to\":\"obj\"}]}";
std::string response;
std::string error;
ASSERT_EQ(run("", request, &response, &error), VDE_PLUGIN_OK) << error;
EXPECT_TRUE(contains(response, "\"status\":-4"));
EXPECT_TRUE(contains(response, "\"failed\":1"));
EXPECT_TRUE(contains(response, "读取失败"));
EXPECT_FALSE(std::filesystem::exists(temp_path("broken.obj")));
}
} // namespace
TEST_F(IoBatchMeshFixture, RunV2BackfillsResultSuccess) {
ASSERT_NE(batch_->run_v2, nullptr);
const std::string request =
"{\"items\":[{\"input\":\"" + temp_path("tri.stl") +
"\",\"output\":\"" + temp_path("v2.obj") +
"\",\"from\":\"stl\",\"to\":\"obj\"}]}";
VdeIoBatchResult result{};
std::string response;
std::string error;
ASSERT_EQ(run_v2_batch("", request, &result, &response, &error), VDE_PLUGIN_OK)
<< error << g_last_error;
EXPECT_EQ(result.status, static_cast<std::uint32_t>(VDE_IO_BATCH_OK));
EXPECT_EQ(result.processed, 1u);
EXPECT_EQ(result.failed, 0u);
EXPECT_TRUE(contains(response, "\"processed\":1"));
EXPECT_TRUE(contains(response, "\"failed\":0"));
}
TEST_F(IoBatchMeshFixture, RunV2BackfillsPartialFailureStatus) {
ASSERT_NE(batch_->run_v2, nullptr);
const std::string request =
"{\"items\":["
"{\"input\":\"" + temp_path("tri.stl") +
"\",\"output\":\"" + temp_path("v2_ok.obj") +
"\",\"from\":\"stl\",\"to\":\"obj\"},"
"{\"input\":\"" + temp_path("missing.stl") +
"\",\"output\":\"" + temp_path("v2_missing.obj") +
"\",\"from\":\"stl\",\"to\":\"obj\"}]}";
VdeIoBatchResult result{};
std::string response;
std::string error;
ASSERT_EQ(run_v2_batch("", request, &result, &response, &error), VDE_PLUGIN_OK)
<< error << g_last_error;
EXPECT_EQ(result.status, static_cast<std::uint32_t>(VDE_IO_BATCH_ERR_PARTIAL));
EXPECT_EQ(result.processed, 1u);
EXPECT_EQ(result.failed, 1u);
EXPECT_TRUE(contains(response, "\"status\":-4"));
}
TEST_F(IoBatchMeshFixture, BatchConvertsOffAndPlyBinary) {
const std::string request =
"{\"items\":["
"{\"input\":\"" + temp_path("tri.off") + "\",\"output\":\"" + temp_path("from_off.obj") +
"\",\"from\":\"off\",\"to\":\"obj\"},"
"{\"input\":\"" + temp_path("tri_binary.plyb") + "\",\"output\":\"" +
temp_path("from_binary.off") + "\",\"from\":\"ply\",\"to\":\"off\"},"
"{\"input\":\"" + temp_path("tri.obj") + "\",\"output\":\"" +
temp_path("to_binary.plyb") + "\",\"from\":\"obj\",\"to\":\"ply\"},"
"{\"input\":\"" + temp_path("tri_double.plyb") + "\",\"output\":\"" +
temp_path("double.obj") + "\",\"from\":\"plyb\",\"to\":\"obj\"}]}";
std::string response;
std::string error;
ASSERT_EQ(run("", request, &response, &error), VDE_PLUGIN_OK) << error << g_last_error;
EXPECT_TRUE(contains(response, "\"ok\":true")) << response;
EXPECT_TRUE(contains(response, "\"processed\":4")) << response;
EXPECT_TRUE(contains(response, "\"failed\":0"));
const std::string obj = read_file(temp_path("from_off.obj"));
EXPECT_TRUE(contains(obj, "v "));
EXPECT_TRUE(contains(obj, "f 1 2 3"));
const std::string off = read_file(temp_path("from_binary.off"));
EXPECT_TRUE(off.rfind("OFF", 0) == 0);
EXPECT_TRUE(contains(off, "3 1 0"));
const std::string binary = read_file(temp_path("to_binary.plyb"));
EXPECT_TRUE(contains(binary, "format binary_little_endian 1.0"));
EXPECT_TRUE(contains(binary, "property float x"));
const std::string double_obj = read_file(temp_path("double.obj"));
EXPECT_TRUE(contains(double_obj, "v "));
EXPECT_TRUE(contains(double_obj, "f 1 2 3"));
}
TEST_F(IoBatchMeshFixture, FormatMatrixOffPlyAsciiPlyBinary) {
const char* inputs[] = {"tri.stl", "tri.obj", "tri.ply", "tri.off", "tri_binary.plyb"};
const char* inputs_format[] = {"stl", "obj", "ply", "off", "ply"};
const char* outputs[] = {"matrix.off", "matrix.ply", "matrix.plyb"};
const char* outputs_format[] = {"off", "ply", "ply"};
std::string request = "{\"items\":[";
bool first = true;
for (int i = 0; i < 5; ++i) {
for (int o = 0; o < 3; ++o) {
if (!first) request += ",";
first = false;
request += "{\"input\":\"" + temp_path(inputs[i]) + "\",\"output\":\"" +
temp_path((std::string("matrix_") + std::to_string(i) + "_" +
outputs[o]).c_str()) +
"\",\"from\":\"" + inputs_format[i] + "\",\"to\":\"" +
outputs_format[o] + "\"}";
}
}
request += "]}";
std::string response;
std::string error;
ASSERT_EQ(run("", request, &response, &error), VDE_PLUGIN_OK) << error << g_last_error;
EXPECT_TRUE(contains(response, "\"processed\":15")) << response;
EXPECT_TRUE(contains(response, "\"failed\":0"));
for (int i = 0; i < 5; ++i) {
for (int o = 0; o < 3; ++o) {
const std::string name = std::string("matrix_") + std::to_string(i) + "_" +
outputs[o];
const std::string text = read_file(temp_path(name.c_str()));
EXPECT_FALSE(text.empty()) << name;
if (o == 2) EXPECT_TRUE(contains(text, "format binary_little_endian 1.0"));
}
}
}
TEST_F(IoBatchMeshFixture, PartialFailuresForBadOffAndBadPly) {
write_file(temp_path("bad.off"), "COFF\n3 1 0\n0 0 0\n1 0 0\n0 1 0\n3 0 1 2\n");
write_file(temp_path("truncated.plyb"), binary_ply_float_int().substr(0, 200));
const std::string request =
"{\"items\":["
"{\"input\":\"" + temp_path("tri.stl") + "\",\"output\":\"" + temp_path("ok2.obj") +
"\",\"from\":\"stl\",\"to\":\"obj\"},"
"{\"input\":\"" + temp_path("bad.off") + "\",\"output\":\"" + temp_path("bad2.obj") +
"\",\"from\":\"off\",\"to\":\"obj\"},"
"{\"input\":\"" + temp_path("truncated.plyb") + "\",\"output\":\"" +
temp_path("truncated.obj") + "\",\"from\":\"ply\",\"to\":\"obj\"}]}";
std::string response;
std::string error;
ASSERT_EQ(run("", request, &response, &error), VDE_PLUGIN_OK) << error;
EXPECT_TRUE(contains(response, "\"status\":-4"));
EXPECT_TRUE(contains(response, "\"processed\":1"));
EXPECT_TRUE(contains(response, "\"failed\":2"));
EXPECT_TRUE(contains(response, "COFF")) << response;
EXPECT_TRUE(contains(response, "读取失败"));
EXPECT_FALSE(std::filesystem::exists(temp_path("bad2.obj")));
EXPECT_FALSE(std::filesystem::exists(temp_path("truncated.obj")));
}
TEST_F(IoBatchMeshFixture, RejectsOffAndPlyBinaryLimitAndBigEndian) {
write_file(temp_path("huge.off"),
"OFF\n20000001 0 0\n");
write_file(temp_path("big_endian.plyb"),
"ply\nformat binary_big_endian 1.0\nelement vertex 3\nproperty float x\n"
"property float y\nproperty float z\nelement face 1\n"
"property list uchar int vertex_indices\nend_header\n");
const std::string request =
"{\"items\":["
"{\"input\":\"" + temp_path("huge.off") + "\",\"output\":\"" + temp_path("huge.obj") +
"\",\"from\":\"off\",\"to\":\"obj\"},"
"{\"input\":\"" + temp_path("big_endian.plyb") + "\",\"output\":\"" +
temp_path("be.obj") + "\",\"from\":\"ply\",\"to\":\"obj\"}]}";
std::string response;
std::string error;
ASSERT_EQ(run("", request, &response, &error), VDE_PLUGIN_OK) << error;
EXPECT_TRUE(contains(response, "\"failed\":2"));
EXPECT_TRUE(contains(response, "上限")) << response;
EXPECT_TRUE(contains(response, "big_endian")) << response;
}
TEST_F(IoBatchMeshFixture, DeterministicOffAndPlyBinaryOutput) {
const auto make_request = [&](const std::string& suffix) {
return std::string("{\"items\":["
"{\"input\":\"") + temp_path("tri.off") + "\",\"output\":\"" +
temp_path((std::string("det_off_") + suffix + ".off").c_str()) +
"\",\"from\":\"off\",\"to\":\"off\"},"
"{\"input\":\"" + temp_path("tri.obj") + "\",\"output\":\"" +
temp_path((std::string("det_ply_") + suffix + ".plyb").c_str()) +
"\",\"from\":\"obj\",\"to\":\"ply\"}]}";
};
std::string response;
std::string error;
ASSERT_EQ(run("", make_request("a"), &response, &error), VDE_PLUGIN_OK) << error;
ASSERT_EQ(run("", make_request("b"), &response, &error), VDE_PLUGIN_OK) << error;
EXPECT_EQ(read_file(temp_path("det_off_a.off")), read_file(temp_path("det_off_b.off")));
EXPECT_EQ(read_file(temp_path("det_ply_a.plyb")), read_file(temp_path("det_ply_b.plyb")));
}