+
+TEST(FuncHelpersTest, invokeLambdaWithArgsListAndReturnValue)
+{
+ int intVal{};
+ QString stringVal{};
+
+ auto callable = [&intVal, &stringVal](int i, const QString& s)
+ {
+ intVal = i;
+ stringVal = s;
+ return -i;
+ };
+
+ // Good case
+ {
+ auto ret = invokeWithArgsList(callable, {42, "Hello World"});
+ ASSERT_TRUE(ret);
+ ASSERT_TRUE(ret->isValid());
+ EXPECT_EQ(-42, *ret);
+ EXPECT_EQ(42, intVal);
+ EXPECT_EQ("Hello World", stringVal);
+ }
+
+ // Failed invocation
+ {
+ ASSERT_FALSE(invokeWithArgsList(callable, {23}));
+ }
+}
+
+class Object
+{
+public:
+ void voidFunc(int i, const QString& s)
+ {
+ intVal = i;
+ stringVal = s;
+ }
+
+ int intFunc(int i)
+ {
+ return -i;
+ }
+
+ int intVal{};
+ QString stringVal{};
+};
+
+TEST(FuncHelpersTest, invokeMemberFunction)
+{
+ Object object;
+
+ // Good case
+ {
+ auto ret = invokeWithArgsList(&object, &Object::voidFunc, {42, "Hello World"});
+ ASSERT_TRUE(ret);
+ EXPECT_FALSE(ret->isValid()); // Callable returns void, so the returned QVariant should be invalid
+ EXPECT_EQ(42, object.intVal);
+ EXPECT_EQ("Hello World", object.stringVal);
+ }
+
+ // Good case with return value
+ {
+ auto ret = invokeWithArgsList(&object, &Object::intFunc, {42});
+ ASSERT_TRUE(ret);
+ EXPECT_EQ(-42, *ret);
+ }
+
+ // Too few arguments
+ {
+ auto ret = invokeWithArgsList(&object, &Object::voidFunc, {23});
+ ASSERT_FALSE(ret);
+ EXPECT_EQ(42, object.intVal);
+ }
+}