Przeglądaj źródła

Add ctkDicomObjectLocatorCacheTest1

Jean-Christophe Fillion-Robin 14 lat temu
rodzic
commit
99392d3f48

+ 2 - 0
Plugins/org.commontk.dah.core/Testing/Cpp/CMakeLists.txt

@@ -2,6 +2,7 @@ SET(KIT ${PROJECT_NAME})
 
 CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cxx
   ctkDicomAppHostingTypesTest1.cpp
+  ctkDicomObjectLocatorCacheTest1.cpp
   )
 
 SET (TestsToRun ${Tests})
@@ -24,3 +25,4 @@ ENDMACRO( SIMPLE_TEST )
 #
 
 SIMPLE_TEST( ctkDicomAppHostingTypesTest1 )
+SIMPLE_TEST( ctkDicomObjectLocatorCacheTest1 )

+ 196 - 0
Plugins/org.commontk.dah.core/Testing/Cpp/ctkDicomObjectLocatorCacheTest1.cpp

@@ -0,0 +1,196 @@
+
+// Qt includes
+#include <QUuid>
+
+// CTK includes
+#include <ctkDicomObjectLocatorCache.h>
+
+// STD includes
+#include <cstdlib>
+#include <iostream>
+
+//----------------------------------------------------------------------------
+int ctkDicomObjectLocatorCacheTest1(int argc, char* argv[])
+{
+  Q_UNUSED(argc);
+  Q_UNUSED(argv);
+
+  ctkDicomObjectLocatorCache cache;
+
+  //----------------------------------------------------------------------------
+  if (cache.remove(""))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  //----------------------------------------------------------------------------
+  QString objectUuid = QUuid::createUuid();
+  ctkDicomAppHosting::ObjectLocator objectLocator;
+  objectLocator.length = 64;
+  objectLocator.source = "/path/to/source";
+
+  ctkDicomAppHosting::ObjectLocator objectLocatorFound;
+  if (cache.find(objectUuid, objectLocatorFound))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  cache.insert(objectUuid, objectLocator);
+
+  //----------------------------------------------------------------------------
+  if (!cache.find(objectUuid, objectLocatorFound))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  if (objectLocator != objectLocatorFound)
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with find() method"
+              << " - objectLocator != objectLocatorFound" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  //----------------------------------------------------------------------------
+  if (!cache.remove(objectUuid))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  //----------------------------------------------------------------------------
+  cache.insert(objectUuid, objectLocator);
+  cache.insert(objectUuid, objectLocator);
+  cache.insert(objectUuid, objectLocator);
+
+  // Since the Reference count associated with the objectLocator is equal to three,
+  // after two successive call of "remove()", the objectLocator should still be in the cache.
+
+  // First call to "remove()"
+  if (!cache.remove(objectUuid))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  ctkDicomAppHosting::ObjectLocator objectLocatorFound2;
+  if (!cache.find(objectUuid, objectLocatorFound2))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  if (objectLocator != objectLocatorFound2)
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with find() method"
+              << " - objectLocator != objectLocatorFound" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  // Second call to "remove()"
+  if (!cache.remove(objectUuid))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  ctkDicomAppHosting::ObjectLocator objectLocatorFound3;
+  if (!cache.find(objectUuid, objectLocatorFound3))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  if (objectLocator != objectLocatorFound3)
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with find() method"
+              << " - objectLocator != objectLocatorFound" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  // Third call to "remove()"
+  if (!cache.remove(objectUuid))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  ctkDicomAppHosting::ObjectLocator objectLocatorFound4;
+  if (cache.find(objectUuid, objectLocatorFound4))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with find() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  // Fourth call to "remove()"
+  if (cache.remove(objectUuid))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with remove() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  //----------------------------------------------------------------------------
+
+  ctkDicomAppHosting::AvailableData availableData;
+
+  if (cache.isCached(availableData))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  ctkDicomAppHosting::Patient patient;
+  availableData.patients << patient;
+
+  if (cache.isCached(availableData))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  ctkDicomAppHosting::ObjectDescriptor objectDescriptor;
+  objectDescriptor.descriptorUUID = objectUuid;
+
+  availableData.objectDescriptors << objectDescriptor;
+
+  if (cache.isCached(availableData))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  cache.insert(objectUuid, objectLocator);
+
+  if (!cache.isCached(availableData))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  QString objectUuid2 = QUuid::createUuid();
+  ctkDicomAppHosting::ObjectDescriptor objectDescriptor2;
+  objectDescriptor2.descriptorUUID = objectUuid2;
+  ctkDicomAppHosting::ObjectLocator objectLocator2;
+  objectLocator2.length = 50;
+  objectLocator2.source = "/path/to/source2";
+
+  availableData.objectDescriptors << objectDescriptor2;
+
+  if (cache.isCached(availableData))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  cache.insert(objectUuid2, objectLocator2);
+
+  if (!cache.isCached(availableData))
+    {
+    std::cerr << "Line " << __LINE__ << " - Problem with isCached() method" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  return EXIT_SUCCESS;
+}