From: Rafał Długołęcki Date: Tue, 5 May 2015 21:55:18 +0000 (+0200) Subject: Add Option tests. X-Git-Tag: v0.2~18 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=ffa13e9b3700e8e3065b5945dab3dc3924c32b00;p=command.git Add Option tests. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 0a9a631..f126d88 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,8 +12,12 @@ TESTS = \ argument_handles_negative_float_value.test \ argument_handles_boolean_value.test \ option_handles_string_value.test \ + option_handles_int_value.test \ + option_handles_negative_int_value.test \ + option_handles_float_value.test \ + option_handles_negative_float_value.test \ option_handles_boolean_value.test \ - option_handles_float_value.test + option_handles_void_value.test noinst_PROGRAMS = $(TESTS) @@ -34,5 +38,9 @@ argument_handles_negative_float_value_test_SOURCES = argument/handles_negative_ argument_handles_boolean_value_test_SOURCES = argument/handles_boolean_value.cpp option_handles_string_value_test_SOURCES = option/handles_string_value.cpp -option_handles_boolean_value_test_SOURCES = option/handles_boolean_value.cpp +option_handles_int_value_test_SOURCES = option/handles_int_value.cpp +option_handles_negative_int_value_test_SOURCES = option/handles_negative_int_value.cpp option_handles_float_value_test_SOURCES = option/handles_float_value.cpp +option_handles_negative_float_value_test_SOURCES = option/handles_negative_float_value.cpp +option_handles_boolean_value_test_SOURCES = option/handles_boolean_value.cpp +option_handles_void_value_test_SOURCES = option/handles_void_value.cpp diff --git a/tests/argument/handles_negative_float_value.cpp b/tests/argument/handles_negative_float_value.cpp index 0111502..7c97467 100644 --- a/tests/argument/handles_negative_float_value.cpp +++ b/tests/argument/handles_negative_float_value.cpp @@ -16,22 +16,22 @@ void function(ArgumentType value) { } int main() { - Argument argument("Argument as float", function); + Argument argument("Argument as negative float", function); if (argument.understand(VALUE)) { argument.handle(); } else { - cout << "Argument class do not understand negative float values\n"; + cout << argument.describe() << " do not understand " << VALUE " value\n"; return 1; } if (test == std::stof(VALUE)) { - cout << "Argument class handles negative float values\n"; + cout << argument.describe() << " handles negative float values\n"; return 0; } - cout << "Argument class do not handle negative float values\n"; + cout << argument.describe() << " do not handle negative float values\n"; return 1; } diff --git a/tests/option/handles_int_value.cpp b/tests/option/handles_int_value.cpp new file mode 100644 index 0000000..a6d9c46 --- /dev/null +++ b/tests/option/handles_int_value.cpp @@ -0,0 +1,41 @@ +#include +#include + +#include "option.h" + +using namespace std; +using namespace command; + +#define NAME "test" +#define VALUE "1234567890" + +#define OPTION NAME "=" VALUE + +typedef int OptionType; + +OptionType test; + +void function(OptionType value) { + test = value; +} + +int main() { + Option option(NAME, "Option as int", function); + + if (option.understand(OPTION)) { + option.handle(); + } + else { + cout << option.describe() << " do not understand int values\n"; + return 1; + } + + if (test == std::stoi(VALUE)) { + cout << option.describe() << " handles int values\n"; + return 0; + } + + cout << option.describe() << " do not handle int values\n"; + + return 1; +} diff --git a/tests/option/handles_negative_float_value.cpp b/tests/option/handles_negative_float_value.cpp new file mode 100644 index 0000000..02bc7e0 --- /dev/null +++ b/tests/option/handles_negative_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 negative 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 negative float values\n"; + + return 1; +} diff --git a/tests/option/handles_negative_int_value.cpp b/tests/option/handles_negative_int_value.cpp new file mode 100644 index 0000000..816e8da --- /dev/null +++ b/tests/option/handles_negative_int_value.cpp @@ -0,0 +1,41 @@ +#include +#include + +#include "option.h" + +using namespace std; +using namespace command; + +#define NAME "test" +#define VALUE "-1234567890" + +#define OPTION NAME "=" VALUE + +typedef int OptionType; + +OptionType test; + +void function(OptionType value) { + test = value; +} + +int main() { + Option option(NAME, "Option as negative int", function); + + if (option.understand(OPTION)) { + option.handle(); + } + else { + cout << option.describe() << " do not understand " << VALUE << " value\n"; + return 1; + } + + if (test == std::stoi(VALUE)) { + cout << option.describe() << " handles negative int values\n"; + return 0; + } + + cout << option.describe() << " do not handle negative int values\n"; + + return 1; +} diff --git a/tests/option/handles_void_value.cpp b/tests/option/handles_void_value.cpp new file mode 100644 index 0000000..b6528e3 --- /dev/null +++ b/tests/option/handles_void_value.cpp @@ -0,0 +1,37 @@ +#include + +#include "option.h" + +using namespace std; +using namespace command; + +#define NAME "test" + +typedef void OptionType; + +bool test = false; + +void function() { + test = true; +} + +int main() { + Option option(NAME, "Option with void value", function); + + if (option.understand(NAME)) { + option.handle(); + } + else { + cout << option.describe() << " do not understand void values\n"; + return 1; + } + + if (test) { + cout << option.describe() << " handles void values\n"; + return 0; + } + + cout << option.describe() << " do not handle void values\n" << endl; + + return 1; +}