From dcf154aaf037ac67260abcec0b0ed3db32bc65ac Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 13 Jan 2015 02:01:30 +0100 Subject: allowing validated methods --- test/core/common/ArgumentTest.cpp | 23 +++++++++++++++-------- test/core/common/FunctionTest.cpp | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'test') 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 helloWorldFun{new Method{[]( - const Variant::arrayType &arr, void *) { return Variant{"Hello World"}; }}}; +static std::shared_ptr helloWorldFun{new Method{ + [](Variant::arrayType &arr, void *) { return Variant{"Hello World"}; }}}; static std::shared_ptr goodbyeWorldFun{ - new Method{[](const Variant::arrayType &arr, + new Method{[](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 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 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); +} } -- cgit v1.2.3