From: Mikko Rasa Date: Wed, 3 Mar 2021 23:42:11 +0000 (+0200) Subject: Support passing a parameter to a test function X-Git-Url: http://git.tdb.fi/?p=libs%2Ftest.git;a=commitdiff_plain;h=e1f68c3afcd3133184b0628c3e3225f43fb9e772 Support passing a parameter to a test function --- 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);