diff options
author | Josh Blum | 2013-07-05 16:10:49 -0700 |
---|---|---|
committer | Josh Blum | 2013-07-05 16:10:49 -0700 |
commit | aa2c285ac86e5671fa418d336920c1c300cf9737 (patch) | |
tree | 33dfab03ddb43b4865ce59b89f421741460d6c24 /tests | |
parent | e23e5f43a97c72f1bf0dd240376bf89ff19f356c (diff) | |
download | sandhi-aa2c285ac86e5671fa418d336920c1c300cf9737.tar.gz sandhi-aa2c285ac86e5671fa418d336920c1c300cf9737.tar.bz2 sandhi-aa2c285ac86e5671fa418d336920c1c300cf9737.zip |
gras: serious template insanity
Diffstat (limited to 'tests')
-rw-r--r-- | tests/callable_test.cpp | 109 |
1 files changed, 86 insertions, 23 deletions
diff --git a/tests/callable_test.cpp b/tests/callable_test.cpp index 1753f79..684a820 100644 --- a/tests/callable_test.cpp +++ b/tests/callable_test.cpp @@ -10,44 +10,107 @@ struct MyClass : gras::Callable { MyClass(void) { - this->register_call("foo", &MyClass::foo); - this->register_call("bar", &MyClass::bar); - this->register_call("baz", &MyClass::baz); - //this->register_call("example_setter", &MyClass::example_setter); + count = 0; + this->register_call("test_args0_with_return", &MyClass::test_args0_with_return); + this->register_call("test_args1_with_return", &MyClass::test_args1_with_return); + this->register_call("test_args2_with_return", &MyClass::test_args2_with_return); + this->register_call("test_args3_with_return", &MyClass::test_args3_with_return); + this->register_call("test_args0_with_no_return", &MyClass::test_args0_with_no_return); + this->register_call("test_args1_with_no_return", &MyClass::test_args1_with_no_return); + this->register_call("test_args2_with_no_return", &MyClass::test_args2_with_no_return); + this->register_call("test_args3_with_no_return", &MyClass::test_args3_with_no_return); } - int foo(void) + int test_args0_with_return(void) { - return 42; + return count; } - int bar(const std::string &a0) + int test_args1_with_return(const int &a0) { - return a0.size(); + return a0; } - int baz(const std::string &a0, const bool &a1) + int test_args2_with_return(const int &a0, const std::string &a1) { - return a1?a0.size():-1; + return a0 + a1.size(); } - void example_setter(const long &) + int test_args3_with_return(const int &a0, const std::string &a1, const bool &a3) { - + return a3? a0 + a1.size() : 0; } -}; -BOOST_AUTO_TEST_CASE(test_property_newshit) -{ - MyClass my_class; - size_t my_foo = my_class.call<size_t>("foo"); - BOOST_CHECK_EQUAL(my_foo, size_t(42)); + void test_args0_with_no_return(void) + { + count++; + } + + void test_args1_with_no_return(const int &a0) + { + count = a0; + } + + void test_args2_with_no_return(const int &a0, const std::string &a1) + { + count = a0 + a1.size(); + } - size_t my_bar = my_class.call<size_t>("bar", "hello"); - BOOST_CHECK_EQUAL(my_bar, size_t(5)); + void test_args3_with_no_return(const int &a0, const std::string &a1, const bool &a2) + { + if (a2) count = a0 + a1.size(); + else count = 0; + } - signed my_baz = my_class.call<signed>("baz", "hello", false); - BOOST_CHECK_EQUAL(my_baz, signed(-1)); + int count; +}; - //my_class.call("example_setter", 123); +BOOST_AUTO_TEST_CASE(test_registered_methods) +{ + MyClass my_class; + { + size_t ret = my_class.call<size_t>("test_args0_with_return"); + BOOST_CHECK_EQUAL(ret, size_t(0)); + } + { + size_t ret = my_class.call<size_t>("test_args1_with_return", 42); + BOOST_CHECK_EQUAL(ret, size_t(42)); + } + { + size_t ret = my_class.call<size_t>("test_args2_with_return", 1, "OK"); + BOOST_CHECK_EQUAL(ret, size_t(3)); + } + { + size_t ret = my_class.call<size_t>("test_args3_with_return", 1, "OK", true); + BOOST_CHECK_EQUAL(ret, size_t(3)); + } + { + size_t ret = my_class.call<size_t>("test_args3_with_return", 1, "OK", false); + BOOST_CHECK_EQUAL(ret, size_t(0)); + } + { + my_class.call("test_args0_with_no_return"); //this adds 1 to count + size_t ret = my_class.call<size_t>("test_args0_with_return"); + BOOST_CHECK_EQUAL(ret, size_t(1)); + } + { + my_class.call("test_args1_with_no_return", 42); + size_t ret = my_class.call<size_t>("test_args0_with_return"); + BOOST_CHECK_EQUAL(ret, size_t(42)); + } + { + my_class.call("test_args2_with_no_return", 1, "OK"); + size_t ret = my_class.call<size_t>("test_args0_with_return"); + BOOST_CHECK_EQUAL(ret, size_t(3)); + } + { + my_class.call("test_args3_with_no_return", 1, "OK", true); + size_t ret = my_class.call<size_t>("test_args0_with_return"); + BOOST_CHECK_EQUAL(ret, size_t(3)); + } + { + my_class.call("test_args3_with_no_return", 1, "OK", false); + size_t ret = my_class.call<size_t>("test_args0_with_return"); + BOOST_CHECK_EQUAL(ret, size_t(0)); + } } |