Add Required tests.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 6 May 2015 06:27:28 +0000 (08:27 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 6 May 2015 06:27:28 +0000 (08:27 +0200)
tests/Makefile.am
tests/required/should_be_required.cpp [new file with mode: 0644]

index 11c3c1800278de23e0a90b806be2c9374ba6770f..6a0fa06e817a8d3e019ca9bb6d09de7217ad2c7c 100644 (file)
@@ -19,7 +19,8 @@ TESTS = \
        option_handles_boolean_value.test \
        option_handles_void_value.test \
        option_should_match_exact_name.test \
-       option_should_throw_exception_on_missing_value.test
+       option_should_throw_exception_on_missing_value.test \
+       required_should_be_required.test
 
 noinst_PROGRAMS = $(TESTS)
 
@@ -48,3 +49,5 @@ option_handles_boolean_value_test_SOURCES  = option/handles_boolean_value.cpp
 option_handles_void_value_test_SOURCES  = option/handles_void_value.cpp
 option_should_match_exact_name_test_SOURCES  = option/should_match_exact_name.cpp
 option_should_throw_exception_on_missing_value_test_SOURCES = option/should_throw_exception_on_missing_value.cpp
+
+required_should_be_required_test_SOURCES = required/should_be_required.cpp
diff --git a/tests/required/should_be_required.cpp b/tests/required/should_be_required.cpp
new file mode 100644 (file)
index 0000000..b59db3d
--- /dev/null
@@ -0,0 +1,37 @@
+#include <iostream>
+
+#include "required.h"
+#include "argument.h"
+#include "option.h"
+
+using namespace std;
+using namespace command;
+
+#define NAME "test"
+#define VALUE "1"
+
+#define OPTION NAME "=" VALUE
+
+typedef int Type;
+
+void function(Type val) { }
+
+int main() {
+    Parameter * requiredOption = new Required(new Option<Type>(NAME, "Required Option", function));
+    Parameter * requiredArgument = new Required(new Argument<Type>("Required Argument", function));
+
+    if (!requiredOption->isRequired()) {
+        cout << requiredOption->describe() << " should be treated as required but it is not\n";
+        delete requiredOption;
+        return 1;
+    }
+    if (!requiredArgument->isRequired()) {
+        cout << requiredArgument->describe() << " should be treated as required but it is not\n";
+        delete requiredOption;
+        return 1;
+    }
+
+    cout << "Required decorator correctly returns its property\n";
+
+    return 0;
+}