mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 12:18:01 +01:00
testsuite for void event
This commit is contained in:
@@ -61,6 +61,17 @@ void BasicEventTest::testNoDelegate()
|
|||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
EventArgs args;
|
EventArgs args;
|
||||||
|
|
||||||
|
assert (_count == 0);
|
||||||
|
assert (Void.empty());
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 0);
|
||||||
|
|
||||||
|
Void += delegate(this, &BasicEventTest::onVoid);
|
||||||
|
assert (!Void.empty());
|
||||||
|
Void -= delegate(this, &BasicEventTest::onVoid);
|
||||||
|
assert (Void.empty());
|
||||||
|
Void.notify(this);
|
||||||
|
|
||||||
assert (_count == 0);
|
assert (_count == 0);
|
||||||
assert (Simple.empty());
|
assert (Simple.empty());
|
||||||
Simple.notify(this, tmp);
|
Simple.notify(this, tmp);
|
||||||
@@ -114,6 +125,13 @@ void BasicEventTest::testNoDelegate()
|
|||||||
Simple.notify(this, tmp);
|
Simple.notify(this, tmp);
|
||||||
assert (_count == 3);
|
assert (_count == 3);
|
||||||
Simple -= delegate(BasicEventTest::onStaticSimple);
|
Simple -= delegate(BasicEventTest::onStaticSimple);
|
||||||
|
|
||||||
|
Void += delegate(&BasicEventTest::onStaticVoid);
|
||||||
|
Void += delegate(&BasicEventTest::onStaticVoid);
|
||||||
|
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 5);
|
||||||
|
Void -= delegate(BasicEventTest::onStaticVoid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicEventTest::testSingleDelegate()
|
void BasicEventTest::testSingleDelegate()
|
||||||
@@ -123,34 +141,38 @@ void BasicEventTest::testSingleDelegate()
|
|||||||
|
|
||||||
assert (_count == 0);
|
assert (_count == 0);
|
||||||
|
|
||||||
|
Void += delegate(this, &BasicEventTest::onVoid);
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 1);
|
||||||
|
|
||||||
Simple += delegate(this, &BasicEventTest::onSimple);
|
Simple += delegate(this, &BasicEventTest::onSimple);
|
||||||
Simple.notify(this, tmp);
|
Simple.notify(this, tmp);
|
||||||
assert (_count == 1);
|
assert (_count == 2);
|
||||||
|
|
||||||
ConstSimple += delegate(this, &BasicEventTest::onConstSimple);
|
ConstSimple += delegate(this, &BasicEventTest::onConstSimple);
|
||||||
ConstSimple.notify(this, tmp);
|
ConstSimple.notify(this, tmp);
|
||||||
assert (_count == 2);
|
assert (_count == 3);
|
||||||
|
|
||||||
EventArgs* pArgs = &args;
|
EventArgs* pArgs = &args;
|
||||||
Complex += delegate(this, &BasicEventTest::onComplex);
|
Complex += delegate(this, &BasicEventTest::onComplex);
|
||||||
Complex.notify(this, pArgs);
|
Complex.notify(this, pArgs);
|
||||||
assert (_count == 3);
|
assert (_count == 4);
|
||||||
|
|
||||||
Complex2 += delegate(this, &BasicEventTest::onComplex2);
|
Complex2 += delegate(this, &BasicEventTest::onComplex2);
|
||||||
Complex2.notify(this, args);
|
Complex2.notify(this, args);
|
||||||
assert (_count == 4);
|
assert (_count == 5);
|
||||||
|
|
||||||
const EventArgs* pCArgs = &args;
|
const EventArgs* pCArgs = &args;
|
||||||
ConstComplex += delegate(this, &BasicEventTest::onConstComplex);
|
ConstComplex += delegate(this, &BasicEventTest::onConstComplex);
|
||||||
ConstComplex.notify(this, pCArgs);
|
ConstComplex.notify(this, pCArgs);
|
||||||
assert (_count == 5);
|
assert (_count == 6);
|
||||||
|
|
||||||
Const2Complex += delegate(this, &BasicEventTest::onConst2Complex);
|
Const2Complex += delegate(this, &BasicEventTest::onConst2Complex);
|
||||||
Const2Complex.notify(this, pArgs);
|
Const2Complex.notify(this, pArgs);
|
||||||
assert (_count == 6);
|
assert (_count == 7);
|
||||||
// check if 2nd notify also works
|
// check if 2nd notify also works
|
||||||
Const2Complex.notify(this, pArgs);
|
Const2Complex.notify(this, pArgs);
|
||||||
assert (_count == 7);
|
assert (_count == 8);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,6 +337,16 @@ void BasicEventTest::testAsyncNotify()
|
|||||||
assert (_count == LARGEINC);
|
assert (_count == LARGEINC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BasicEventTest::onStaticVoid(const void* pSender)
|
||||||
|
{
|
||||||
|
BasicEventTest* p = const_cast<BasicEventTest*>(reinterpret_cast<const BasicEventTest*>(pSender));
|
||||||
|
p->_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BasicEventTest::onVoid(const void* pSender)
|
||||||
|
{
|
||||||
|
_count++;
|
||||||
|
}
|
||||||
|
|
||||||
void BasicEventTest::onSimpleNoSender(int& i)
|
void BasicEventTest::onSimpleNoSender(int& i)
|
||||||
{
|
{
|
||||||
@@ -394,6 +426,7 @@ void BasicEventTest::setUp()
|
|||||||
// must clear events, otherwise repeating test executions will fail
|
// must clear events, otherwise repeating test executions will fail
|
||||||
// because tests are only created once, only setup is called before
|
// because tests are only created once, only setup is called before
|
||||||
// each test run
|
// each test run
|
||||||
|
Void.clear();
|
||||||
Simple.clear();
|
Simple.clear();
|
||||||
ConstSimple.clear();
|
ConstSimple.clear();
|
||||||
Complex.clear();
|
Complex.clear();
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
class BasicEventTest: public CppUnit::TestCase
|
class BasicEventTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
|
Poco::BasicEvent<void> Void;
|
||||||
Poco::BasicEvent<int> Simple;
|
Poco::BasicEvent<int> Simple;
|
||||||
Poco::BasicEvent<const int> ConstSimple;
|
Poco::BasicEvent<const int> ConstSimple;
|
||||||
Poco::BasicEvent<Poco::EventArgs*> Complex;
|
Poco::BasicEvent<Poco::EventArgs*> Complex;
|
||||||
@@ -72,9 +73,14 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
static void onStaticVoid(const void* pSender);
|
||||||
|
|
||||||
|
void onVoid(const void* pSender);
|
||||||
|
|
||||||
static void onStaticSimple(const void* pSender, int& i);
|
static void onStaticSimple(const void* pSender, int& i);
|
||||||
static void onStaticSimple2(void* pSender, int& i);
|
static void onStaticSimple2(void* pSender, int& i);
|
||||||
static void onStaticSimple3(int& i);
|
static void onStaticSimple3(int& i);
|
||||||
|
|
||||||
void onSimpleNoSender(int& i);
|
void onSimpleNoSender(int& i);
|
||||||
void onSimple(const void* pSender, int& i);
|
void onSimple(const void* pSender, int& i);
|
||||||
void onSimpleOther(const void* pSender, int& i);
|
void onSimpleOther(const void* pSender, int& i);
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ void FIFOEventTest::testNoDelegate()
|
|||||||
EventArgs args;
|
EventArgs args;
|
||||||
|
|
||||||
assert (_count == 0);
|
assert (_count == 0);
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 0);
|
||||||
|
|
||||||
|
Void += delegate(this, &FIFOEventTest::onVoid);
|
||||||
|
Void -= delegate(this, &FIFOEventTest::onVoid);
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 0);
|
||||||
|
|
||||||
Simple.notify(this, tmp);
|
Simple.notify(this, tmp);
|
||||||
assert (_count == 0);
|
assert (_count == 0);
|
||||||
|
|
||||||
@@ -105,34 +113,38 @@ void FIFOEventTest::testSingleDelegate()
|
|||||||
|
|
||||||
assert (_count == 0);
|
assert (_count == 0);
|
||||||
|
|
||||||
|
Void += delegate(this, &FIFOEventTest::onVoid);
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 1);
|
||||||
|
|
||||||
Simple += delegate(this, &FIFOEventTest::onSimple);
|
Simple += delegate(this, &FIFOEventTest::onSimple);
|
||||||
Simple.notify(this, tmp);
|
Simple.notify(this, tmp);
|
||||||
assert (_count == 1);
|
assert (_count == 2);
|
||||||
|
|
||||||
ConstSimple += delegate(this, &FIFOEventTest::onConstSimple);
|
ConstSimple += delegate(this, &FIFOEventTest::onConstSimple);
|
||||||
ConstSimple.notify(this, tmp);
|
ConstSimple.notify(this, tmp);
|
||||||
assert (_count == 2);
|
assert (_count == 3);
|
||||||
|
|
||||||
EventArgs* pArgs = &args;
|
EventArgs* pArgs = &args;
|
||||||
Complex += delegate(this, &FIFOEventTest::onComplex);
|
Complex += delegate(this, &FIFOEventTest::onComplex);
|
||||||
Complex.notify(this, pArgs);
|
Complex.notify(this, pArgs);
|
||||||
assert (_count == 3);
|
assert (_count == 4);
|
||||||
|
|
||||||
Complex2 += delegate(this, &FIFOEventTest::onComplex2);
|
Complex2 += delegate(this, &FIFOEventTest::onComplex2);
|
||||||
Complex2.notify(this, args);
|
Complex2.notify(this, args);
|
||||||
assert (_count == 4);
|
assert (_count == 5);
|
||||||
|
|
||||||
const EventArgs* pCArgs = &args;
|
const EventArgs* pCArgs = &args;
|
||||||
ConstComplex += delegate(this, &FIFOEventTest::onConstComplex);
|
ConstComplex += delegate(this, &FIFOEventTest::onConstComplex);
|
||||||
ConstComplex.notify(this, pCArgs);
|
ConstComplex.notify(this, pCArgs);
|
||||||
assert (_count == 5);
|
assert (_count == 6);
|
||||||
|
|
||||||
Const2Complex += delegate(this, &FIFOEventTest::onConst2Complex);
|
Const2Complex += delegate(this, &FIFOEventTest::onConst2Complex);
|
||||||
Const2Complex.notify(this, pArgs);
|
Const2Complex.notify(this, pArgs);
|
||||||
assert (_count == 6);
|
assert (_count == 7);
|
||||||
// check if 2nd notify also works
|
// check if 2nd notify also works
|
||||||
Const2Complex.notify(this, pArgs);
|
Const2Complex.notify(this, pArgs);
|
||||||
assert (_count == 7);
|
assert (_count == 8);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,6 +365,11 @@ void FIFOEventTest::testAsyncNotify()
|
|||||||
assert (_count == LARGEINC);
|
assert (_count == LARGEINC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FIFOEventTest::onVoid(const void* pSender)
|
||||||
|
{
|
||||||
|
_count++;
|
||||||
|
}
|
||||||
|
|
||||||
void FIFOEventTest::onSimple(const void* pSender, int& i)
|
void FIFOEventTest::onSimple(const void* pSender, int& i)
|
||||||
{
|
{
|
||||||
_count++;
|
_count++;
|
||||||
@@ -405,6 +422,7 @@ void FIFOEventTest::setUp()
|
|||||||
// must clear events, otherwise repeating test executions will fail
|
// must clear events, otherwise repeating test executions will fail
|
||||||
// because tests are only created once, only setup is called before
|
// because tests are only created once, only setup is called before
|
||||||
// each test run
|
// each test run
|
||||||
|
Void.clear();
|
||||||
Simple.clear();
|
Simple.clear();
|
||||||
ConstSimple.clear();
|
ConstSimple.clear();
|
||||||
Complex.clear();
|
Complex.clear();
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
class FIFOEventTest: public CppUnit::TestCase
|
class FIFOEventTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
|
Poco::FIFOEvent<void> Void;
|
||||||
Poco::FIFOEvent<int> Simple;
|
Poco::FIFOEvent<int> Simple;
|
||||||
Poco::FIFOEvent<const int> ConstSimple;
|
Poco::FIFOEvent<const int> ConstSimple;
|
||||||
Poco::FIFOEvent<Poco::EventArgs*> Complex;
|
Poco::FIFOEvent<Poco::EventArgs*> Complex;
|
||||||
@@ -72,7 +73,7 @@ public:
|
|||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void onVoid(const void* pSender);
|
||||||
void onSimple(const void* pSender, int& i);
|
void onSimple(const void* pSender, int& i);
|
||||||
void onSimpleOther(const void* pSender, int& i);
|
void onSimpleOther(const void* pSender, int& i);
|
||||||
void onConstSimple(const void* pSender, const int& i);
|
void onConstSimple(const void* pSender, const int& i);
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ void PriorityEventTest::testNoDelegate()
|
|||||||
EventArgs args;
|
EventArgs args;
|
||||||
|
|
||||||
assert (_count == 0);
|
assert (_count == 0);
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 0);
|
||||||
|
|
||||||
|
Void += priorityDelegate(this, &PriorityEventTest::onVoid, 0);
|
||||||
|
Void -= priorityDelegate(this, &PriorityEventTest::onVoid, 0);
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 0);
|
||||||
|
|
||||||
Simple.notify(this, tmp);
|
Simple.notify(this, tmp);
|
||||||
assert (_count == 0);
|
assert (_count == 0);
|
||||||
|
|
||||||
@@ -111,6 +119,15 @@ void PriorityEventTest::testNoDelegate()
|
|||||||
Simple.notify(this, tmp);
|
Simple.notify(this, tmp);
|
||||||
assert (_count == 4);
|
assert (_count == 4);
|
||||||
Simple -= priorityDelegate(PriorityEventTest::onStaticSimple, 0);
|
Simple -= priorityDelegate(PriorityEventTest::onStaticSimple, 0);
|
||||||
|
|
||||||
|
|
||||||
|
Void += priorityDelegate(&PriorityEventTest::onStaticVoid, 0);
|
||||||
|
Void += priorityDelegate(&PriorityEventTest::onStaticVoid, 0);
|
||||||
|
Void += priorityDelegate(&PriorityEventTest::onStaticVoid, 1);
|
||||||
|
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 7);
|
||||||
|
Void -= priorityDelegate(PriorityEventTest::onStaticVoid, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PriorityEventTest::testSingleDelegate()
|
void PriorityEventTest::testSingleDelegate()
|
||||||
@@ -120,41 +137,47 @@ void PriorityEventTest::testSingleDelegate()
|
|||||||
|
|
||||||
assert (_count == 0);
|
assert (_count == 0);
|
||||||
|
|
||||||
|
Void += priorityDelegate(this, &PriorityEventTest::onVoid, 0);
|
||||||
|
// unregistering with a different priority --> different observer, is ignored
|
||||||
|
Void -= priorityDelegate(this, &PriorityEventTest::onVoid, 3);
|
||||||
|
Void.notify(this);
|
||||||
|
assert (_count == 1);
|
||||||
|
|
||||||
Simple += priorityDelegate(this, &PriorityEventTest::onSimple, 0);
|
Simple += priorityDelegate(this, &PriorityEventTest::onSimple, 0);
|
||||||
// unregistering with a different priority --> different observer, is ignored
|
// unregistering with a different priority --> different observer, is ignored
|
||||||
Simple -= priorityDelegate(this, &PriorityEventTest::onSimple, 3);
|
Simple -= priorityDelegate(this, &PriorityEventTest::onSimple, 3);
|
||||||
Simple.notify(this, tmp);
|
Simple.notify(this, tmp);
|
||||||
assert (_count == 1);
|
assert (_count == 2);
|
||||||
|
|
||||||
ConstSimple += priorityDelegate(this, &PriorityEventTest::onConstSimple, 0);
|
ConstSimple += priorityDelegate(this, &PriorityEventTest::onConstSimple, 0);
|
||||||
ConstSimple -= priorityDelegate(this, &PriorityEventTest::onConstSimple, 3);
|
ConstSimple -= priorityDelegate(this, &PriorityEventTest::onConstSimple, 3);
|
||||||
ConstSimple.notify(this, tmp);
|
ConstSimple.notify(this, tmp);
|
||||||
assert (_count == 2);
|
assert (_count == 3);
|
||||||
|
|
||||||
EventArgs* pArgs = &args;
|
EventArgs* pArgs = &args;
|
||||||
Complex += priorityDelegate(this, &PriorityEventTest::onComplex, 0);
|
Complex += priorityDelegate(this, &PriorityEventTest::onComplex, 0);
|
||||||
Complex -= priorityDelegate(this, &PriorityEventTest::onComplex, 3);
|
Complex -= priorityDelegate(this, &PriorityEventTest::onComplex, 3);
|
||||||
Complex.notify(this, pArgs);
|
Complex.notify(this, pArgs);
|
||||||
assert (_count == 3);
|
assert (_count == 4);
|
||||||
|
|
||||||
Complex2 += priorityDelegate(this, &PriorityEventTest::onComplex2, 0);
|
Complex2 += priorityDelegate(this, &PriorityEventTest::onComplex2, 0);
|
||||||
Complex2 -= priorityDelegate(this, &PriorityEventTest::onComplex2, 3);
|
Complex2 -= priorityDelegate(this, &PriorityEventTest::onComplex2, 3);
|
||||||
Complex2.notify(this, args);
|
Complex2.notify(this, args);
|
||||||
assert (_count == 4);
|
assert (_count == 5);
|
||||||
|
|
||||||
const EventArgs* pCArgs = &args;
|
const EventArgs* pCArgs = &args;
|
||||||
ConstComplex += priorityDelegate(this, &PriorityEventTest::onConstComplex, 0);
|
ConstComplex += priorityDelegate(this, &PriorityEventTest::onConstComplex, 0);
|
||||||
ConstComplex -= priorityDelegate(this, &PriorityEventTest::onConstComplex, 3);
|
ConstComplex -= priorityDelegate(this, &PriorityEventTest::onConstComplex, 3);
|
||||||
ConstComplex.notify(this, pCArgs);
|
ConstComplex.notify(this, pCArgs);
|
||||||
assert (_count == 5);
|
assert (_count == 6);
|
||||||
|
|
||||||
Const2Complex += priorityDelegate(this, &PriorityEventTest::onConst2Complex, 0);
|
Const2Complex += priorityDelegate(this, &PriorityEventTest::onConst2Complex, 0);
|
||||||
Const2Complex -= priorityDelegate(this, &PriorityEventTest::onConst2Complex, 3);
|
Const2Complex -= priorityDelegate(this, &PriorityEventTest::onConst2Complex, 3);
|
||||||
Const2Complex.notify(this, pArgs);
|
Const2Complex.notify(this, pArgs);
|
||||||
assert (_count == 6);
|
assert (_count == 7);
|
||||||
// check if 2nd notify also works
|
// check if 2nd notify also works
|
||||||
Const2Complex.notify(this, pArgs);
|
Const2Complex.notify(this, pArgs);
|
||||||
assert (_count == 7);
|
assert (_count == 8);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,6 +423,15 @@ void PriorityEventTest::testAsyncNotify()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PriorityEventTest::onStaticVoid(const void* pSender)
|
||||||
|
{
|
||||||
|
PriorityEventTest* p = const_cast<PriorityEventTest*>(reinterpret_cast<const PriorityEventTest*>(pSender));
|
||||||
|
p->_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PriorityEventTest::onVoid(const void* pSender){
|
||||||
|
_count++;
|
||||||
|
}
|
||||||
|
|
||||||
void PriorityEventTest::onStaticSimple(const void* pSender, int& i)
|
void PriorityEventTest::onStaticSimple(const void* pSender, int& i)
|
||||||
{
|
{
|
||||||
@@ -478,6 +510,7 @@ void PriorityEventTest::setUp()
|
|||||||
// must clear events, otherwise repeating test executions will fail
|
// must clear events, otherwise repeating test executions will fail
|
||||||
// because tests are only created once, only setup is called before
|
// because tests are only created once, only setup is called before
|
||||||
// each test run
|
// each test run
|
||||||
|
Void.clear();
|
||||||
Simple.clear();
|
Simple.clear();
|
||||||
ConstSimple.clear();
|
ConstSimple.clear();
|
||||||
Complex.clear();
|
Complex.clear();
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
class PriorityEventTest: public CppUnit::TestCase
|
class PriorityEventTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
|
Poco::PriorityEvent<void> Void;
|
||||||
Poco::PriorityEvent<int> Simple;
|
Poco::PriorityEvent<int> Simple;
|
||||||
Poco::PriorityEvent<const int> ConstSimple;
|
Poco::PriorityEvent<const int> ConstSimple;
|
||||||
Poco::PriorityEvent<Poco::EventArgs*> Complex;
|
Poco::PriorityEvent<Poco::EventArgs*> Complex;
|
||||||
@@ -72,6 +73,10 @@ public:
|
|||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
static void onStaticVoid(const void* pSender);
|
||||||
|
|
||||||
|
void onVoid(const void* pSender);
|
||||||
|
|
||||||
static void onStaticSimple(const void* pSender, int& i);
|
static void onStaticSimple(const void* pSender, int& i);
|
||||||
static void onStaticSimple2(void* pSender, int& i);
|
static void onStaticSimple2(void* pSender, int& i);
|
||||||
static void onStaticSimple3(int& i);
|
static void onStaticSimple3(int& i);
|
||||||
|
|||||||
Reference in New Issue
Block a user