CKM: Extend test framework with multiple environment testing 01/43501/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 8 Jul 2015 11:18:34 +0000 (13:18 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 28 Jul 2015 09:11:04 +0000 (02:11 -0700)
[Problem] It's impossible to execute the same test in different environments.
[Solution] Add support for running the same test in multiple environments.

[Verification] Test with next commit

Change-Id: I8ad04d1d28364026f63cb2c5f44bad87e7b4343b

src/framework/include/dpl/test/test_case_extended.h
src/framework/include/dpl/test/test_runner.h

index 129365a..e970310 100644 (file)
@@ -77,6 +77,24 @@ private:
     std::function<void(std::tuple<Args...> &t)> m_testFunc;
 };
 
+typedef void(*TestFnType)();
+
+template<typename T>
+class TestCaseExt2 : public TestCase
+{
+public:
+    TestCaseExt2(const std::string &name, const TestFnType &testFunc)
+        : TestCase(name), m_testFunc(testFunc) {}
+
+private:
+    virtual void Init() { m_env.init(GetName()); }
+    virtual void Finish() { m_env.finish(); }
+    virtual void Test() { m_testFunc(); }
+
+    T m_env;
+    TestFnType m_testFunc;
+};
+
 } // namespace Test
 } // namespace DPL
 
index 8a14823..4f01833 100644 (file)
@@ -152,7 +152,54 @@ typedef DPL::Singleton<TestRunner> TestRunnerSingleton;
 
 TestResult::FailStatus TryCatch(const std::function<void(void)> &func, std::string &reason);
 
-}
+/*
+ * Test execution in multiple environments.
+ *
+ * To execute the same test in different environments provide an environment classes CLASS1, CLASS2,.... Classes have to
+ * provide init() & finish() methods to be called before and after execution in each environment.
+ * They should also provide suffix() method returning test case name suffix for given environment.
+ *
+ * Define the test as follows
+ *
+ * RUNNER_TEST_MULTIPLE(my_test, CLASS1, CLASS2,...)
+ * {
+ *     // do the test stuff
+ * }
+ *
+ * For each class C the order of operation will be as follows:
+ * - construct C (default constructor)
+ * - call init() on C object
+ * - call test case function
+ * - call finish() on C object
+ * - destroy the C object
+ */
+
+template <typename ...Args>
+struct StaticProc;
+
+template <typename First>
+struct StaticProc<First> {
+protected:
+    static void Internal(const std::string& name, const TestFnType& proc) {
+        TestRunnerSingleton::Instance().RegisterTest(
+                new TestCaseExt2<First>(name + First::suffix(), proc));
+    }
+};
+
+template <typename First, typename ...Args>
+struct StaticProc<First, Args...> : public StaticProc<First>, public StaticProc<Args...> {
+    static int Init(const std::string& name, const TestFnType& proc) {
+        StaticProc<First, Args...>::Internal(name, proc);
+        return 0;
+    }
+protected:
+    static void Internal(const std::string& name, const TestFnType& proc) {
+        StaticProc<First>::Internal(name, proc);
+        StaticProc<Args...>::Internal(name, proc);
+    }
+};
+
+} // Test
 } // namespace DPL
 
 #define RUNNER_TEST_GROUP_INIT(GroupName)                                 \
@@ -175,6 +222,12 @@ TestResult::FailStatus TryCatch(const std::function<void(void)> &func, std::stri
     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();                  \
     void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED)
 
+
+#define RUNNER_TEST_MULTIPLE(Proc, ...)                                                                  \
+    void Proc();                                                                                         \
+    const int DPL_UNUSED Static##Proc##InitVar = DPL::Test::StaticProc<__VA_ARGS__>::Init(#Proc, &Proc); \
+    void Proc()
+
 /**
  * ASSERT MACROS
  *