ctkDicomObjectLocatorCacheTest1.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Qt includes
  2. #include <QUuid>
  3. // CTK includes
  4. #include <ctkDicomObjectLocatorCache.h>
  5. // STD includes
  6. #include <cstdlib>
  7. #include <iostream>
  8. //----------------------------------------------------------------------------
  9. int ctkDicomObjectLocatorCacheTest1(int argc, char* argv[])
  10. {
  11. Q_UNUSED(argc);
  12. Q_UNUSED(argv);
  13. ctkDicomObjectLocatorCache cache;
  14. //----------------------------------------------------------------------------
  15. if (cache.remove(""))
  16. {
  17. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  18. return EXIT_FAILURE;
  19. }
  20. //----------------------------------------------------------------------------
  21. QString objectUuid = QUuid::createUuid();
  22. ctkDicomAppHosting::ObjectLocator objectLocator;
  23. objectLocator.length = 64;
  24. objectLocator.source = "/path/to/source";
  25. ctkDicomAppHosting::ObjectLocator objectLocatorFound;
  26. if (cache.find(objectUuid, objectLocatorFound))
  27. {
  28. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  29. return EXIT_FAILURE;
  30. }
  31. cache.insert(objectUuid, objectLocator);
  32. //----------------------------------------------------------------------------
  33. if (!cache.find(objectUuid, objectLocatorFound))
  34. {
  35. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  36. return EXIT_FAILURE;
  37. }
  38. if (objectLocator != objectLocatorFound)
  39. {
  40. std::cerr << "Line " << __LINE__ << " - Problem with find() method"
  41. << " - objectLocator != objectLocatorFound" << std::endl;
  42. return EXIT_FAILURE;
  43. }
  44. //----------------------------------------------------------------------------
  45. if (!cache.remove(objectUuid))
  46. {
  47. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  48. return EXIT_FAILURE;
  49. }
  50. //----------------------------------------------------------------------------
  51. cache.insert(objectUuid, objectLocator);
  52. cache.insert(objectUuid, objectLocator);
  53. cache.insert(objectUuid, objectLocator);
  54. // Since the Reference count associated with the objectLocator is equal to three,
  55. // after two successive call of "remove()", the objectLocator should still be in the cache.
  56. // First call to "remove()"
  57. if (!cache.remove(objectUuid))
  58. {
  59. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  60. return EXIT_FAILURE;
  61. }
  62. ctkDicomAppHosting::ObjectLocator objectLocatorFound2;
  63. if (!cache.find(objectUuid, objectLocatorFound2))
  64. {
  65. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  66. return EXIT_FAILURE;
  67. }
  68. if (objectLocator != objectLocatorFound2)
  69. {
  70. std::cerr << "Line " << __LINE__ << " - Problem with find() method"
  71. << " - objectLocator != objectLocatorFound" << std::endl;
  72. return EXIT_FAILURE;
  73. }
  74. // Second call to "remove()"
  75. if (!cache.remove(objectUuid))
  76. {
  77. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  78. return EXIT_FAILURE;
  79. }
  80. ctkDicomAppHosting::ObjectLocator objectLocatorFound3;
  81. if (!cache.find(objectUuid, objectLocatorFound3))
  82. {
  83. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  84. return EXIT_FAILURE;
  85. }
  86. if (objectLocator != objectLocatorFound3)
  87. {
  88. std::cerr << "Line " << __LINE__ << " - Problem with find() method"
  89. << " - objectLocator != objectLocatorFound" << std::endl;
  90. return EXIT_FAILURE;
  91. }
  92. // Third call to "remove()"
  93. if (!cache.remove(objectUuid))
  94. {
  95. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  96. return EXIT_FAILURE;
  97. }
  98. ctkDicomAppHosting::ObjectLocator objectLocatorFound4;
  99. if (cache.find(objectUuid, objectLocatorFound4))
  100. {
  101. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  102. return EXIT_FAILURE;
  103. }
  104. // Fourth call to "remove()"
  105. if (cache.remove(objectUuid))
  106. {
  107. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  108. return EXIT_FAILURE;
  109. }
  110. //----------------------------------------------------------------------------
  111. ctkDicomAppHosting::AvailableData availableData;
  112. if (cache.isCached(availableData))
  113. {
  114. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  115. return EXIT_FAILURE;
  116. }
  117. ctkDicomAppHosting::Patient patient;
  118. availableData.patients << patient;
  119. if (cache.isCached(availableData))
  120. {
  121. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  122. return EXIT_FAILURE;
  123. }
  124. ctkDicomAppHosting::ObjectDescriptor objectDescriptor;
  125. objectDescriptor.descriptorUUID = objectUuid;
  126. availableData.objectDescriptors << objectDescriptor;
  127. if (cache.isCached(availableData))
  128. {
  129. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  130. return EXIT_FAILURE;
  131. }
  132. cache.insert(objectUuid, objectLocator);
  133. if (!cache.isCached(availableData))
  134. {
  135. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  136. return EXIT_FAILURE;
  137. }
  138. QString objectUuid2 = QUuid::createUuid();
  139. ctkDicomAppHosting::ObjectDescriptor objectDescriptor2;
  140. objectDescriptor2.descriptorUUID = objectUuid2;
  141. ctkDicomAppHosting::ObjectLocator objectLocator2;
  142. objectLocator2.length = 50;
  143. objectLocator2.source = "/path/to/source2";
  144. availableData.objectDescriptors << objectDescriptor2;
  145. if (cache.isCached(availableData))
  146. {
  147. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  148. return EXIT_FAILURE;
  149. }
  150. cache.insert(objectUuid2, objectLocator2);
  151. if (!cache.isCached(availableData))
  152. {
  153. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  154. return EXIT_FAILURE;
  155. }
  156. return EXIT_SUCCESS;
  157. }