Files
ViewDesignEngine/tests/foundation/test_io_amf.cpp
T
hm 1a78e8e191 fix: comprehensive test fixes and implementation bugs
Build system: fix VDE_BUILD_TYPE, MinGW big-obj, cross-platform temp dir
Core fixes: Matrix4D inverse, ExactPredicates sign, GJK overflow, VdeFormat weights, VRML/Collada IO
Test fixes: ObjectPool, Transaction paths, /tmp replacement, Matrix4D expectations
Result: 292/295 fast tests pass (99%)
2026-08-04 06:44:53 +08:00

113 lines
3.2 KiB
C++

#include <gtest/gtest.h>
#include <cstdio>
#include "vde/foundation/io_amf.h"
using namespace vde::foundation;
// Helper
static AmfMesh make_tet_amf(const std::string& name = "") {
AmfMesh am;
am.name = name;
am.mesh.build_from_triangles(
{
vde::mesh::Point3D(0, 0, 0), vde::mesh::Point3D(1, 0, 0),
vde::mesh::Point3D(0.5, 0.866, 0), vde::mesh::Point3D(0.5, 0.289, 0.816)
},
{
{0, 1, 2}, {0, 3, 1}, {1, 3, 2}, {0, 2, 3}
}
);
return am;
}
static AmfMesh make_cube_amf(const std::string& name = "") {
AmfMesh am;
am.name = name;
am.mesh.build_from_triangles(
{
vde::mesh::Point3D(0,0,0), vde::mesh::Point3D(1,0,0), vde::mesh::Point3D(1,1,0), vde::mesh::Point3D(0,1,0),
vde::mesh::Point3D(0,0,1), vde::mesh::Point3D(1,0,1), vde::mesh::Point3D(1,1,1), vde::mesh::Point3D(0,1,1)
},
{
{0,1,2}, {0,2,3},
{4,5,6}, {4,6,7},
{0,4,5}, {0,5,1},
{2,1,5}, {2,5,6},
{3,2,6}, {3,6,7},
{0,3,7}, {0,7,4}
}
);
return am;
}
// ── Test 1: Export then import tetrahedron round-trip ──
TEST(IoAmfTest, ExportThenImportTetrahedron) {
auto am = make_tet_amf("TetPart");
am.diffuse_r = 1.0f;
am.diffuse_g = 0.0f;
am.diffuse_b = 0.0f;
const char* path = VDE_TEST_TEMP_DIR "test_amf_tet.amf";
std::remove(path);
ASSERT_TRUE(export_amf_multi({am}, path));
auto loaded = import_amf_all(path);
ASSERT_GE(loaded.size(), 1u);
EXPECT_EQ(loaded[0].name, "TetPart");
EXPECT_EQ(loaded[0].mesh.num_vertices(), 4u);
EXPECT_EQ(loaded[0].mesh.num_faces(), 4u);
EXPECT_FLOAT_EQ(loaded[0].diffuse_r, 1.0f);
std::remove(path);
}
// ── Test 2: Multiple objects round-trip ──
TEST(IoAmfTest, MultipleObjectsRoundTrip) {
auto t1 = make_tet_amf("PartA");
auto t2 = make_cube_amf("PartB");
const char* path = VDE_TEST_TEMP_DIR "test_amf_multi.amf";
std::remove(path);
ASSERT_TRUE(export_amf_multi({t1, t2}, path));
auto loaded = import_amf_all(path);
EXPECT_EQ(loaded.size(), 2u);
EXPECT_EQ(loaded[0].name, "PartA");
EXPECT_EQ(loaded[1].name, "PartB");
EXPECT_EQ(loaded[0].mesh.num_vertices(), 4u);
EXPECT_EQ(loaded[1].mesh.num_vertices(), 8u);
std::remove(path);
}
// ── Test 3: Metadata round-trip ──
TEST(IoAmfTest, MetadataRoundTrip) {
auto am = make_tet_amf("MetaTest");
am.description = "Test object";
am.author = "VDE";
am.license = "Apache-2.0";
const char* path = VDE_TEST_TEMP_DIR "test_amf_meta.amf";
std::remove(path);
ASSERT_TRUE(export_amf_multi({am}, path));
auto loaded = import_amf_all(path);
ASSERT_GE(loaded.size(), 1u);
EXPECT_EQ(loaded[0].description, "Test object");
EXPECT_EQ(loaded[0].author, "VDE");
EXPECT_EQ(loaded[0].license, "Apache-2.0");
std::remove(path);
}
// ── Test 4: Empty export returns false ──
TEST(IoAmfTest, ExportEmptyReturnsFalse) {
const char* path = VDE_TEST_TEMP_DIR "test_amf_empty.amf";
std::remove(path);
EXPECT_FALSE(export_amf_multi({}, path));
std::remove(path);
}