Added Argument boolean tests.
[command.git] / tests / 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 (file)
index 0000000..b41106f
--- /dev/null
@@ -0,0 +1,51 @@
+#include <iostream>
+
+#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<ArgumentType> 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<ArgumentType> 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;
+}