mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 14:16:09 -06:00
.autotest
git-svn-id: svn://ultimatepp.org/upp/trunk@8877 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
baa0a85e88
commit
32a86bea42
3 changed files with 158 additions and 0 deletions
145
autotest/LambdaCallback/LambdaCallback.cpp
Normal file
145
autotest/LambdaCallback/LambdaCallback.cpp
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
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<bool> x;
|
||||
x << [&](bool x) { b = x; };
|
||||
x(true);
|
||||
ASSERT(b);
|
||||
x(false);
|
||||
ASSERT(!b);
|
||||
}
|
||||
{
|
||||
bool b = false;
|
||||
int n = 0;
|
||||
Callback2<bool, int> 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<bool, int, String> 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<bool, int, String, Color> 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<bool> 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<bool, int> 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<bool, int, String> 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<bool, int, String, Color> 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
|
||||
9
autotest/LambdaCallback/LambdaCallback.upp
Normal file
9
autotest/LambdaCallback/LambdaCallback.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
LambdaCallback.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
4
autotest/LambdaCallback/init
Normal file
4
autotest/LambdaCallback/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _LambdaCallback_icpp_init_stub
|
||||
#define _LambdaCallback_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue