144 lines
3.7 KiB
C++
144 lines
3.7 KiB
C++
#include <gtest/gtest.h>
|
|
#include <XCEngine/Resources/Mesh/Mesh.h>
|
|
#include <XCEngine/Resources/Material/Material.h>
|
|
#include <XCEngine/Core/Asset/ResourceTypes.h>
|
|
#include <XCEngine/Core/Asset/ResourceManager.h>
|
|
|
|
using namespace XCEngine::Resources;
|
|
using namespace XCEngine::Math;
|
|
|
|
namespace {
|
|
|
|
struct TrackingMaterial final : Material {
|
|
static int s_destructorCount;
|
|
|
|
~TrackingMaterial() override {
|
|
++s_destructorCount;
|
|
}
|
|
};
|
|
|
|
int TrackingMaterial::s_destructorCount = 0;
|
|
|
|
struct TrackingTexture final : Texture {
|
|
static int s_destructorCount;
|
|
|
|
~TrackingTexture() override {
|
|
++s_destructorCount;
|
|
}
|
|
};
|
|
|
|
int TrackingTexture::s_destructorCount = 0;
|
|
|
|
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, ReleaseDeletesOwnedSubresourcesOnce) {
|
|
TrackingMaterial::s_destructorCount = 0;
|
|
TrackingTexture::s_destructorCount = 0;
|
|
|
|
auto* mesh = new Mesh();
|
|
mesh->AddMaterial(new TrackingMaterial());
|
|
mesh->AddTexture(new TrackingTexture());
|
|
|
|
mesh->Release();
|
|
|
|
EXPECT_EQ(TrackingMaterial::s_destructorCount, 1);
|
|
EXPECT_EQ(TrackingTexture::s_destructorCount, 1);
|
|
EXPECT_EQ(mesh->GetMaterials().Size(), 0u);
|
|
EXPECT_EQ(mesh->GetTextures().Size(), 0u);
|
|
|
|
delete mesh;
|
|
|
|
EXPECT_EQ(TrackingMaterial::s_destructorCount, 1);
|
|
EXPECT_EQ(TrackingTexture::s_destructorCount, 1);
|
|
}
|
|
|
|
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
|