Bläddra i källkod

process: safety net

Michele Caini 7 månader sedan
förälder
incheckning
e35eed905b

+ 2 - 1
src/entt/process/process.hpp

@@ -186,7 +186,8 @@ public:
      * @param child A child process to run in case of success.
      * @return A reference to the newly assigned child process.
      */
-    basic_process &then(std::shared_ptr<basic_process> child){
+    basic_process &then(std::shared_ptr<basic_process> child) {
+        ENTT_ASSERT(child, "Null process not allowed");
         return *(next = std::move(child));
     }
 

+ 1 - 0
src/entt/process/scheduler.hpp

@@ -150,6 +150,7 @@ public:
      */
     template<typename Proc>
     type &attach(std::shared_ptr<Proc> proc) {
+        ENTT_ASSERT(proc, "Null process not allowed");
         return *handlers.first().emplace_back(std::move(proc));
     }
 

+ 7 - 0
test/entt/process/process.cpp

@@ -2,6 +2,7 @@
 #include <memory>
 #include <gtest/gtest.h>
 #include <entt/process/process.hpp>
+#include "../../common/config.h"
 #include "../../common/empty.h"
 
 template<typename Delta>
@@ -199,6 +200,12 @@ TEST(Process, ThenPeek) {
     ASSERT_TRUE(process->peek());
 }
 
+ENTT_DEBUG_TEST(ProcessDeathTest, Then) {
+    auto process = std::make_shared<test_process<int>>();
+
+    ASSERT_DEATH(process->then(nullptr), "");
+}
+
 TEST(ProcessAdaptor, Resolved) {
     bool updated = false;
     auto lambda = [&updated](entt::process &proc, std::uint32_t, void *) {

+ 8 - 1
test/entt/process/scheduler.cpp

@@ -4,6 +4,7 @@
 #include <gtest/gtest.h>
 #include <entt/process/process.hpp>
 #include <entt/process/scheduler.hpp>
+#include "../../common/config.h"
 
 class foo_process: public entt::process {
     void update(const delta_type, void *) override {
@@ -104,7 +105,7 @@ TEST(Scheduler, Swap) {
     ASSERT_EQ(counter, 2);
 }
 
-TEST(Scheduler, Then) {
+TEST(Scheduler, AttachThen) {
     entt::scheduler scheduler{};
     std::pair<int, int> counter{};
 
@@ -131,6 +132,12 @@ TEST(Scheduler, Then) {
     ASSERT_EQ(counter.second, 2u);
 }
 
+ENTT_DEBUG_TEST(SchedulerDeathTest, Attach) {
+    entt::scheduler scheduler{};
+
+    ASSERT_DEATH(scheduler.attach<succeeded_process>(nullptr), "");
+}
+
 TEST(Scheduler, Functor) {
     entt::scheduler scheduler{};