comparison 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
comparison
equal deleted inserted replaced
449:694f06a84bf4 450:58b433bb9762
11 #include "../Core/OrthancException.h" 11 #include "../Core/OrthancException.h"
12 #include "../Core/Toolbox.h" 12 #include "../Core/Toolbox.h"
13 #include "../Core/Uuid.h" 13 #include "../Core/Uuid.h"
14 #include "../OrthancServer/FromDcmtkBridge.h" 14 #include "../OrthancServer/FromDcmtkBridge.h"
15 #include "../OrthancServer/OrthancInitialization.h" 15 #include "../OrthancServer/OrthancInitialization.h"
16 #include "../Core/MultiThreading/SharedMessageQueue.h"
16 17
17 using namespace Orthanc; 18 using namespace Orthanc;
18 19
19 20
20 TEST(Uuid, Generation) 21 TEST(Uuid, Generation)
395 ASSERT_EQ(2047, StringToMetadata("2047")); 396 ASSERT_EQ(2047, StringToMetadata("2047"));
396 ASSERT_EQ(2047, StringToMetadata("Ceci est un test")); 397 ASSERT_EQ(2047, StringToMetadata("Ceci est un test"));
397 } 398 }
398 399
399 400
401
402 class DynamicInteger : public IDynamicObject
403 {
404 private:
405 int value_;
406
407 public:
408 DynamicInteger(int value) : value_(value)
409 {
410 }
411
412 int GetValue() const
413 {
414 return value_;
415 }
416 };
417
418
419 TEST(SharedMessageQueue, Basic)
420 {
421 SharedMessageQueue q;
422 q.Enqueue(new DynamicInteger(10));
423 q.Enqueue(new DynamicInteger(20));
424 q.Enqueue(new DynamicInteger(30));
425 q.Enqueue(new DynamicInteger(40));
426
427 std::auto_ptr<DynamicInteger> i;
428 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(10))); ASSERT_EQ(10, i->GetValue());
429 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(10))); ASSERT_EQ(20, i->GetValue());
430 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(10))); ASSERT_EQ(30, i->GetValue());
431 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(10))); ASSERT_EQ(40, i->GetValue());
432
433 ASSERT_EQ(NULL, q.Dequeue(10));
434 }
435
436
437 TEST(SharedMessageQueue, Clean)
438 {
439 try
440 {
441 SharedMessageQueue q;
442 q.Enqueue(new DynamicInteger(10));
443 q.Enqueue(new DynamicInteger(20));
444 throw OrthancException("Nope");
445 }
446 catch (OrthancException)
447 {
448 }
449 }
450
451
400 int main(int argc, char **argv) 452 int main(int argc, char **argv)
401 { 453 {
402 // Initialize Google's logging library. 454 // Initialize Google's logging library.
403 FLAGS_logtostderr = true; 455 FLAGS_logtostderr = true;
404 FLAGS_minloglevel = 0; 456 FLAGS_minloglevel = 0;