From d51669e81ee37c88191b828c5b5d2f9a41731aa7 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:57:48 +0200 Subject: [PATCH] Added Option tests. --- tests/Makefile.am | 4 ++- tests/argument/handles_float_value.cpp | 4 +-- tests/option/handles_float_value.cpp | 41 ++++++++++++++++++++++++++ tests/option/handles_string_value.cpp | 4 +-- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 tests/option/handles_float_value.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index e17ac34..224aa6a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,7 +12,8 @@ TESTS = \ argument_handles_negative_float_value.test \ argument_handles_boolean_value.test \ option_handles_string_value.test \ - option_handles_boolean_value.test + option_handles_boolean_value.test \ + option_handles_float_value.test noinst_PROGRAMS = $(TESTS) @@ -34,3 +35,4 @@ argument_handles_boolean_value_test_SOURCES = argument/handles_boolean_value.cp option_handles_string_value_test_SOURCES = option/handles_string_value.cpp option_handles_boolean_value_test_SOURCES = option/handles_boolean_value.cpp +option_handles_float_value_test_SOURCES = option/handles_float_value.cpp diff --git a/tests/argument/handles_float_value.cpp b/tests/argument/handles_float_value.cpp index 93ff14f..9e53dc8 100644 --- a/tests/argument/handles_float_value.cpp +++ b/tests/argument/handles_float_value.cpp @@ -22,12 +22,12 @@ int main() { argument.handle(); } else { - cout << "Argument class do not understand float values\n"; + cout << argument.describe() << " do not understand float values\n"; return 1; } if (test == std::stof(VALUE)) { - cout << "Argument class handles float values\n"; + cout << argument.describe() << " handles float values\n"; return 0; } diff --git a/tests/option/handles_float_value.cpp b/tests/option/handles_float_value.cpp new file mode 100644 index 0000000..e1599f6 --- /dev/null +++ b/tests/option/handles_float_value.cpp @@ -0,0 +1,41 @@ +#include +#include + +#include "option.h" + +using namespace std; +using namespace command; + +#define NAME "test" +#define VALUE "567890.1234" + +#define OPTION NAME"="VALUE + +typedef float OptionType; + +OptionType test; + +void function(OptionType value) { + test = value; +} + +int main() { + Option option(NAME, "Option with float value", function); + + if (option.understand(OPTION)) { + option.handle(); + } + else { + cout << option.describe() << " do not understand " << VALUE << " value\n"; + return 1; + } + + if (test == std::stof(VALUE)) { + cout << option.describe() << " handles " << VALUE << " value\n"; + return 0; + } + + cout << "Option class do not handle float values\n"; + + return 1; +} diff --git a/tests/option/handles_string_value.cpp b/tests/option/handles_string_value.cpp index 574b5c5..4b276ec 100644 --- a/tests/option/handles_string_value.cpp +++ b/tests/option/handles_string_value.cpp @@ -26,14 +26,14 @@ int main() { option.handle(); } else { - cout << "Option class do not understand string values\n"; + cout << option.describe() << " do not understand string values\n"; return 1; } int cmp = strcmp(test.c_str(), VALUE); if (cmp == 0) { - cout << "Option class handles string values\n"; + cout << option.describe() << " handles string values\n"; return 0; } -- 2.30.2