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%)
108 lines
4.6 KiB
C++
108 lines
4.6 KiB
C++
#include <gtest/gtest.h>
|
|
#include <cstdio>
|
|
#include <fstream>
|
|
#include "vde/foundation/io_collada.h"
|
|
|
|
using namespace vde::foundation;
|
|
|
|
// ── Test 1: Import tetrahedron COLLADA ──
|
|
TEST(IoColladaTest, ImportTetrahedron) {
|
|
const char* path = VDE_TEST_TEMP_DIR "test_collada_1.dae";
|
|
std::remove(path);
|
|
std::ofstream out(path);
|
|
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
|
out << "<COLLADA xmlns=\"http://www.collada.org/2005/11/COLLADASchema\" version=\"1.4.1\">\n";
|
|
out << " <library_geometries>\n";
|
|
out << " <geometry id=\"geom0\" name=\"Tet\">\n";
|
|
out << " <mesh>\n";
|
|
out << " <source id=\"geom0-positions\">\n";
|
|
out << " <float_array id=\"fa0\" count=\"12\">";
|
|
out << "0 0 0 1 0 0 0.5 0.866 0 0.5 0.289 0.816</float_array>\n";
|
|
out << " <technique_common>\n";
|
|
out << " <accessor source=\"#fa0\" count=\"4\" stride=\"3\">\n";
|
|
out << " <param name=\"X\" type=\"float\"/>\n";
|
|
out << " <param name=\"Y\" type=\"float\"/>\n";
|
|
out << " <param name=\"Z\" type=\"float\"/>\n";
|
|
out << " </accessor>\n";
|
|
out << " </technique_common>\n";
|
|
out << " </source>\n";
|
|
out << " <vertices id=\"v0\">\n";
|
|
out << " <input semantic=\"POSITION\" source=\"#geom0-positions\"/>\n";
|
|
out << " </vertices>\n";
|
|
out << " <triangles count=\"4\">\n";
|
|
out << " <input semantic=\"VERTEX\" source=\"#v0\" offset=\"0\"/>\n";
|
|
out << " <p>0 1 2 0 3 1 1 3 2 0 2 3</p>\n";
|
|
out << " </triangles>\n";
|
|
out << " </mesh>\n";
|
|
out << " </geometry>\n";
|
|
out << " </library_geometries>\n";
|
|
out << " <library_visual_scenes>\n";
|
|
out << " <visual_scene id=\"S\"><node name=\"Tet\"><instance_geometry url=\"#geom0\"/></node></visual_scene>\n";
|
|
out << " </library_visual_scenes>\n";
|
|
out << " <scene><instance_visual_scene url=\"#S\"/></scene>\n";
|
|
out << "</COLLADA>\n";
|
|
out.close();
|
|
|
|
auto models = import_collada(path);
|
|
ASSERT_GE(models.size(), 1u);
|
|
EXPECT_GT(models[0].num_vertices(), 0u);
|
|
EXPECT_GT(models[0].num_faces(), 0u);
|
|
std::remove(path);
|
|
}
|
|
|
|
// ── Test 2: Import single triangle ──
|
|
TEST(IoColladaTest, ImportSingleTriangle) {
|
|
const char* path = VDE_TEST_TEMP_DIR "test_collada_2.dae";
|
|
std::remove(path);
|
|
std::ofstream out(path);
|
|
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
|
out << "<COLLADA xmlns=\"http://www.collada.org/2005/11/COLLADASchema\" version=\"1.4.1\">\n";
|
|
out << " <library_geometries>\n";
|
|
out << " <geometry id=\"g1\" name=\"Tri\">\n";
|
|
out << " <mesh>\n";
|
|
out << " <source id=\"s1\">\n";
|
|
out << " <float_array id=\"fa1\" count=\"9\">1 0 0 2 0 0 1.5 0.866 0</float_array>\n";
|
|
out << " <technique_common>\n";
|
|
out << " <accessor source=\"#fa1\" count=\"3\" stride=\"3\">\n";
|
|
out << " <param name=\"X\" type=\"float\"/>\n";
|
|
out << " <param name=\"Y\" type=\"float\"/>\n";
|
|
out << " <param name=\"Z\" type=\"float\"/>\n";
|
|
out << " </accessor>\n";
|
|
out << " </technique_common>\n";
|
|
out << " </source>\n";
|
|
out << " <vertices id=\"v1\">\n";
|
|
out << " <input semantic=\"POSITION\" source=\"#s1\"/>\n";
|
|
out << " </vertices>\n";
|
|
out << " <triangles count=\"1\">\n";
|
|
out << " <input semantic=\"VERTEX\" source=\"#v1\" offset=\"0\"/>\n";
|
|
out << " <p>0 1 2</p>\n";
|
|
out << " </triangles>\n";
|
|
out << " </mesh>\n";
|
|
out << " </geometry>\n";
|
|
out << " </library_geometries>\n";
|
|
out << " <library_visual_scenes>\n";
|
|
out << " <visual_scene id=\"S\"><node name=\"Tri\"><instance_geometry url=\"#g1\"/></node></visual_scene>\n";
|
|
out << " </library_visual_scenes>\n";
|
|
out << " <scene><instance_visual_scene url=\"#S\"/></scene>\n";
|
|
out << "</COLLADA>\n";
|
|
out.close();
|
|
|
|
auto models = import_collada(path);
|
|
ASSERT_GE(models.size(), 1u);
|
|
EXPECT_EQ(models[0].num_vertices(), 3u);
|
|
EXPECT_EQ(models[0].num_faces(), 1u);
|
|
std::remove(path);
|
|
}
|
|
|
|
// ── Test 3: Empty export returns false ──
|
|
TEST(IoColladaTest, ExportEmptyReturnsFalse) {
|
|
std::vector<vde::brep::BrepModel> empty;
|
|
EXPECT_FALSE(export_collada(empty, VDE_TEST_TEMP_DIR "test_collada_empty.dae"));
|
|
}
|
|
|
|
// ── Test 4: Import nonexistent file ──
|
|
TEST(IoColladaTest, ImportNonExistentReturnsEmpty) {
|
|
auto result = import_collada(VDE_TEST_TEMP_DIR "nonexistent_collada_xyz.dae");
|
|
EXPECT_TRUE(result.empty());
|
|
}
|