#include extern "C" { #include "vde/capi/vde_capi.h" } #include // ═══════════════════════════════════════════════════════════ // C API 扩展测试 — 句柄生命周期与 null 安全 // ═══════════════════════════════════════════════════════════ TEST(CApiExtendedTest, CreateDestroyContext) { VdeHandle ctx = vde_create(); ASSERT_NE(ctx, nullptr); vde_destroy(ctx); // vde_destroy 后不应 crash } TEST(CApiExtendedTest, VersionString) { const char* ver = vde_version(); ASSERT_NE(ver, nullptr); EXPECT_GT(strlen(ver), 0u); } TEST(CApiExtendedTest, LastErrorEmpty) { VdeHandle ctx = vde_create(); const char* err = vde_last_error(ctx); // 刚创建时应为 null 或空字符串 if (err != nullptr) { EXPECT_EQ(strlen(err), 0u); } vde_destroy(ctx); } TEST(CApiExtendedTest, CreateBodyBox) { VdeHandle ctx = vde_create(); VdeBodyHandle body = vde_body_create_box(ctx, 1.0, 2.0, 3.0); ASSERT_NE(body, nullptr); vde_body_free(body); vde_destroy(ctx); } TEST(CApiExtendedTest, CreateBodyCylinder) { VdeHandle ctx = vde_create(); VdeBodyHandle body = vde_body_create_cylinder(ctx, 1.0, 3.0, 32); ASSERT_NE(body, nullptr); vde_body_free(body); vde_destroy(ctx); } TEST(CApiExtendedTest, CreateBodySphere) { VdeHandle ctx = vde_create(); VdeBodyHandle body = vde_body_create_sphere(ctx, 1.0, 32, 32); ASSERT_NE(body, nullptr); vde_body_free(body); vde_destroy(ctx); } TEST(CApiExtendedTest, FreeBodyNullSafe) { vde_body_free(nullptr); SUCCEED(); } TEST(CApiExtendedTest, FreeMeshNullSafe) { vde_mesh_free(nullptr); SUCCEED(); } TEST(CApiExtendedTest, FreeCurveNullSafe) { vde_curve_free(nullptr); SUCCEED(); } TEST(CApiExtendedTest, FreeSolverNullSafe) { vde_solver_free(nullptr); SUCCEED(); } TEST(CApiExtendedTest, CreateSolver) { VdeSolverHandle solver = vde_solver_create(); ASSERT_NE(solver, nullptr); vde_solver_free(solver); } TEST(CApiExtendedTest, CreateCurveBezier) { VdeHandle ctx = vde_create(); // 4 个控制点 → 3 次 Bézier 曲线 double cp[] = { 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 3.0, 2.0, 0.0, 4.0, 0.0, 0.0 }; VdeCurveHandle curve = vde_curve_create_bezier(ctx, cp, 4, 3); ASSERT_NE(curve, nullptr); EXPECT_EQ(vde_curve_degree(curve), 3); vde_curve_free(curve); vde_destroy(ctx); }