comparison UnitTestsSources/main.cpp @ 723:0da078f3affc

multithreading tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Feb 2014 16:18:42 +0100
parents 38e2883e096f
children
comparison
equal deleted inserted replaced
722:3596177682a9 723:0da078f3affc
10 #include "../Core/OrthancException.h" 10 #include "../Core/OrthancException.h"
11 #include "../Core/Toolbox.h" 11 #include "../Core/Toolbox.h"
12 #include "../Core/Uuid.h" 12 #include "../Core/Uuid.h"
13 #include "../OrthancServer/FromDcmtkBridge.h" 13 #include "../OrthancServer/FromDcmtkBridge.h"
14 #include "../OrthancServer/OrthancInitialization.h" 14 #include "../OrthancServer/OrthancInitialization.h"
15 #include "../Core/MultiThreading/SharedMessageQueue.h"
16 15
17 using namespace Orthanc; 16 using namespace Orthanc;
18 17
19 18
20 TEST(Uuid, Generation) 19 TEST(Uuid, Generation)
496 ASSERT_EQ(2047, StringToMetadata("Ceci est un test")); 495 ASSERT_EQ(2047, StringToMetadata("Ceci est un test"));
497 } 496 }
498 497
499 498
500 499
501 class DynamicInteger : public IDynamicObject
502 {
503 private:
504 int value_;
505
506 public:
507 DynamicInteger(int value) : value_(value)
508 {
509 }
510
511 int GetValue() const
512 {
513 return value_;
514 }
515 };
516
517
518 TEST(SharedMessageQueue, Basic)
519 {
520 SharedMessageQueue q;
521 ASSERT_TRUE(q.WaitEmpty(0));
522 q.Enqueue(new DynamicInteger(10));
523 ASSERT_FALSE(q.WaitEmpty(1));
524 q.Enqueue(new DynamicInteger(20));
525 q.Enqueue(new DynamicInteger(30));
526 q.Enqueue(new DynamicInteger(40));
527
528 std::auto_ptr<DynamicInteger> i;
529 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue());
530 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue());
531 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue());
532 ASSERT_FALSE(q.WaitEmpty(1));
533 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue());
534 ASSERT_TRUE(q.WaitEmpty(0));
535 ASSERT_EQ(NULL, q.Dequeue(1));
536 }
537
538
539 TEST(SharedMessageQueue, Clean)
540 {
541 try
542 {
543 SharedMessageQueue q;
544 q.Enqueue(new DynamicInteger(10));
545 q.Enqueue(new DynamicInteger(20));
546 throw OrthancException("Nope");
547 }
548 catch (OrthancException&)
549 {
550 }
551 }
552
553
554 TEST(Toolbox, WriteFile) 500 TEST(Toolbox, WriteFile)
555 { 501 {
556 std::string path; 502 std::string path;
557 503
558 { 504 {