From e440905b4cbc8761e62ab645e686ceeada0bb5e6 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 01:48:25 +0200 Subject: [PATCH] Added Argument tests. --- tests/Makefile.am | 13 ++++++- tests/argument/handles_float_value.cpp | 34 ++++++++++++++++++ tests/argument/handles_int_value.cpp | 34 ++++++++++++++++++ .../argument/handles_negative_float_value.cpp | 34 ++++++++++++++++++ tests/argument/handles_negative_int_value.cpp | 33 +++++++++++++++++ tests/argument/handles_string_value.cpp | 36 +++++++++++++++++++ 6 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 tests/argument/handles_float_value.cpp create mode 100644 tests/argument/handles_int_value.cpp create mode 100644 tests/argument/handles_negative_float_value.cpp create mode 100644 tests/argument/handles_negative_int_value.cpp create mode 100644 tests/argument/handles_string_value.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index b60d58a..374f604 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -4,13 +4,24 @@ TESTS = \ descriptive_holds_data.test \ callable_invokes_provided_function.test \ parameter_is_descriptive.test \ - argument_handles_string_value.test + argument_handles_string_value.test \ + argument_handles_int_value.test \ + argument_handles_negative_int_value.test \ + argument_handles_float_value.test \ + argument_handles_negative_float_value.test noinst_PROGRAMS = $(TESTS) AM_CXXFLAGS = -O3 -I$(top_srcdir)/include -std=c++11 descriptive_holds_data_test_SOURCES = descriptive/holds_data.cpp + callable_invokes_provided_function_test_SOURCES = callable/invokes_provided_function.cpp + parameter_is_descriptive_test_SOURCES = parameter/is_descriptive.cpp + argument_handles_string_value_test_SOURCES = argument/handles_string_value.cpp +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 diff --git a/tests/argument/handles_float_value.cpp b/tests/argument/handles_float_value.cpp new file mode 100644 index 0000000..3fd86fb --- /dev/null +++ b/tests/argument/handles_float_value.cpp @@ -0,0 +1,34 @@ +#include + +#include "argument.h" + +using namespace std; +using namespace command; + +#define VALUE "567890.1234" + +typedef float ArgumentType; + +ArgumentType test; + +void function(ArgumentType value) { + test = value; +} + +int main() { + Argument argument("Argument as float", function); + + if (argument.understand(VALUE)) { + argument.handle(); + } + + if (test == std::stof(VALUE)) { + cout << "Argument class handles float values\n"; + return 0; + } + + cout << "Argument class do not handle float values\n"; + + + return 1; +} diff --git a/tests/argument/handles_int_value.cpp b/tests/argument/handles_int_value.cpp new file mode 100644 index 0000000..552a2e3 --- /dev/null +++ b/tests/argument/handles_int_value.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include "argument.h" + +using namespace std; +using namespace command; + +#define VALUE "1234567890" + +typedef int ArgumentType; + +ArgumentType test; + +void function(ArgumentType value) { + test = value; +} + +int main() { + Argument argument("Argument as int", function); + + if (argument.understand(VALUE)) { + argument.handle(); + } + + if (test == std::stoi(VALUE)) { + cout << "Argument class handles int values\n"; + return 0; + } + + cout << "Argument class do not handle int values\n"; + + return 1; +} diff --git a/tests/argument/handles_negative_float_value.cpp b/tests/argument/handles_negative_float_value.cpp new file mode 100644 index 0000000..0279cac --- /dev/null +++ b/tests/argument/handles_negative_float_value.cpp @@ -0,0 +1,34 @@ +#include + +#include "argument.h" + +using namespace std; +using namespace command; + +#define VALUE "-567890.1234" + +typedef float ArgumentType; + +ArgumentType test; + +void function(ArgumentType value) { + test = value; +} + +int main() { + Argument argument("Argument as float", function); + + if (argument.understand(VALUE)) { + argument.handle(); + } + + if (test == std::stof(VALUE)) { + cout << "Argument class handles negative float values\n"; + return 0; + } + + 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 new file mode 100644 index 0000000..3f53f1a --- /dev/null +++ b/tests/argument/handles_negative_int_value.cpp @@ -0,0 +1,33 @@ +#include + +#include "argument.h" + +using namespace std; +using namespace command; + +#define VALUE "-1234567890" + +typedef int ArgumentType; + +ArgumentType test; + +void function(ArgumentType value) { + test = value; +} + +int main() { + Argument argument("Argument as negative int", function); + + if (argument.understand(VALUE)) { + argument.handle(); + } + + if (test == std::stoi(VALUE)) { + cout << "Argument class handles negative int values\n"; + return 0; + } + + cout << "Argument class do not handle negative int values\n"; + + return 1; +} diff --git a/tests/argument/handles_string_value.cpp b/tests/argument/handles_string_value.cpp new file mode 100644 index 0000000..9dd6efa --- /dev/null +++ b/tests/argument/handles_string_value.cpp @@ -0,0 +1,36 @@ +#include +#include + +#include "argument.h" + +using namespace std; +using namespace command; + +#define VALUE "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + +typedef std::string ArgumentType; + +ArgumentType test; + +void function(ArgumentType value) { + test = value; +} + +int main() { + Argument argument("Argument as string", function); + + if (argument.understand(VALUE)) { + argument.handle(); + } + + int cmp = strcmp(test.c_str(), VALUE); + + if (cmp == 0) { + cout << "Argument class handles string values\n"; + return 0; + } + + cout << "Argument class do not handle string values\n"; + + return 1; +} -- 2.30.2