Add init and finish functionality
[platform/core/test/security-tests.git] / src / framework / src / test_runner_child.cpp
index e2efb02..fcb745e 100644 (file)
@@ -20,6 +20,7 @@
  * @brief       This file is the implementation file of test runner
  */
 #include <stddef.h>
+#include <dpl/assert.h>
 #include <dpl/test/test_failed.h>
 #include <dpl/test/test_ignored.h>
 #include <dpl/test/test_runner.h>
@@ -287,7 +288,7 @@ PipeWrapper::Status PipeWrapper::readHelp(void *buf, int size, time_t deadline)
     return SUCCESS;
 }
 
-void RunChildProc(TestRunner::TestCase procChild)
+void RunChildProc(const std::function<void(void)> &testFunc)
 {
     PipeWrapper pipe;
     if (!pipe.isReady()) {
@@ -339,9 +340,6 @@ void RunChildProc(TestRunner::TestCase procChild)
         // End Runner after current test
         TestRunnerSingleton::Instance().Terminate();
 
-        int code = CHILD_TEST_PASS;
-        std::string msg;
-
         bool allowLogs = TestRunnerSingleton::Instance().GetAllowChildLogs();
 
         close(STDIN_FILENO);
@@ -351,17 +349,20 @@ void RunChildProc(TestRunner::TestCase procChild)
 
         pipe.setUsage(PipeWrapper::WRITEONLY);
 
-        try {
-            procChild();
-        } catch (const DPL::Test::TestFailed &e) {
-            msg = e.GetMessage();
-            code = CHILD_TEST_FAIL;
-        } catch (const DPL::Test::TestIgnored &e) {
-            msg = e.GetMessage();
-            code = CHILD_TEST_IGNORED;
-        } catch (...) { // catch all exception generated by "user" code
-            msg = "unhandled exeception";
-            code = CHILD_TEST_FAIL;
+        int code;
+        std::string msg;
+        switch (TryCatch(testFunc, msg)) {
+            case TestResult::FailStatus::FAILED:
+                code = CHILD_TEST_FAIL;
+                break;
+            case TestResult::FailStatus::IGNORED:
+                code = CHILD_TEST_IGNORED;
+                break;
+            case TestResult::FailStatus::NONE:
+                code = CHILD_TEST_PASS;
+                break;
+            default:
+                Assert(false && "Unhandled fail status");
         }
 
         if (allowLogs) {