diff --git a/autotest/LambdaCallback/LambdaCallback.cpp b/autotest/LambdaCallback/LambdaCallback.cpp new file mode 100644 index 000000000..6527a6753 --- /dev/null +++ b/autotest/LambdaCallback/LambdaCallback.cpp @@ -0,0 +1,145 @@ +#include + +using namespace Upp; + +#ifdef CPP_11 + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + { + bool b = false; + Callback x; + x << [&] { b = true; }; + x(); + ASSERT(b); + } + { + bool b = false; + Callback1 x; + x << [&](bool x) { b = x; }; + x(true); + ASSERT(b); + x(false); + ASSERT(!b); + } + { + bool b = false; + int n = 0; + Callback2 x; + x << [&](bool x, int y) { b = x; n = y; }; + x(true, 12); + ASSERT(b); + ASSERT(n == 12); + x(false, 13); + ASSERT(!b); + ASSERT(n == 13); + } + { + bool b = false; + int n = 0; + String s; + Callback3 x; + x << [&](bool x, int y, String z) { b = x; n = y; s = z; }; + x(true, 12, "one"); + ASSERT(b); + ASSERT(n == 12); + ASSERT(s == "one"); + x(false, 13, "two"); + ASSERT(!b); + ASSERT(n == 13); + ASSERT(s == "two"); + } + { + bool b = false; + int n = 0; + String s; + Color c = Blue; + Callback4 x; + x << [&](bool x, int y, String z, Color q) { b = x; n = y; s = z; c = q; }; + x(true, 12, "one", Blue()); + ASSERT(b); + ASSERT(n == 12); + ASSERT(s == "one"); + ASSERT(c == Blue()); + x(false, 13, "two", Green()); + ASSERT(!b); + ASSERT(n == 13); + ASSERT(s == "two"); + ASSERT(c == Green()); + } + + { + bool b = false; + Gate x; + x << [&]() -> bool { b = true; return b; }; + ASSERT(x()); + ASSERT(b); + } + { + bool b = false; + Gate1 x; + x << [&](bool x) -> bool { b = x; return b; }; + ASSERT(x(true)); + ASSERT(b); + ASSERT(!x(false)); + ASSERT(!b); + } + { + bool b = false; + int n = 0; + Gate2 x; + x << [&](bool x, int y) -> bool { b = x; n = y; return b; }; + ASSERT(x(true, 12)); + ASSERT(b); + ASSERT(n == 12); + ASSERT(!x(false, 13)); + ASSERT(!b); + ASSERT(n == 13); + } + { + bool b = false; + int n = 0; + String s; + Gate3 x; + x << [&](bool x, int y, String z) -> bool { b = x; n = y; s = z; return b; }; + ASSERT(x(true, 12, "one")); + ASSERT(b); + ASSERT(n == 12); + ASSERT(s == "one"); + ASSERT(!x(false, 13, "two")); + ASSERT(!b); + ASSERT(n == 13); + ASSERT(s == "two"); + } + { + bool b = false; + int n = 0; + String s; + Color c = Blue; + Gate4 x; + x << [&](bool x, int y, String z, Color q) -> bool { b = x; n = y; s = z; c = q; return b; }; + ASSERT(x(true, 12, "one", Blue())); + ASSERT(b); + ASSERT(n == 12); + ASSERT(s == "one"); + ASSERT(c == Blue()); + ASSERT(!x(false, 13, "two", Green())); + ASSERT(!b); + ASSERT(n == 13); + ASSERT(s == "two"); + ASSERT(c == Green()); + } + + DLOG("----- Everything OK"); +} + +#else + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + DLOG("----- Not a C++11 compiler, test omitted"); +} + +#endif diff --git a/autotest/LambdaCallback/LambdaCallback.upp b/autotest/LambdaCallback/LambdaCallback.upp new file mode 100644 index 000000000..502cc78ed --- /dev/null +++ b/autotest/LambdaCallback/LambdaCallback.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + LambdaCallback.cpp; + +mainconfig + "" = ""; + diff --git a/autotest/LambdaCallback/init b/autotest/LambdaCallback/init new file mode 100644 index 000000000..2da0240d1 --- /dev/null +++ b/autotest/LambdaCallback/init @@ -0,0 +1,4 @@ +#ifndef _LambdaCallback_icpp_init_stub +#define _LambdaCallback_icpp_init_stub +#include "Core/init" +#endif