Skip to content

Commit

Permalink
Add system singleton tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cfnptr committed Oct 28, 2024
1 parent bf9e92f commit 7d668d4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/test-ecsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct TestComponent final : public Component
}
};

class TestSystem final : public ComponentSystem<TestComponent>
class TestSystem final : public ComponentSystem<TestComponent>, Singleton<TestSystem>
{
TestSystem()
{
Expand Down Expand Up @@ -114,6 +114,8 @@ static void testCommonFlow()

auto system = manager->get<TestSystem>();

if (system != TestSystem::Instance::get())
throw runtime_error("Different manager and system singleton instance.");
if (system->isInitialized != false)
throw runtime_error("Test system is already initialized.");

Expand Down Expand Up @@ -147,10 +149,13 @@ static void testCommonFlow()

if (testView->ID != 1 || testView->someData != 123.456f)
throw runtime_error("Bad test component data before update.");

if (system->updateCounter != 0 || system->postUpdateCounter != 0)
throw runtime_error("Bad test system data before update.");

auto singletonTestView = TestSystem::Instance::get()->getComponent(testEntity);
if (testView != singletonTestView)
throw runtime_error("Different manager and system singleton component views.");

manager->update();

if (system->updateCounter != 1 || system->postUpdateCounter != 2)
Expand Down

0 comments on commit 7d668d4

Please sign in to comment.