// Qt includes #include // CTK includes #include // STD includes #include #include //---------------------------------------------------------------------------- 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; }