From 35da2ab13d099d9c332b1671046de55a41ee39b7 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 31 Aug 2015 08:59:13 +0000 Subject: [PATCH] .autotest git-svn-id: svn://ultimatepp.org/upp/trunk@8877 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- autotest/LambdaCallback/LambdaCallback.cpp | 145 +++++++++++++++++++++ autotest/LambdaCallback/LambdaCallback.upp | 9 ++ autotest/LambdaCallback/init | 4 + 3 files changed, 158 insertions(+) create mode 100644 autotest/LambdaCallback/LambdaCallback.cpp create mode 100644 autotest/LambdaCallback/LambdaCallback.upp create mode 100644 autotest/LambdaCallback/init 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