From 1298bcd1e421ccfefafa78c6d33760818902f399 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 4 Jul 2013 19:46:58 -0700 Subject: gras: function registry is more flexible --- tests/block_props_test.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests/block_props_test.cpp') diff --git a/tests/block_props_test.cpp b/tests/block_props_test.cpp index f53a1c3..ad1c5e2 100644 --- a/tests/block_props_test.cpp +++ b/tests/block_props_test.cpp @@ -68,3 +68,53 @@ BOOST_AUTO_TEST_CASE(test_property_errors) //wrong type for property BOOST_CHECK_THROW(my_block.set("foo", "a string"), std::exception); } + +struct MyBlockNewShit : gras::Block +{ + MyBlockNewShit(void): + gras::Block("MyBlockNewShit") + { + this->register_call("foo", &MyBlockNewShit::foo); + this->register_call("bar", &MyBlockNewShit::bar); + this->register_call("baz", &MyBlockNewShit::baz); + //this->register_call("example_setter", &MyBlockNewShit::example_setter); + } + + //dummy work + void work(const InputItems &, const OutputItems &){} + + int foo(void) + { + return 42; + } + + int bar(const std::string &a0) + { + return a0.size(); + } + + int baz(const std::string &a0, const bool &a1) + { + return a1?a0.size():-1; + } + + void example_setter(const long &) + { + + } +}; + +BOOST_AUTO_TEST_CASE(test_property_newshit) +{ + MyBlockNewShit my_block; + size_t my_foo = my_block.call("foo"); + BOOST_CHECK_EQUAL(my_foo, size_t(42)); + + size_t my_bar = my_block.call("bar", "hello"); + BOOST_CHECK_EQUAL(my_bar, size_t(5)); + + signed my_baz = my_block.call("baz", "hello", false); + BOOST_CHECK_EQUAL(my_baz, signed(-1)); + + //my_block.call("example_setter", 123); +} -- cgit