feat(editor): add audio and physics component editor coverage

This commit is contained in:
2026-04-15 12:15:13 +08:00
parent 34aca206ce
commit 9c5b19a928
11 changed files with 891 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
#include <gtest/gtest.h>
#include <XCEngine/Components/BoxColliderComponent.h>
#include <XCEngine/Components/CapsuleColliderComponent.h>
#include <XCEngine/Components/RigidbodyComponent.h>
#include <XCEngine/Components/SphereColliderComponent.h>
#include <XCEngine/Physics/PhysicsTypes.h>
#include <sstream>
using namespace XCEngine::Components;
namespace {
TEST(PhysicsComponents_Test, Rigidbody_SerializeRoundTripPreservesFields) {
RigidbodyComponent source;
source.SetBodyType(XCEngine::Physics::PhysicsBodyType::Kinematic);
source.SetMass(3.5f);
source.SetLinearDamping(0.2f);
source.SetAngularDamping(0.8f);
source.SetUseGravity(false);
source.SetEnableCCD(true);
std::stringstream stream;
source.Serialize(stream);
RigidbodyComponent target;
target.Deserialize(stream);
EXPECT_EQ(target.GetBodyType(), XCEngine::Physics::PhysicsBodyType::Kinematic);
EXPECT_FLOAT_EQ(target.GetMass(), 3.5f);
EXPECT_FLOAT_EQ(target.GetLinearDamping(), 0.2f);
EXPECT_FLOAT_EQ(target.GetAngularDamping(), 0.8f);
EXPECT_FALSE(target.GetUseGravity());
EXPECT_TRUE(target.GetEnableCCD());
}
TEST(PhysicsComponents_Test, BoxCollider_SerializeRoundTripPreservesFields) {
BoxColliderComponent source;
source.SetTrigger(true);
source.SetCenter(XCEngine::Math::Vector3(1.0f, 2.0f, 3.0f));
source.SetStaticFriction(0.7f);
source.SetDynamicFriction(0.2f);
source.SetRestitution(0.4f);
source.SetSize(XCEngine::Math::Vector3(2.0f, 4.0f, 6.0f));
std::stringstream stream;
source.Serialize(stream);
BoxColliderComponent target;
target.Deserialize(stream);
EXPECT_TRUE(target.IsTrigger());
EXPECT_EQ(target.GetCenter(), XCEngine::Math::Vector3(1.0f, 2.0f, 3.0f));
EXPECT_FLOAT_EQ(target.GetStaticFriction(), 0.7f);
EXPECT_FLOAT_EQ(target.GetDynamicFriction(), 0.2f);
EXPECT_FLOAT_EQ(target.GetRestitution(), 0.4f);
EXPECT_EQ(target.GetSize(), XCEngine::Math::Vector3(2.0f, 4.0f, 6.0f));
}
TEST(PhysicsComponents_Test, SphereCollider_InvalidRadiusIsSanitized) {
SphereColliderComponent sphere;
sphere.SetRadius(-10.0f);
EXPECT_GT(sphere.GetRadius(), 0.0f);
}
TEST(PhysicsComponents_Test, CapsuleCollider_HeightStaysAtLeastDiameter) {
CapsuleColliderComponent capsule;
capsule.SetRadius(1.25f);
capsule.SetHeight(1.0f);
capsule.SetAxis(ColliderAxis::Z);
EXPECT_FLOAT_EQ(capsule.GetRadius(), 1.25f);
EXPECT_FLOAT_EQ(capsule.GetHeight(), 2.5f);
EXPECT_EQ(capsule.GetAxis(), ColliderAxis::Z);
}
} // namespace