From: Rafał Długołęcki Date: Sun, 3 May 2015 00:10:59 +0000 (+0200) Subject: Added Argument boolean tests. X-Git-Tag: v0.2~27 X-Git-Url: https://git.dlugolecki.net.pl/?p=command.git;a=commitdiff_plain;h=4d3ba3307820eed7fab532abd2d35e24359b5a51 Added Argument boolean tests. --- diff --git a/src/main.cpp b/src/main.cpp index 6365c7f..813491a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,15 +5,15 @@ #include "argument.h" #include "command.h" -void some_function(std::string) { - std::cout << "Some function" << std::endl; +void some_function(bool a) { + std::cout << "Some function " << a << std::endl; } int main(int argc, char *argv[]) { command::Command command(argc, argv, { - new command::Argument("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }), - new command::Argument("File path", some_function), - new command::Option("h", "Help", some_function) +// new command::Argument("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }), + new command::Argument("File path", some_function)/*, + new command::Option("h", "Help", some_function)*/ }); return 0; diff --git a/tests/Makefile.am b/tests/Makefile.am index 374f604..ecc69f9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,7 +8,8 @@ TESTS = \ argument_handles_int_value.test \ argument_handles_negative_int_value.test \ argument_handles_float_value.test \ - argument_handles_negative_float_value.test + argument_handles_negative_float_value.test \ + argument_handles_boolean_value.test noinst_PROGRAMS = $(TESTS) @@ -25,3 +26,4 @@ argument_handles_int_value_test_SOURCES = argument/handles_int_value.cpp argument_handles_negative_int_value_test_SOURCES = argument/handles_negative_int_value.cpp argument_handles_float_value_test_SOURCES = argument/handles_float_value.cpp argument_handles_negative_float_value_test_SOURCES = argument/handles_negative_float_value.cpp +argument_handles_boolean_value_test_SOURCES = argument/handles_boolean_value.cpp diff --git a/tests/argument/handles_boolean_value.cpp b/tests/argument/handles_boolean_value.cpp new file mode 100644 index 0000000..b41106f --- /dev/null +++ b/tests/argument/handles_boolean_value.cpp @@ -0,0 +1,51 @@ +#include + +#include "argument.h" + +using namespace std; +using namespace command; + +#define FALSE "0" +#define TRUE "1" + +typedef bool ArgumentType; + +ArgumentType test; + +void function(ArgumentType value) { + test = value; +} + +int main() { + Argument argument("Argument as boolean", function); + + if (argument.understand(FALSE)) { + argument.handle(); + } + else { + cout << "Argument class do not understand boolean (FALSE) values\n"; + return 1; + } + + if (test == (bool)std::stoi(FALSE)) { + cout << "Argument class handles boolean (FALSE) values\n"; + } + + Argument argument2("Argument as boolean", function); + if (argument2.understand(TRUE)) { + argument2.handle(); + } + else { + cout << "Argument class do not understand boolean (TRUE) values\n"; + return 1; + } + + if (test == (bool)std::stoi(TRUE)) { + cout << "Argument class handles boolean (TRUE) values\n"; + return 0; + } + + cout << "Argument class do not handle boolean values\n"; + + return 1; +} diff --git a/tests/argument/handles_float_value.cpp b/tests/argument/handles_float_value.cpp index 3fd86fb..93ff14f 100644 --- a/tests/argument/handles_float_value.cpp +++ b/tests/argument/handles_float_value.cpp @@ -21,6 +21,10 @@ int main() { if (argument.understand(VALUE)) { argument.handle(); } + else { + cout << "Argument class do not understand float values\n"; + return 1; + } if (test == std::stof(VALUE)) { cout << "Argument class handles float values\n"; diff --git a/tests/argument/handles_int_value.cpp b/tests/argument/handles_int_value.cpp index 552a2e3..ffe130c 100644 --- a/tests/argument/handles_int_value.cpp +++ b/tests/argument/handles_int_value.cpp @@ -22,6 +22,10 @@ int main() { if (argument.understand(VALUE)) { argument.handle(); } + else { + cout << "Argument class do not understand int values\n"; + return 1; + } if (test == std::stoi(VALUE)) { cout << "Argument class handles int values\n"; diff --git a/tests/argument/handles_negative_float_value.cpp b/tests/argument/handles_negative_float_value.cpp index 0279cac..0111502 100644 --- a/tests/argument/handles_negative_float_value.cpp +++ b/tests/argument/handles_negative_float_value.cpp @@ -21,6 +21,10 @@ int main() { if (argument.understand(VALUE)) { argument.handle(); } + else { + cout << "Argument class do not understand negative float values\n"; + return 1; + } if (test == std::stof(VALUE)) { cout << "Argument class handles negative float values\n"; @@ -29,6 +33,5 @@ int main() { cout << "Argument class do not handle negative float values\n"; - return 1; } diff --git a/tests/argument/handles_negative_int_value.cpp b/tests/argument/handles_negative_int_value.cpp index 3f53f1a..f9c222f 100644 --- a/tests/argument/handles_negative_int_value.cpp +++ b/tests/argument/handles_negative_int_value.cpp @@ -21,6 +21,10 @@ int main() { if (argument.understand(VALUE)) { argument.handle(); } + else { + cout << "Argument class do not understand negative int values\n"; + return 1; + } if (test == std::stoi(VALUE)) { cout << "Argument class handles negative int values\n"; diff --git a/tests/argument/handles_string_value.cpp b/tests/argument/handles_string_value.cpp index 9dd6efa..38e6efa 100644 --- a/tests/argument/handles_string_value.cpp +++ b/tests/argument/handles_string_value.cpp @@ -22,6 +22,10 @@ int main() { if (argument.understand(VALUE)) { argument.handle(); } + else { + cout << "Argument class do not understand string values\n"; + return 1; + } int cmp = strcmp(test.c_str(), VALUE);