#include #include #include #include #include using namespace XCEngine::Resources; using namespace XCEngine::Math; namespace { TEST(Mesh, DefaultConstructor) { Mesh mesh; EXPECT_EQ(mesh.GetVertexCount(), 0u); EXPECT_EQ(mesh.GetIndexCount(), 0u); EXPECT_EQ(mesh.GetVertexStride(), 0u); EXPECT_FALSE(mesh.IsUse32BitIndex()); } TEST(Mesh, GetType) { Mesh mesh; EXPECT_EQ(mesh.GetType(), ResourceType::Mesh); } TEST(Mesh, GetMemorySize) { Mesh mesh; EXPECT_EQ(mesh.GetMemorySize(), 0u); } TEST(Mesh, GetSections) { Mesh mesh; EXPECT_EQ(mesh.GetSections().Size(), 0u); } TEST(Mesh, GetMaterials) { Mesh mesh; EXPECT_EQ(mesh.GetMaterials().Size(), 0u); } TEST(Mesh, SetVertexAndIndexData) { Mesh mesh; StaticMeshVertex vertices[3]; vertices[0].position = Vector3(0.0f, 0.0f, 0.0f); vertices[1].position = Vector3(1.0f, 0.0f, 0.0f); vertices[2].position = Vector3(0.0f, 1.0f, 0.0f); const uint16_t indices[3] = {0, 1, 2}; mesh.SetVertexData(vertices, sizeof(vertices), 3, sizeof(StaticMeshVertex), VertexAttribute::Position | VertexAttribute::Normal | VertexAttribute::UV0); mesh.SetIndexData(indices, sizeof(indices), 3, false); EXPECT_EQ(mesh.GetVertexCount(), 3u); EXPECT_EQ(mesh.GetIndexCount(), 3u); EXPECT_EQ(mesh.GetVertexStride(), sizeof(StaticMeshVertex)); EXPECT_TRUE(HasVertexAttribute(mesh.GetVertexAttributes(), VertexAttribute::Position)); EXPECT_TRUE(HasVertexAttribute(mesh.GetVertexAttributes(), VertexAttribute::Normal)); EXPECT_TRUE(HasVertexAttribute(mesh.GetVertexAttributes(), VertexAttribute::UV0)); EXPECT_GT(mesh.GetMemorySize(), 0u); } TEST(Mesh, AddSection) { Mesh mesh; MeshSection section{}; section.baseVertex = 1; section.vertexCount = 3; section.startIndex = 6; section.indexCount = 9; section.materialID = 2; mesh.AddSection(section); ASSERT_EQ(mesh.GetSections().Size(), 1u); EXPECT_EQ(mesh.GetSections()[0].baseVertex, 1u); EXPECT_EQ(mesh.GetSections()[0].materialID, 2u); } TEST(Mesh, AddMaterial) { Mesh mesh; auto* material = new Material(); mesh.AddMaterial(material); ASSERT_EQ(mesh.GetMaterials().Size(), 1u); EXPECT_EQ(mesh.GetMaterial(0), material); EXPECT_GT(mesh.GetMemorySize(), 0u); } TEST(Mesh, SetBounds) { Mesh mesh; Bounds bounds; bounds.SetMinMax(Vector3(-1.0f, -2.0f, -3.0f), Vector3(1.0f, 2.0f, 3.0f)); mesh.SetBounds(bounds); EXPECT_EQ(mesh.GetBounds().GetMin(), Vector3(-1.0f, -2.0f, -3.0f)); EXPECT_EQ(mesh.GetBounds().GetMax(), Vector3(1.0f, 2.0f, 3.0f)); } } // namespace