summaryrefslogtreecommitdiff
path: root/test/core/script/Function.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/script/Function.cpp')
-rw-r--r--test/core/script/Function.cpp47
1 files changed, 27 insertions, 20 deletions
diff --git a/test/core/script/Function.cpp b/test/core/script/Function.cpp
index bd2c9d6..cd6bd84 100644
--- a/test/core/script/Function.cpp
+++ b/test/core/script/Function.cpp
@@ -25,38 +25,45 @@ namespace script {
TEST(HostFunction, callDirect)
{
- // Local variable
int v = 0;
-
- // Host function which sets the local variable
- auto f = createHostFunction(
- [&v](const std::vector<Variant> &args, void *data) {
- v = args[0].getIntegerValue();
- return VarNull;
- }, {ArgumentDescriptor{VariantType::integer}});
-
- // Call the host function
+ HostFunction f{[](const std::vector<Variant> &args, void *data) {
+ *(static_cast<int*>(data)) = args[0].getIntegerValue();
+ return VarNull;
+ }, {Argument{VariantType::integer}}, &v};
ASSERT_EQ(VariantType::null, f.call({{(int64_t)42}}).getType());
ASSERT_EQ(42, v);
}
TEST(HostFunction, callDefaults)
{
- // Local variable
int v = 0;
-
- // Host function which sets the local variable
- auto f = createHostFunction(
- [&v](const std::vector<Variant> &args, void *data) {
- v = args[0].getIntegerValue();
- return Variant{"Hallo Welt"};
- }, {ArgumentDescriptor{VariantType::integer, {(int64_t)42}}});
-
- // Call the host function
+ HostFunction f{[](const std::vector<Variant> &args, void *data) {
+ *(static_cast<int*>(data)) = args[0].getIntegerValue();
+ return Variant{"Hallo Welt"};
+ }, {Argument{VariantType::integer, {(int64_t)42}}}, &v};
ASSERT_EQ("Hallo Welt", f.call().getStringValue());
ASSERT_EQ(42, v);
}
+TEST(Setter, call)
+{
+ int v = 0;
+ Setter f{VariantType::integer, [](Variant arg, void *data) {
+ *(static_cast<int*>(data)) = arg.getIntegerValue();
+ }, &v};
+ f.call({(int64_t)42});
+ ASSERT_EQ(42, v);
+}
+
+TEST(Getter, call)
+{
+ int v = 42;
+ Getter f{[](void *data) {
+ return Variant{int64_t(*(static_cast<int*>(data)))};
+ }, &v};
+ ASSERT_EQ(v, f.call().getIntegerValue());
+}
+
}
}