argument_handles_negative_int_value.test \
argument_handles_float_value.test \
argument_handles_negative_float_value.test \
- argument_handles_boolean_value.test
+ argument_handles_boolean_value.test \
+ option_handles_string_value.test \
+ option_handles_boolean_value.test
noinst_PROGRAMS = $(TESTS)
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
+
+option_handles_string_value_test_SOURCES = option/handles_string_value.cpp
+option_handles_boolean_value_test_SOURCES = option/handles_boolean_value.cpp
--- /dev/null
+#include <iostream>
+
+#include "option.h"
+
+using namespace std;
+using namespace command;
+
+#define NAME "test"
+#define FALSE "0"
+#define TRUE "1"
+
+#define OPTION1 NAME "=" FALSE
+#define OPTION2 NAME "=" TRUE
+
+typedef bool OptionType;
+
+OptionType test;
+
+void function(OptionType value) {
+ test = value;
+}
+
+int main() {
+ Option<OptionType> option(NAME, "Option with boolean value", function);
+
+ if (option.understand(OPTION1)) {
+ option.handle();
+ }
+ else {
+ cout << option.describe() << " do not understand " << FALSE << " values\n";
+ return 1;
+ }
+
+ if (test == (bool)std::stoi(FALSE)) {
+ cout << option.describe() << " handles " << FALSE << " values\n";
+ }
+
+ Option<OptionType> option2(NAME, "Option with boolean value", function);
+
+ if (option2.understand(OPTION2)) {
+ option2.handle();
+ }
+ else {
+ cout << option.describe() << " do not understand " << TRUE << " values\n";
+ return 1;
+ }
+
+ if (test == (bool)std::stoi(TRUE)) {
+ cout << option.describe() << " handles " << TRUE << " values\n";
+ return 0;
+ }
+
+ cout << "Option class do not handle boolean values\n" << test;
+
+ return 1;
+}
--- /dev/null
+#include <cstring>
+#include <iostream>
+
+#include "option.h"
+
+using namespace std;
+using namespace command;
+
+#define NAME "test"
+#define VALUE "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+
+#define OPTION NAME"="VALUE
+
+typedef std::string OptionType;
+
+OptionType test;
+
+void function(OptionType value) {
+ test = value;
+}
+
+int main() {
+ Option<OptionType> option(NAME, "Option with string value", function);
+
+ if (option.understand(OPTION)) {
+ option.handle();
+ }
+ else {
+ cout << "Option class 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";
+ return 0;
+ }
+
+ cout << "Option class do not handle string values\n";
+
+ return 1;
+}