From 0c3fb217c99492ca15f3ff4a8a0402b801d7105f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Wed, 6 May 2015 08:27:28 +0200 Subject: [PATCH] Add Required tests. --- tests/Makefile.am | 5 +++- tests/required/should_be_required.cpp | 37 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/required/should_be_required.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index 11c3c18..6a0fa06 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,7 +19,8 @@ TESTS = \ option_handles_boolean_value.test \ option_handles_void_value.test \ option_should_match_exact_name.test \ - option_should_throw_exception_on_missing_value.test + option_should_throw_exception_on_missing_value.test \ + required_should_be_required.test noinst_PROGRAMS = $(TESTS) @@ -48,3 +49,5 @@ option_handles_boolean_value_test_SOURCES = option/handles_boolean_value.cpp option_handles_void_value_test_SOURCES = option/handles_void_value.cpp option_should_match_exact_name_test_SOURCES = option/should_match_exact_name.cpp option_should_throw_exception_on_missing_value_test_SOURCES = option/should_throw_exception_on_missing_value.cpp + +required_should_be_required_test_SOURCES = required/should_be_required.cpp diff --git a/tests/required/should_be_required.cpp b/tests/required/should_be_required.cpp new file mode 100644 index 0000000..b59db3d --- /dev/null +++ b/tests/required/should_be_required.cpp @@ -0,0 +1,37 @@ +#include + +#include "required.h" +#include "argument.h" +#include "option.h" + +using namespace std; +using namespace command; + +#define NAME "test" +#define VALUE "1" + +#define OPTION NAME "=" VALUE + +typedef int Type; + +void function(Type val) { } + +int main() { + Parameter * requiredOption = new Required(new Option(NAME, "Required Option", function)); + Parameter * requiredArgument = new Required(new Argument("Required Argument", function)); + + if (!requiredOption->isRequired()) { + cout << requiredOption->describe() << " should be treated as required but it is not\n"; + delete requiredOption; + return 1; + } + if (!requiredArgument->isRequired()) { + cout << requiredArgument->describe() << " should be treated as required but it is not\n"; + delete requiredOption; + return 1; + } + + cout << "Required decorator correctly returns its property\n"; + + return 0; +} -- 2.30.2