Skip to content

Commit

Permalink
Add unit tests for func_static creation and rendering
Browse files Browse the repository at this point in the history
Confirm that func_static renders nothing without a "model" key, then the
expected number of renderables once a model is set.
  • Loading branch information
Matthew Mott committed Feb 9, 2021
1 parent 3bd99f9 commit b77588d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/irender.h
Expand Up @@ -219,8 +219,8 @@ inline std::ostream& operator<< (std::ostream& os, const RendererLight& l)
}

/**
* \brief
* Interface for an object which can test its intersection with a RendererLight.
* \brief Interface for an object which can test its intersection with a
* RendererLight.
*
* Objects which implement this interface define a intersectsLight() function
* which determines whether the given light intersects the object.
Expand Down
45 changes: 45 additions & 0 deletions test/Entity.cpp
Expand Up @@ -329,6 +329,14 @@ namespace
RenderFixture(bool solid = false): renderSolid(solid)
{}

// Convenience method to set render backend and traverse a node and its
// children for rendering
void renderSubGraph(const scene::INodePtr& node)
{
node->setRenderSystem(backend);
node->traverse(*this);
}

// NodeVisitor implementation
bool pre(const scene::INodePtr& node) override
{
Expand Down Expand Up @@ -434,6 +442,43 @@ TEST_F(EntityTest, RenderLightAsLightSource)
"lights/biground_torchflicker");
}

TEST_F(EntityTest, RenderEmptyFuncStatic)
{
auto funcStatic = createByClassName("func_static");

// Func static without a model key is empty
RenderFixture rf;
funcStatic->traverse(rf);
EXPECT_EQ(rf.collector.lights, 0);
EXPECT_EQ(rf.collector.renderables, 0);
}

TEST_F(EntityTest, RenderFuncStaticWithModel)
{
// Create a func_static with a model key
auto funcStatic = createByClassName("func_static");
funcStatic->getEntity().setKeyValue("model", "models/moss_patch.ase");

// We should get one renderable
RenderFixture rf;
rf.renderSubGraph(funcStatic);
EXPECT_EQ(rf.collector.lights, 0);
EXPECT_EQ(rf.collector.renderables, 1);
}

TEST_F(EntityTest, RenderFuncStaticWithMultiSurfaceModel)
{
// Create a func_static with a model key
auto funcStatic = createByClassName("func_static");
funcStatic->getEntity().setKeyValue("model", "models/torch.lwo");

// This torch model has 3 renderable surfaces
RenderFixture rf;
rf.renderSubGraph(funcStatic);
EXPECT_EQ(rf.collector.lights, 0);
EXPECT_EQ(rf.collector.renderables, 3);
}

TEST_F(EntityTest, CreateAttachedLightEntity)
{
// Create the torch entity which has an attached light
Expand Down

0 comments on commit b77588d

Please sign in to comment.