mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
Added NotificationQueue::remove function
This includes appropriate tests, which pass on my Mac 10.4 machine
This commit is contained in:
@@ -125,6 +125,10 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
/// Removes all notifications from the queue.
|
/// Removes all notifications from the queue.
|
||||||
|
|
||||||
|
bool remove(Notification::Ptr pNotification);
|
||||||
|
/// Removes a notification from the queue.
|
||||||
|
/// Returns true if remove succeeded, false otherwise
|
||||||
|
|
||||||
bool hasIdleThreads() const;
|
bool hasIdleThreads() const;
|
||||||
/// Returns true if the queue has at least one thread waiting
|
/// Returns true if the queue has at least one thread waiting
|
||||||
/// for a notification.
|
/// for a notification.
|
||||||
|
|||||||
@@ -179,6 +179,19 @@ void NotificationQueue::clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool NotificationQueue::remove(Notification::Ptr pNotification)
|
||||||
|
{
|
||||||
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
|
NfQueue::iterator it = std::find(_nfQueue.begin(), _nfQueue.end(), pNotification);
|
||||||
|
if (it == _nfQueue.end())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_nfQueue.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool NotificationQueue::hasIdleThreads() const
|
bool NotificationQueue::hasIdleThreads() const
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
|
|||||||
@@ -190,6 +190,29 @@ void NotificationQueueTest::testDefaultQueue()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NotificationQueueTest::testQueueRemove()
|
||||||
|
{
|
||||||
|
NotificationQueue queue;
|
||||||
|
Notification::Ptr frontNotification = new QTestNotification("front");
|
||||||
|
Notification::Ptr middleNotification = new QTestNotification("middle");
|
||||||
|
Notification::Ptr backNotification = new QTestNotification("back");
|
||||||
|
queue.enqueueNotification(frontNotification);
|
||||||
|
queue.enqueueNotification(new QTestNotification("dummy"));
|
||||||
|
queue.enqueueNotification(middleNotification);
|
||||||
|
queue.enqueueNotification(new QTestNotification("dummy"));
|
||||||
|
queue.enqueueNotification(backNotification);
|
||||||
|
assert (queue.size() == 5);
|
||||||
|
assert (queue.remove(frontNotification));
|
||||||
|
assert (queue.size() == 4);
|
||||||
|
assert (queue.remove(middleNotification));
|
||||||
|
assert (queue.size() == 3);
|
||||||
|
assert (queue.remove(backNotification));
|
||||||
|
assert (queue.size() == 2);
|
||||||
|
assert (!queue.remove(backNotification));
|
||||||
|
assert (queue.size() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void NotificationQueueTest::setUp()
|
void NotificationQueueTest::setUp()
|
||||||
{
|
{
|
||||||
_handled.clear();
|
_handled.clear();
|
||||||
@@ -227,6 +250,7 @@ CppUnit::Test* NotificationQueueTest::suite()
|
|||||||
CppUnit_addTest(pSuite, NotificationQueueTest, testWaitDequeue);
|
CppUnit_addTest(pSuite, NotificationQueueTest, testWaitDequeue);
|
||||||
CppUnit_addTest(pSuite, NotificationQueueTest, testThreads);
|
CppUnit_addTest(pSuite, NotificationQueueTest, testThreads);
|
||||||
CppUnit_addTest(pSuite, NotificationQueueTest, testDefaultQueue);
|
CppUnit_addTest(pSuite, NotificationQueueTest, testDefaultQueue);
|
||||||
|
CppUnit_addTest(pSuite, NotificationQueueTest, testQueueRemove);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public:
|
|||||||
void testWaitDequeue();
|
void testWaitDequeue();
|
||||||
void testThreads();
|
void testThreads();
|
||||||
void testDefaultQueue();
|
void testDefaultQueue();
|
||||||
|
void testQueueRemove();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|||||||
Reference in New Issue
Block a user