summaryrefslogtreecommitdiff
path: root/test/core/script/Function.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-10-24 22:22:26 +0000
committerandreas <andreas@daaaf23c-2e50-4459-9457-1e69db5a47bf>2014-10-24 22:22:26 +0000
commit7e51bf3804e50ea063fcc97b2682a32a8505902f (patch)
tree6a6097216708049b5dd7a4c43020c85aafb046a1 /test/core/script/Function.cpp
parent4a9912f516bf096c6f8c6259b3fc6ba4b95b8d69 (diff)
added Function, Property and Object classes; added CMakeLists entries for the mozjs-24 library (the Firefox JavaScript engine which is available as Package on Fedora); added Doxygen target to makefile
git-svn-id: file:///var/local/svn/basicwriter@75 daaaf23c-2e50-4459-9457-1e69db5a47bf
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());
+}
+
}
}