Files
ViewDesignEngine/tests/core/test_material_library.cpp
T
hm 3334acf0fd test: comprehensive test suite + bug fixes across all modules
- Add 12 new test files: render/viewport_layout, render/section_view, boolean/polygon_offset, core/icp, core/voronoi, core/material_library, spatial/incremental_bvh, spatial/kd_tree, curves/bezier_surface, capi/capi_extended, and expand mesh/halfedge + mesh/delaunay
- Fix 30+ compilation errors: missing includes, undefined symbols, circular dependencies, namespace issues, API mismatches
- Implement missing functions: point_to_plane_icp, colored_icp, scale_aware_registration, polygon_offset_arc, multi_contour_offset, offset_quality_check, validate_style, available_standards, add_vertex_unique, angle_distribution
- Fix infinite recursion in MaterialDatabase constructor
- Fix polygon_offset normal direction (inward -> outward)
- Fix viewport_bounds out-of-bounds handling
- Add linker group flags for static library circular dependencies
- 87% test pass rate (4479 tests, 592 pre-existing failures)
2026-08-03 13:28:13 +08:00

151 lines
4.4 KiB
C++

#include <gtest/gtest.h>
#include "vde/core/material_library.h"
#include <algorithm>
using namespace vde::core;
// ═══ MaterialDatabase 基础测试 ═══
TEST(MaterialLibraryTest, InitPopulatesDatabase) {
init_native_material_db();
EXPECT_GT(MaterialDatabase::instance().count(), 0u);
}
TEST(MaterialLibraryTest, Singleton_ReturnsSameReference) {
auto& a = MaterialDatabase::instance();
auto& b = MaterialDatabase::instance();
EXPECT_EQ(&a, &b);
}
TEST(MaterialLibraryTest, Count_GreaterThanZero) {
init_native_material_db();
EXPECT_GT(MaterialDatabase::instance().count(), 0u);
}
TEST(MaterialLibraryTest, Get_SteelReturnsValid) {
init_native_material_db();
auto mat = MaterialDatabase::instance().get("Steel A36");
ASSERT_TRUE(mat.has_value());
EXPECT_EQ(mat->name, "Steel A36");
EXPECT_FALSE(mat->category.empty());
}
TEST(MaterialLibraryTest, Get_NonExistentReturnsNullopt) {
init_native_material_db();
auto mat = MaterialDatabase::instance().get("Unobtanium");
EXPECT_FALSE(mat.has_value());
}
TEST(MaterialLibraryTest, All_ReturnsAllMaterials) {
init_native_material_db();
auto all = MaterialDatabase::instance().all();
EXPECT_EQ(all.size(), MaterialDatabase::instance().count());
EXPECT_FALSE(all.empty());
}
TEST(MaterialLibraryTest, Add_IncreasesCount) {
auto& db = MaterialDatabase::instance();
size_t before = db.count();
MaterialProperties mat;
mat.name = "Testium";
mat.category = "metal";
mat.density_kgm3 = 9999.0;
db.add(mat);
EXPECT_EQ(db.count(), before + 1);
}
TEST(MaterialLibraryTest, Add_CanRetrieveAdded) {
auto& db = MaterialDatabase::instance();
MaterialProperties mat;
mat.name = "CustomAlloy";
mat.category = "metal";
mat.density_kgm3 = 7200.0;
mat.yield_strength_mpa = 500.0;
db.add(mat);
auto retrieved = db.get("CustomAlloy");
ASSERT_TRUE(retrieved.has_value());
EXPECT_EQ(retrieved->name, "CustomAlloy");
EXPECT_DOUBLE_EQ(retrieved->density_kgm3, 7200.0);
}
TEST(MaterialLibraryTest, Clear_ResetsCount) {
auto& db = MaterialDatabase::instance();
db.clear();
EXPECT_EQ(db.count(), 0u);
}
// ═══ material_search 测试 ═══
TEST(MaterialLibraryTest, Search_ByCategory) {
init_native_material_db();
MaterialSearchQuery q;
q.category = "metal";
auto results = material_search(q);
EXPECT_FALSE(results.empty());
for (auto& m : results) {
EXPECT_EQ(m.category, "metal");
}
}
TEST(MaterialLibraryTest, Search_ByDensityRange) {
init_native_material_db();
MaterialSearchQuery q;
q.min_density = 7000.0;
q.max_density = 9000.0;
auto results = material_search(q);
EXPECT_FALSE(results.empty());
for (auto& m : results) {
EXPECT_GE(m.density_kgm3, 7000.0);
EXPECT_LE(m.density_kgm3, 9000.0);
}
}
TEST(MaterialLibraryTest, Search_ByNamePattern) {
init_native_material_db();
MaterialSearchQuery q;
q.name_pattern = "Steel";
auto results = material_search(q);
EXPECT_FALSE(results.empty());
bool found = false;
for (auto& m : results) {
if (m.name.find("Steel") != std::string::npos) found = true;
}
EXPECT_TRUE(found);
}
// ═══ material_properties 便捷函数 ═══
TEST(MaterialLibraryTest, MaterialProperties_ConvenienceFunction) {
init_native_material_db();
auto props = material_properties("Steel A36");
ASSERT_TRUE(props.has_value());
EXPECT_EQ(props->name, "Steel A36");
}
TEST(MaterialLibraryTest, MaterialProperties_NonExistent) {
auto props = material_properties("FairyDust");
EXPECT_FALSE(props.has_value());
}
TEST(MaterialLibraryTest, MaterialProperties_FieldsPopulated) {
init_native_material_db();
auto props = material_properties("Steel A36");
ASSERT_TRUE(props.has_value());
EXPECT_FALSE(props->name.empty());
EXPECT_FALSE(props->category.empty());
EXPECT_GT(props->density_kgm3, 0.0);
EXPECT_GT(props->youngs_modulus_gpa, 0.0);
EXPECT_GE(props->poisson_ratio, 0.0);
EXPECT_LE(props->poisson_ratio, 0.5);
EXPECT_GT(props->yield_strength_mpa, 0.0);
EXPECT_FALSE(props->standard.empty());
}
TEST(MaterialLibraryTest, MaterialProperties_DensityReasonable) {
init_native_material_db();
auto all = MaterialDatabase::instance().all();
for (auto& m : all) {
EXPECT_GT(m.density_kgm3, 0.0);
EXPECT_LT(m.density_kgm3, 100000.0);
}
}