* @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
*/
#include <cstdlib>
#include <cstring>
#include <exception>
+#include <functional>
#include <iostream>
#include <list>
#include <map>
#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>
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;
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();
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);
};
typedef DPL::Singleton<TestRunner> TestRunnerSingleton;
+
+TestResult::FailStatus TryCatch(const std::function<void(void)> &func, std::string &reason);
+
}
} // namespace DPL
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