#include "argument.h"
#include "command.h"
-void some_function(std::string) {
- std::cout << "Some function" << std::endl;
+void some_function(bool a) {
+ std::cout << "Some function " << a << std::endl;
}
int main(int argc, char *argv[]) {
command::Command command(argc, argv, {
- new command::Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
- new command::Argument<std::string>("File path", some_function),
- new command::Option<std::string>("h", "Help", some_function)
+// new command::Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
+ new command::Argument<bool>("File path", some_function)/*,
+ new command::Option<std::string>("h", "Help", some_function)*/
});
return 0;
argument_handles_int_value.test \
argument_handles_negative_int_value.test \
argument_handles_float_value.test \
- argument_handles_negative_float_value.test
+ argument_handles_negative_float_value.test \
+ argument_handles_boolean_value.test
noinst_PROGRAMS = $(TESTS)
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
+argument_handles_boolean_value_test_SOURCES = argument/handles_boolean_value.cpp
--- /dev/null
+#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;
+}
if (argument.understand(VALUE)) {
argument.handle();
}
+ else {
+ cout << "Argument class do not understand float values\n";
+ return 1;
+ }
if (test == std::stof(VALUE)) {
cout << "Argument class handles float values\n";
if (argument.understand(VALUE)) {
argument.handle();
}
+ else {
+ cout << "Argument class do not understand int values\n";
+ return 1;
+ }
if (test == std::stoi(VALUE)) {
cout << "Argument class handles int values\n";
if (argument.understand(VALUE)) {
argument.handle();
}
+ else {
+ cout << "Argument class do not understand negative float values\n";
+ return 1;
+ }
if (test == std::stof(VALUE)) {
cout << "Argument class handles negative float values\n";
cout << "Argument class do not handle negative float values\n";
-
return 1;
}
if (argument.understand(VALUE)) {
argument.handle();
}
+ else {
+ cout << "Argument class do not understand negative int values\n";
+ return 1;
+ }
if (test == std::stoi(VALUE)) {
cout << "Argument class handles negative int values\n";
if (argument.understand(VALUE)) {
argument.handle();
}
+ else {
+ cout << "Argument class do not understand string values\n";
+ return 1;
+ }
int cmp = strcmp(test.c_str(), VALUE);