summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-13 02:01:30 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-13 02:01:30 +0100
commitdcf154aaf037ac67260abcec0b0ed3db32bc65ac (patch)
tree94dd32865be508d70617c351c609f398c9ec6f06 /test
parent742b76b006daf27ea19b2834e56696cb3c5a0e18 (diff)
allowing validated methods
Diffstat (limited to 'test')
-rw-r--r--test/core/common/ArgumentTest.cpp23
-rw-r--r--test/core/common/FunctionTest.cpp17
2 files changed, 30 insertions, 10 deletions
diff --git a/test/core/common/ArgumentTest.cpp b/test/core/common/ArgumentTest.cpp
index d58f71b..0dec809 100644
--- a/test/core/common/ArgumentTest.cpp
+++ b/test/core/common/ArgumentTest.cpp
@@ -471,11 +471,11 @@ TEST(Argument, validateObjectDefault)
}
}
-static std::shared_ptr<Function> helloWorldFun{new Method<void>{[](
- const Variant::arrayType &arr, void *) { return Variant{"Hello World"}; }}};
+static std::shared_ptr<Function> helloWorldFun{new Method<void>{
+ [](Variant::arrayType &arr, void *) { return Variant{"Hello World"}; }}};
static std::shared_ptr<Function> goodbyeWorldFun{
- new Method<void>{[](const Variant::arrayType &arr,
+ new Method<void>{[](Variant::arrayType &arr,
void *) { return Variant{"Goodbye Cruel World"}; }}};
TEST(Argument, validateFunction)
@@ -835,31 +835,38 @@ TEST(Arguments, validateMap)
{
Variant::mapType map{{"a", 2}, {"c", false}};
ASSERT_TRUE(args.validateMap(map, logger, false));
- ASSERT_EQ(Variant::mapType({{"a", 2}, {"b", "test"}, {"c", false}}), map);
+ ASSERT_EQ(Variant::mapType({{"a", 2}, {"b", "test"}, {"c", false}}),
+ map);
}
{
Variant::mapType map{{"a", 2}};
ASSERT_TRUE(args.validateMap(map, logger, false));
- ASSERT_EQ(Variant::mapType({{"a", 2}, {"b", "test"}, {"c", true}}), map);
+ ASSERT_EQ(Variant::mapType({{"a", 2}, {"b", "test"}, {"c", true}}),
+ map);
}
{
Variant::mapType map{};
ASSERT_FALSE(args.validateMap(map, logger, false));
- ASSERT_EQ(Variant::mapType({{"a", 0}, {"b", "test"}, {"c", true}}), map);
+ ASSERT_EQ(Variant::mapType({{"a", 0}, {"b", "test"}, {"c", true}}),
+ map);
}
{
Variant::mapType map{{"a", 2}, {"d", nullptr}};
ASSERT_FALSE(args.validateMap(map, logger, false));
- ASSERT_EQ(Variant::mapType({{"a", 2}, {"b", "test"}, {"c", true}, {"d", nullptr}}), map);
+ ASSERT_EQ(Variant::mapType(
+ {{"a", 2}, {"b", "test"}, {"c", true}, {"d", nullptr}}),
+ map);
}
{
Variant::mapType map{{"a", 2}, {"d", nullptr}};
ASSERT_TRUE(args.validateMap(map, logger, true));
- ASSERT_EQ(Variant::mapType({{"a", 2}, {"b", "test"}, {"c", true}, {"d", nullptr}}), map);
+ ASSERT_EQ(Variant::mapType(
+ {{"a", 2}, {"b", "test"}, {"c", true}, {"d", nullptr}}),
+ map);
}
}
}
diff --git a/test/core/common/FunctionTest.cpp b/test/core/common/FunctionTest.cpp
index 7225f9c..ed20695 100644
--- a/test/core/common/FunctionTest.cpp
+++ b/test/core/common/FunctionTest.cpp
@@ -29,10 +29,10 @@ public:
void visit() { visited = true; }
};
-TEST(Method, simpleTest)
+TEST(Method, simple)
{
Method<MethodTestClass> m{
- [](const Variant::arrayType &args, MethodTestClass *thisRef) {
+ [](Variant::arrayType &args, MethodTestClass *thisRef) {
thisRef->visit();
return Variant{};
}};
@@ -40,5 +40,18 @@ TEST(Method, simpleTest)
MethodTestClass inst;
m.call({}, &inst);
}
+
+TEST(Method, validation)
+{
+ Method<void> m{{Argument::Int("a"), Argument::Int("b")},
+ [](Variant::arrayType &args, void *thisRef) {
+ return Variant{args[0].asInt() + args[1].asInt()};
+ }};
+
+ MethodTestClass inst;
+ ASSERT_EQ(3, m.call({1, 2}, &inst).asInt());
+ ASSERT_THROW(m.call({1}, &inst), LoggableException);
+ ASSERT_THROW(m.call({1, "bla"}, &inst), LoggableException);
+}
}