Added Argument tests.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 2 May 2015 23:48:25 +0000 (01:48 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 2 May 2015 23:48:25 +0000 (01:48 +0200)
tests/Makefile.am
tests/argument/handles_float_value.cpp [new file with mode: 0644]
tests/argument/handles_int_value.cpp [new file with mode: 0644]
tests/argument/handles_negative_float_value.cpp [new file with mode: 0644]
tests/argument/handles_negative_int_value.cpp [new file with mode: 0644]
tests/argument/handles_string_value.cpp [new file with mode: 0644]

index b60d58a44f5824db81ffd3ba4d2523cd1cec2b8a..374f604fda964f3fc49ef808f0685bd47ecdc83b 100644 (file)
@@ -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 (file)
index 0000000..3fd86fb
--- /dev/null
@@ -0,0 +1,34 @@
+#include <iostream>
+
+#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<ArgumentType> 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 (file)
index 0000000..552a2e3
--- /dev/null
@@ -0,0 +1,34 @@
+#include <cstring>
+#include <iostream>
+
+#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<ArgumentType> 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 (file)
index 0000000..0279cac
--- /dev/null
@@ -0,0 +1,34 @@
+#include <iostream>
+
+#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<ArgumentType> 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 (file)
index 0000000..3f53f1a
--- /dev/null
@@ -0,0 +1,33 @@
+#include <iostream>
+
+#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<ArgumentType> 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 (file)
index 0000000..9dd6efa
--- /dev/null
@@ -0,0 +1,36 @@
+#include <cstring>
+#include <iostream>
+
+#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<ArgumentType> 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;
+}