From: Rafał Długołęcki Date: Wed, 6 May 2015 06:27:28 +0000 (+0200) Subject: Add Required tests. X-Git-Tag: v0.2~13 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=0c3fb217c99492ca15f3ff4a8a0402b801d7105f;p=command.git Add Required tests. --- 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; +}