-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d21a2c6
commit 02508fa
Showing
7 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
test_Manager | ||
test_System | ||
test_Entity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
AM_CPPFLAGS = ${CATCH2_CFLAGS} -I../include | ||
|
||
check_PROGRAMS = test_Manager | ||
check_PROGRAMS = test_Manager test_System test_Entity | ||
|
||
test_Manager_SOURCES = test_Manager.cpp | ||
test_Manager_LDADD = ../src/libecs-cpp.la | ||
|
||
test_System_SOURCES = test_System.cpp | ||
test_System_LDADD = ../src/libecs-cpp.la | ||
|
||
test_Entity_SOURCES = test_Entity.cpp | ||
test_Entity_LDADD = ../src/libecs-cpp.la |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#include <catch2/catch.hpp> | ||
#include <libecs-cpp/ecs.hpp> | ||
|
||
class TestComponent : public ecs::Component | ||
{ | ||
public: | ||
TestComponent() | ||
{ | ||
this->Type = "TestComponent"; | ||
} | ||
|
||
TestComponent(nlohmann::json config) | ||
{ | ||
this->Type = "TestComponent"; | ||
this->value = config["value"].get<uint64_t>(); | ||
} | ||
|
||
nlohmann::json Export() | ||
{ | ||
nlohmann::json config; | ||
config["value"] = this->value; | ||
return config; | ||
} | ||
|
||
uint64_t value = 0; | ||
}; | ||
|
||
TEST_CASE("Entity is created with a unique handle", "[Entity]") { | ||
auto container = ECS->Container(); | ||
auto entity = container->Entity(); | ||
REQUIRE_FALSE(entity->Handle.empty()); | ||
} | ||
|
||
TEST_CASE("Entity can be created with a custom handle", "[Entity]") { | ||
std::string customHandle = "myEntity"; | ||
auto container = ECS->Container(); | ||
auto entity = container->Entity(customHandle); | ||
REQUIRE(entity->Handle == customHandle); | ||
} | ||
|
||
TEST_CASE("Entity exports its data correctly", "[Entity]") { | ||
auto container = ECS->Container(); | ||
auto entity = container->Entity(); | ||
nlohmann::json exportedData = entity->Export(); | ||
REQUIRE(exportedData["Handle"] == entity->Handle); | ||
} | ||
|
||
TEST_CASE("Entity can add and retrieve a component", "[Entity]") { | ||
auto container = ECS->Container(); | ||
auto entity = container->Entity(); | ||
nlohmann::json config; | ||
config["value"] = 5; | ||
//auto component = std::make_shared<TestComponent>(config); | ||
entity->Component(new TestComponent(config)); | ||
auto retrievedComponent = container->Components["TestComponent"][entity->Handle]; | ||
REQUIRE(retrievedComponent != nullptr); | ||
} | ||
|
||
TEST_CASE("Entity can destroy a component", "[Entity]") { | ||
auto container = ECS->Container(); | ||
auto entity = container->Entity(); | ||
nlohmann::json config; | ||
config["value"] = 5; | ||
entity->Component(new TestComponent(config)); | ||
entity->ComponentDestroy("TestComponent"); | ||
auto retrievedComponent = container->Components["TestComponent"][entity->Handle]; | ||
REQUIRE(retrievedComponent == nullptr); | ||
} | ||
|
||
TEST_CASE("Entity can be destroyed", "[Entity]") { | ||
auto container = ECS->Container(); | ||
auto entity = container->Entity(); | ||
std::string handle = entity->Handle; | ||
entity->Destroy(); | ||
// Assuming there is a way to check if an entity has been destroyed, e.g.: | ||
REQUIRE(container->Entities[handle] == nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#include <catch2/catch.hpp> | ||
#include <libecs-cpp/ecs.hpp> | ||
|
||
class TestSystem : public ecs::System | ||
{ | ||
public: | ||
TestSystem() | ||
{ | ||
this->Handle = "TestSystem"; | ||
} | ||
|
||
TestSystem(std::string Handle) | ||
{ | ||
this->Handle = Handle; | ||
} | ||
|
||
nlohmann::json Export() | ||
{ | ||
nlohmann::json config; | ||
return config; | ||
} | ||
|
||
}; | ||
|
||
TEST_CASE("System is initialized with a valid handle", "[System]") { | ||
TestSystem system; | ||
REQUIRE_FALSE(system.Handle.empty()); | ||
} | ||
|
||
TEST_CASE("System can be initialized with a custom handle", "[System]") { | ||
std::string customHandle = "custom_handle"; | ||
TestSystem system(customHandle); | ||
REQUIRE(system.Handle == customHandle); | ||
} | ||
|
||
TEST_CASE("System starts with no messages", "[System]") { | ||
TestSystem system; | ||
REQUIRE(system.MessagesWaiting() == 0); | ||
} | ||
|
||
TEST_CASE("System can submit messages", "[System]") { | ||
TestSystem system; | ||
nlohmann::json message = {{"key", "value"}}; | ||
system.MessageSubmit(message); | ||
REQUIRE(system.MessagesWaiting() == 1); | ||
} | ||
|
||
TEST_CASE("System can calculate delta time", "[System]") { | ||
TestSystem system; | ||
// First call to initialize LastTime | ||
system.DeltaTimeGet(); | ||
// Small sleep to simulate passage of time | ||
std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
uint32_t deltaTime = system.DeltaTimeGet(); | ||
REQUIRE(deltaTime >= 10); // Check if at least 10ms have passed | ||
} |