ctkDicomObjectLocatorCacheTest1.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. // Qt includes
  16. #include <QUuid>
  17. // CTK includes
  18. #include <ctkDicomObjectLocatorCache.h>
  19. // STD includes
  20. #include <cstdlib>
  21. #include <iostream>
  22. //----------------------------------------------------------------------------
  23. int ctkDicomObjectLocatorCacheTest1(int argc, char* argv[])
  24. {
  25. Q_UNUSED(argc);
  26. Q_UNUSED(argv);
  27. ctkDicomObjectLocatorCache cache;
  28. //----------------------------------------------------------------------------
  29. if (cache.remove(""))
  30. {
  31. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  32. return EXIT_FAILURE;
  33. }
  34. //----------------------------------------------------------------------------
  35. QString objectUuid = QUuid::createUuid();
  36. ctkDicomAppHosting::ObjectLocator objectLocator;
  37. objectLocator.length = 64;
  38. objectLocator.source = "/path/to/source";
  39. ctkDicomAppHosting::ObjectLocator objectLocatorFound;
  40. if (cache.find(objectUuid, objectLocatorFound))
  41. {
  42. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  43. return EXIT_FAILURE;
  44. }
  45. cache.insert(objectUuid, objectLocator);
  46. //----------------------------------------------------------------------------
  47. if (!cache.find(objectUuid, objectLocatorFound))
  48. {
  49. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. if (objectLocator != objectLocatorFound)
  53. {
  54. std::cerr << "Line " << __LINE__ << " - Problem with find() method"
  55. << " - objectLocator != objectLocatorFound" << std::endl;
  56. return EXIT_FAILURE;
  57. }
  58. //----------------------------------------------------------------------------
  59. if (!cache.remove(objectUuid))
  60. {
  61. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  62. return EXIT_FAILURE;
  63. }
  64. //----------------------------------------------------------------------------
  65. cache.insert(objectUuid, objectLocator);
  66. cache.insert(objectUuid, objectLocator);
  67. cache.insert(objectUuid, objectLocator);
  68. // Since the Reference count associated with the objectLocator is equal to three,
  69. // after two successive call of "remove()", the objectLocator should still be in the cache.
  70. // First call to "remove()"
  71. if (!cache.remove(objectUuid))
  72. {
  73. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  74. return EXIT_FAILURE;
  75. }
  76. ctkDicomAppHosting::ObjectLocator objectLocatorFound2;
  77. if (!cache.find(objectUuid, objectLocatorFound2))
  78. {
  79. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  80. return EXIT_FAILURE;
  81. }
  82. if (objectLocator != objectLocatorFound2)
  83. {
  84. std::cerr << "Line " << __LINE__ << " - Problem with find() method"
  85. << " - objectLocator != objectLocatorFound" << std::endl;
  86. return EXIT_FAILURE;
  87. }
  88. // Second call to "remove()"
  89. if (!cache.remove(objectUuid))
  90. {
  91. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  92. return EXIT_FAILURE;
  93. }
  94. ctkDicomAppHosting::ObjectLocator objectLocatorFound3;
  95. if (!cache.find(objectUuid, objectLocatorFound3))
  96. {
  97. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  98. return EXIT_FAILURE;
  99. }
  100. if (objectLocator != objectLocatorFound3)
  101. {
  102. std::cerr << "Line " << __LINE__ << " - Problem with find() method"
  103. << " - objectLocator != objectLocatorFound" << std::endl;
  104. return EXIT_FAILURE;
  105. }
  106. // Third call to "remove()"
  107. if (!cache.remove(objectUuid))
  108. {
  109. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  110. return EXIT_FAILURE;
  111. }
  112. ctkDicomAppHosting::ObjectLocator objectLocatorFound4;
  113. if (cache.find(objectUuid, objectLocatorFound4))
  114. {
  115. std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
  116. return EXIT_FAILURE;
  117. }
  118. // Fourth call to "remove()"
  119. if (cache.remove(objectUuid))
  120. {
  121. std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
  122. return EXIT_FAILURE;
  123. }
  124. //----------------------------------------------------------------------------
  125. ctkDicomAppHosting::AvailableData availableData;
  126. if (cache.isCached(availableData))
  127. {
  128. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  129. return EXIT_FAILURE;
  130. }
  131. ctkDicomAppHosting::Patient patient;
  132. availableData.patients << patient;
  133. if (cache.isCached(availableData))
  134. {
  135. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  136. return EXIT_FAILURE;
  137. }
  138. ctkDicomAppHosting::ObjectDescriptor objectDescriptor;
  139. objectDescriptor.descriptorUUID = objectUuid;
  140. availableData.objectDescriptors << objectDescriptor;
  141. if (cache.isCached(availableData))
  142. {
  143. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  144. return EXIT_FAILURE;
  145. }
  146. cache.insert(objectUuid, objectLocator);
  147. if (!cache.isCached(availableData))
  148. {
  149. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  150. return EXIT_FAILURE;
  151. }
  152. QString objectUuid2 = QUuid::createUuid();
  153. ctkDicomAppHosting::ObjectDescriptor objectDescriptor2;
  154. objectDescriptor2.descriptorUUID = objectUuid2;
  155. ctkDicomAppHosting::ObjectLocator objectLocator2;
  156. objectLocator2.length = 50;
  157. objectLocator2.source = "/path/to/source2";
  158. availableData.objectDescriptors << objectDescriptor2;
  159. if (cache.isCached(availableData))
  160. {
  161. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  162. return EXIT_FAILURE;
  163. }
  164. cache.insert(objectUuid2, objectLocator2);
  165. if (!cache.isCached(availableData))
  166. {
  167. std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
  168. return EXIT_FAILURE;
  169. }
  170. return EXIT_SUCCESS;
  171. }