Added Option tests.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 3 May 2015 10:57:48 +0000 (12:57 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 3 May 2015 10:57:48 +0000 (12:57 +0200)
tests/Makefile.am
tests/argument/handles_float_value.cpp
tests/option/handles_float_value.cpp [new file with mode: 0644]
tests/option/handles_string_value.cpp

index e17ac34ccda60bba70049e939a92e9e2cf46d637..224aa6aabb2684d1cd26b0c293ec45fc8ec182c0 100644 (file)
@@ -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
index 93ff14f11484cad3b7108a99c110496a7a043249..9e53dc8d5b276f2d1cd9c11836ecab632f5a1492 100644 (file)
@@ -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 (file)
index 0000000..e1599f6
--- /dev/null
@@ -0,0 +1,41 @@
+#include <cstring>
+#include <iostream>
+
+#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<OptionType> 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;
+}
index 574b5c5adfe7ed5d8a4a6d44cab6c508ee9b8aa2..4b276ec6844235fb7bb742ff85f565a19f56eb46 100644 (file)
@@ -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;
     }