Mercurial > hg > orthanc
diff UnitTests/main.cpp @ 450:58b433bb9762
SharedMessageQueue
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Jul 2013 09:34:09 +0200 |
parents | beca6747945e |
children | 80f7539147a2 |
line wrap: on
line diff
--- a/UnitTests/main.cpp Tue Jun 25 16:30:21 2013 +0200 +++ b/UnitTests/main.cpp Thu Jul 04 09:34:09 2013 +0200 @@ -13,6 +13,7 @@ #include "../Core/Uuid.h" #include "../OrthancServer/FromDcmtkBridge.h" #include "../OrthancServer/OrthancInitialization.h" +#include "../Core/MultiThreading/SharedMessageQueue.h" using namespace Orthanc; @@ -397,6 +398,57 @@ } + +class DynamicInteger : public IDynamicObject +{ +private: + int value_; + +public: + DynamicInteger(int value) : value_(value) + { + } + + int GetValue() const + { + return value_; + } +}; + + +TEST(SharedMessageQueue, Basic) +{ + SharedMessageQueue q; + q.Enqueue(new DynamicInteger(10)); + q.Enqueue(new DynamicInteger(20)); + q.Enqueue(new DynamicInteger(30)); + q.Enqueue(new DynamicInteger(40)); + + std::auto_ptr<DynamicInteger> i; + i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(10))); ASSERT_EQ(10, i->GetValue()); + i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(10))); ASSERT_EQ(20, i->GetValue()); + i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(10))); ASSERT_EQ(30, i->GetValue()); + i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(10))); ASSERT_EQ(40, i->GetValue()); + + ASSERT_EQ(NULL, q.Dequeue(10)); +} + + +TEST(SharedMessageQueue, Clean) +{ + try + { + SharedMessageQueue q; + q.Enqueue(new DynamicInteger(10)); + q.Enqueue(new DynamicInteger(20)); + throw OrthancException("Nope"); + } + catch (OrthancException) + { + } +} + + int main(int argc, char **argv) { // Initialize Google's logging library.