Use functor object as main argument of callAndWait
[platform/core/test/security-tests.git] / src / common / timeout.h
index 7e985ab..98662e1 100644 (file)
@@ -25,6 +25,7 @@
 #include <chrono>
 #include <functional>
 #include <future>
+#include <type_traits>
 #include <utility>
 
 #include <tests_common.h>
@@ -34,9 +35,6 @@ namespace Timeout {
 template <class Rep, class Period>
 using Timeout = std::chrono::duration<Rep, Period>;
 
-template <class Ret, class... Args>
-using Function = std::function<Ret(Args...)>;
-
 typedef std::function<void(void)> CancelFunction;
 
 enum ExpectMode {
@@ -62,16 +60,15 @@ std::ostream& operator<<(std::ostream& os, const std::future_status &status)
     return os;
 }
 
-template <class Rep, class Period, class Ret, class... Args>
-Ret callAndWait(const Timeout<Rep, Period> &timeout,
+template <class Rep, class Period, class F, class... Args>
+    typename std::result_of<F(Args...)>::type
+    callAndWait(const Timeout<Rep, Period> &timeout,
                  ExpectMode expect,
                  CancelFunction cancelFunction,
-                 Function<Ret, Args...> function,
-                 Args... args) {
-    RUNNER_ASSERT_MSG(function,
-                         "not empty function must be passed to callAndWait");
+                 F&& function,
+                 Args&&... args) {
 
-    std::future<Ret> fut = std::async(std::launch::async, function, std::forward<Args>(args)...);
+    auto fut = std::async(std::launch::async, function, std::forward<Args>(args)...);
     std::future_status status = fut.wait_for(timeout);
 
     if (status == std::future_status::timeout && cancelFunction)