Add init and finish functionality
[platform/core/test/security-tests.git] / src / framework / include / dpl / test / test_runner.h
index ee1d7c3..8a14823 100644 (file)
@@ -17,6 +17,7 @@
  * @file        test_runner.h
  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
  * @version     1.0
  * @brief       This file is the header file of test runner
  */
@@ -28,6 +29,7 @@
 #include <cstdlib>
 #include <cstring>
 #include <exception>
+#include <functional>
 #include <iostream>
 #include <list>
 #include <map>
@@ -43,6 +45,8 @@
 #include <dpl/gdbbacktrace.h>
 #include <dpl/singleton.h>
 #include <dpl/test/performance_result.h>
+#include <dpl/test/test_case.h>
+#include <dpl/test/test_case_extended.h>
 #include <dpl/test/test_exception.h>
 #include <dpl/test/test_failed.h>
 #include <dpl/test/test_ignored.h>
@@ -78,36 +82,18 @@ class TestRunner
 
     void addFailReason(const std::string &reason);
 
-    typedef void (*TestCase)();
+    ~TestRunner();
 
   private:
-    struct TestCaseStruct
-    {
-        std::string name;
-        TestCase proc;
-        PerformanceResultPtr performance;
-
-        bool operator <(const TestCaseStruct &other) const
-        {
-            return name < other.name;
-        }
-
-        bool operator ==(const TestCaseStruct &other) const
-        {
-            return name == other.name;
-        }
-
-        TestCaseStruct(const std::string &n, TestCase p) :
-            name(n),
-            proc(p)
-        {}
-    };
-
-    typedef std::list<TestCaseStruct> TestCaseStructList;
-    typedef std::map<std::string, TestCaseStructList> TestCaseGroupMap;
+    typedef std::list<TestCasePtr> TestCaseList;
+    typedef std::map<std::string, TestCaseList> TestCaseGroupMap;
+    typedef std::set<TestCasePtr> TestCaseSet;
+
     TestCaseGroupMap m_testGroups;
+    TestCaseSet m_testCaseSet;
+
+    TestCasePtr m_currentTestCase;
 
-    TestCaseStruct * m_currentTestCase;
 
     std::string m_currentGroup;
 
@@ -125,10 +111,10 @@ class TestRunner
     bool filterByXML(std::map<std::string, bool> & casesMap);
     void normalizeXMLTag(std::string& str, const std::string& testcase);
 
-    void RunTestCase(const TestCaseStruct& testCase);
+    void RunTestCase(TestCasePtr testCase);
 
-    void setCurrentTestCase(TestCaseStruct* testCase);
-    TestCaseStruct *getCurrentTestCase();
+    void setCurrentTestCase(TestCasePtr testCase);
+    TestCasePtr getCurrentTestCase();
 
     void RunTests();
 
@@ -137,9 +123,8 @@ class TestRunner
     void CollectResult(const std::string& id, const TestResult &result);
 
   public:
-    void RegisterTest(const char *testName, TestCase proc);
     void InitGroup(const char* name);
-
+    void RegisterTest(TestCasePtr testCase);
     int ExecTestRunner(int argc, char *argv[]);
     typedef std::vector<std::string> ArgsList;
     int ExecTestRunner(ArgsList args);
@@ -164,6 +149,9 @@ private:
 };
 
 typedef DPL::Singleton<TestRunner> TestRunnerSingleton;
+
+TestResult::FailStatus TryCatch(const std::function<void(void)> &func, std::string &reason);
+
 }
 } // namespace DPL
 
@@ -176,16 +164,16 @@ typedef DPL::Singleton<TestRunner> TestRunnerSingleton;
     const int DPL_UNUSED Static##GroupName##InitVar =                     \
         Static##GroupName##Init();
 
-#define RUNNER_TEST(Proc)                                                      \
-    void Proc();                                                               \
-    static int Static##Proc##Init()                                            \
-    {                                                                          \
-        DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
-        return 0;                                                              \
-    }                                                                          \
-    const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();         \
-    void Proc()
-
+#define RUNNER_TEST(Proc, ...)                                                          \
+    void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple);                              \
+    static int Static##Proc##Init()                                                     \
+    {                                                                                   \
+        DPL::Test::TestRunnerSingleton::Instance().RegisterTest(                        \
+            new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc));                \
+        return 0;                                                                       \
+    }                                                                                   \
+    const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();                  \
+    void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
 
 /**
  * ASSERT MACROS