From e1f68c3afcd3133184b0628c3e3225f43fb9e772 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 4 Mar 2021 01:42:11 +0200 Subject: [PATCH] Support passing a parameter to a test function --- source/function.h | 24 +++++++++++++++++++++++- source/test.h | 7 +++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/source/function.h b/source/function.h index b76426e..a50b5c1 100644 --- a/source/function.h +++ b/source/function.h @@ -39,7 +39,7 @@ private: FuncPtr func; public: - TypedFunction(FuncPtr f, const std::string & d): + TypedFunction(FuncPtr f, const std::string &d): Function(d), func(f) { } @@ -50,6 +50,28 @@ public: } }; +template +class TypedFunction1: public Function +{ +private: + typedef void (T::*FuncPtr)(A); + + FuncPtr func; + A arg; + +public: + TypedFunction1(FuncPtr f, const A &a, const std::string &d): + Function(d), + func(f), + arg(a) + { } + + virtual void run(Test &t) const + { + (dynamic_cast(t).*func)(arg); + } +}; + } // namespace Test } // namespace Msp diff --git a/source/test.h b/source/test.h index a6dad93..0b12dbe 100644 --- a/source/test.h +++ b/source/test.h @@ -61,6 +61,13 @@ protected: return *functions.back(); } + template + Function &add(void (T::*f)(A), const A &a, const std::string &d) + { + functions.push_back(new TypedFunction1(f, a, d)); + return *functions.back(); + } + public: static void run_single(const std::string &, bool); static void run_all(bool); -- 2.45.2