1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "testglobal.h"
23 #include <QVariantList>
25 #include "funchelpers.h"
27 TEST(FuncHelpersTest, invokeWithArgsList)
32 auto callable = [&intVal, &stringVal](int i, const QString& s)
40 QVariantList argsList{42, "Hello World"};
41 auto ret = invokeWithArgsList(callable, argsList);
43 EXPECT_FALSE(ret->isValid()); // Callable returns void, so the returned QVariant should be invalid
44 EXPECT_EQ(42, intVal);
45 EXPECT_EQ("Hello World", stringVal);
50 QVariantList argsList{23, "Hi Universe", 2.3};
51 ASSERT_FALSE(invokeWithArgsList(callable, argsList));
52 // Values shouldn't have changed
53 EXPECT_EQ(42, intVal);
54 EXPECT_EQ("Hello World", stringVal);
59 QVariantList argsList{23};
60 ASSERT_FALSE(invokeWithArgsList(callable, argsList));
61 // Values shouldn't have changed
62 EXPECT_EQ(42, intVal);
63 EXPECT_EQ("Hello World", stringVal);
66 // Cannot convert argument type
68 // Ensure type cannot be converted
69 QVariantList wrong{"Foo", "Bar"};
71 ASSERT_FALSE(v.canConvert<QString>());
73 QVariantList argsList{23, wrong};
74 ASSERT_FALSE(invokeWithArgsList(callable, argsList));
75 // Values shouldn't have changed
76 EXPECT_EQ(42, intVal);
77 EXPECT_EQ("Hello World", stringVal);
81 TEST(FuncHelpersTest, invokeWithArgsListAndReturnValue)
87 auto callable = [&intVal, &stringVal](int i, const QString& s)
96 QVariantList argsList{42, "Hello World"};
97 auto ret = invokeWithArgsList(callable, argsList);
99 ASSERT_TRUE(ret->isValid());
100 EXPECT_EQ(-42, *ret);
101 EXPECT_EQ(42, intVal);
102 EXPECT_EQ("Hello World", stringVal);
107 QVariantList argsList{23};
108 ASSERT_FALSE(invokeWithArgsList(callable, argsList));