]> git.tdb.fi Git - libs/test.git/commitdiff
Support passing a parameter to a test function master
authorMikko Rasa <tdb@tdb.fi>
Wed, 3 Mar 2021 23:42:11 +0000 (01:42 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 3 Mar 2021 23:42:11 +0000 (01:42 +0200)
source/function.h
source/test.h

index b76426ec2bf1df3735421f50ed81dd0f27a6bb18..a50b5c1d33252e5bae7159a82eae47f35c416af5 100644 (file)
@@ -39,7 +39,7 @@ private:
        FuncPtr func;
 
 public:
        FuncPtr func;
 
 public:
-       TypedFunction(FuncPtr f, const std::string & d):
+       TypedFunction(FuncPtr f, const std::string &d):
                Function(d),
                func(f)
        { }
                Function(d),
                func(f)
        { }
@@ -50,6 +50,28 @@ public:
        }
 };
 
        }
 };
 
+template<typename T, typename A>
+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 &>(t).*func)(arg);
+       }
+};
+
 } // namespace Test
 } // namespace Msp
 
 } // namespace Test
 } // namespace Msp
 
index a6dad93f2dede3c7c6f0460cfec4c7ccd5c1d45c..0b12dbefa9a6a16d4c7534e55cc09bf6c2cfe886 100644 (file)
@@ -61,6 +61,13 @@ protected:
                return *functions.back();
        }
 
                return *functions.back();
        }
 
+       template<typename T, typename A>
+       Function &add(void (T::*f)(A), const A &a, const std::string &d)
+       {
+               functions.push_back(new TypedFunction1<T, A>(f, a, d));
+               return *functions.back();
+       }
+
 public:
        static void run_single(const std::string &, bool);
        static void run_all(bool);
 public:
        static void run_single(const std::string &, bool);
        static void run_all(bool);