Add some tests.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 2 May 2015 16:23:41 +0000 (18:23 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 2 May 2015 16:23:41 +0000 (18:23 +0200)
tests/Makefile.am
tests/callable/TestCallable.h [new file with mode: 0644]
tests/callable/invokes_provided_function.cpp [new file with mode: 0644]
tests/descriptive/holds_data.cpp [new file with mode: 0644]
tests/parameter/is_descriptive.cpp [new file with mode: 0644]

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..4572a3b516cf25592b4b197978cb0dde025d94cf 100644 (file)
@@ -0,0 +1,14 @@
+AUTOMAKE_OPTIONS = subdir-objects
+
+TESTS = \
+       descriptive_holds_data.test \
+       callable_invokes_provided_function.test \
+       parameter_is_descriptive.test
+
+noinst_PROGRAMS = $(TESTS)
+
+AM_CXXFLAGS = -O3 -I$(top_srcdir)/include -std=c++11
+
+descriptive_holds_data_test_SOURCES  = descriptive/holds_data.cpp
+callable_invokes_provided_function_test_SOURCES  = callable/invokes_provided_function.cpp
+parameter_is_descriptive_test_SOURCES  = parameter/is_descriptive.cpp
diff --git a/tests/callable/TestCallable.h b/tests/callable/TestCallable.h
new file mode 100644 (file)
index 0000000..097e115
--- /dev/null
@@ -0,0 +1,15 @@
+#include "callable.h"
+
+using namespace command;
+
+template<typename ArgumentType>
+class TestCallable : public Callable<ArgumentType> {
+public:
+    TestCallable(void (*function)(ArgumentType))
+        : Callable<ArgumentType>(function) {
+    }
+
+    void callFunction(ArgumentType test) {
+        this->call(test);
+    }
+};
diff --git a/tests/callable/invokes_provided_function.cpp b/tests/callable/invokes_provided_function.cpp
new file mode 100644 (file)
index 0000000..7322da5
--- /dev/null
@@ -0,0 +1,30 @@
+#include <cstring>
+#include <iostream>
+
+#include "TestCallable.h"
+#include "callable.h"
+
+using namespace std;
+using namespace command;
+
+bool test = false;
+
+void function(bool val) {
+    test = val;
+};
+
+int main() {
+
+    TestCallable<bool> callable(function);
+    callable.callFunction(true);
+
+    if (test == true) {
+        cout << "Callable class calls provided function\n";
+        return 0;
+    }
+
+    cout << "Callable class does not call provided function\n";
+
+    return 1;
+}
+
diff --git a/tests/descriptive/holds_data.cpp b/tests/descriptive/holds_data.cpp
new file mode 100644 (file)
index 0000000..df0e010
--- /dev/null
@@ -0,0 +1,25 @@
+#include <cstring>
+#include <iostream>
+
+#include "descriptive.h"
+
+using namespace std;
+using namespace command;
+
+#define STRING "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+
+int main() {
+    Descriptive descriptive(STRING);
+
+    int cmp = strcmp(descriptive.describe().c_str(), STRING);
+
+    if (cmp == 0) {
+        cout << "Descriptive class holds data correctly\n";
+        return 0;
+    }
+
+    cout << "Descriptive class changes provided description\n";
+
+    return 1;
+}
+
diff --git a/tests/parameter/is_descriptive.cpp b/tests/parameter/is_descriptive.cpp
new file mode 100644 (file)
index 0000000..0b9c733
--- /dev/null
@@ -0,0 +1,33 @@
+#include <cstring>
+#include <iostream>
+
+#include "parameter.h"
+
+using namespace std;
+using namespace command;
+
+#define STRING "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+
+class TestParameter : public Parameter {
+public:
+    TestParameter(std::string description) : Parameter(description) { }
+
+    virtual void handle() { }
+    virtual bool understand(std::string argVal) { }
+};
+
+int main() {
+    TestParameter parameter(STRING);
+
+    int cmp = strcmp(parameter.describe().c_str(), STRING);
+
+    if (cmp == 0) {
+        cout << "Parameter class is descriptive\n";
+        return 0;
+    }
+
+    cout << "Parameter class changes provided description so is not descriptive\n";
+
+    return 1;
+}
+