Added Option tests.
[command.git] / tests / option / handles_float_value.cpp
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;
+}