From: Rafał Długołęcki Date: Sat, 2 May 2015 16:23:41 +0000 (+0200) Subject: Add some tests. X-Git-Tag: v0.2~35 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=d4b5ce7fcb3c7ffcfbdc28684a66f0b21b7ec446;p=command.git Add some tests. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index e69de29..4572a3b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 0000000..097e115 --- /dev/null +++ b/tests/callable/TestCallable.h @@ -0,0 +1,15 @@ +#include "callable.h" + +using namespace command; + +template +class TestCallable : public Callable { +public: + TestCallable(void (*function)(ArgumentType)) + : Callable(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 index 0000000..7322da5 --- /dev/null +++ b/tests/callable/invokes_provided_function.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include "TestCallable.h" +#include "callable.h" + +using namespace std; +using namespace command; + +bool test = false; + +void function(bool val) { + test = val; +}; + +int main() { + + TestCallable 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 index 0000000..df0e010 --- /dev/null +++ b/tests/descriptive/holds_data.cpp @@ -0,0 +1,25 @@ +#include +#include + +#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 index 0000000..0b9c733 --- /dev/null +++ b/tests/parameter/is_descriptive.cpp @@ -0,0 +1,33 @@ +#include +#include + +#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; +} +