From f11e60384326f936aa57e55700e440e9e10f9466 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sun, 3 May 2015 12:18:15 +0200 Subject: [PATCH] Test for callable void function arguments. --- tests/Makefile.am | 2 ++ tests/callable/TestCallable.h | 12 ++++++++++ tests/callable/invokes_void_function.cpp | 29 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 tests/callable/invokes_void_function.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index ecc69f9..c08c2cc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,6 +3,7 @@ AUTOMAKE_OPTIONS = subdir-objects TESTS = \ descriptive_holds_data.test \ callable_invokes_provided_function.test \ + callable_invokes_void_function.test \ parameter_is_descriptive.test \ argument_handles_string_value.test \ argument_handles_int_value.test \ @@ -18,6 +19,7 @@ AM_CXXFLAGS = -O3 -I$(top_srcdir)/include -std=c++11 descriptive_holds_data_test_SOURCES = descriptive/holds_data.cpp callable_invokes_provided_function_test_SOURCES = callable/invokes_provided_function.cpp +callable_invokes_void_function_test_SOURCES = callable/invokes_void_function.cpp parameter_is_descriptive_test_SOURCES = parameter/is_descriptive.cpp diff --git a/tests/callable/TestCallable.h b/tests/callable/TestCallable.h index 097e115..7fea870 100644 --- a/tests/callable/TestCallable.h +++ b/tests/callable/TestCallable.h @@ -13,3 +13,15 @@ public: this->call(test); } }; + +template<> +class TestCallable : public Callable { +public: + TestCallable(void (*function)(void)) + : Callable(function) { + } + + void callFunction() { + this->call(); + } +}; diff --git a/tests/callable/invokes_void_function.cpp b/tests/callable/invokes_void_function.cpp new file mode 100644 index 0000000..f0e4671 --- /dev/null +++ b/tests/callable/invokes_void_function.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include "TestCallable.h" +#include "callable.h" + +using namespace std; +using namespace command; + +bool test = false; + +void function(void) { + test = true; +}; + +int main() { + TestCallable callable(function); + callable.callFunction(); + + if (test == true) { + cout << "Callable class calls provided function\n"; + return 0; + } + + cout << "Callable class does not call provided function\n"; + + return 1; +} + -- 2.30.2