Mercurial > hg > orthanc
diff UnitTestsSources/ServerIndexTests.cpp @ 1763:f7014cca73c7
integration db-changes->mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Oct 2015 12:45:20 +0100 |
parents | ca69082ab200 |
children | 9ead18ef460a |
line wrap: on
line diff
--- a/UnitTestsSources/ServerIndexTests.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Thu Oct 29 12:45:20 2015 +0100 @@ -39,6 +39,7 @@ #include "../OrthancServer/DatabaseWrapper.h" #include "../OrthancServer/ServerContext.h" #include "../OrthancServer/ServerIndex.h" +#include "../OrthancServer/Search/LookupIdentifierQuery.h" #include <ctype.h> #include <algorithm> @@ -245,6 +246,18 @@ throw OrthancException(ErrorCode_InternalError); } } + + + void DoLookup(std::list<std::string>& result, + ResourceType level, + const DicomTag& tag, + const std::string& value) + { + LookupIdentifierQuery query(level); + query.AddConstraint(tag, IdentifierConstraintType_Equal, value); + query.Apply(result, *index_); + } + }; } @@ -690,36 +703,64 @@ index_->SetIdentifierTag(a[2], DICOM_TAG_STUDY_INSTANCE_UID, "0"); index_->SetIdentifierTag(a[3], DICOM_TAG_SERIES_INSTANCE_UID, "0"); - std::list<int64_t> s; + std::list<std::string> s; - index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "0"); + DoLookup(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, "0"); ASSERT_EQ(2u, s.size()); - ASSERT_TRUE(std::find(s.begin(), s.end(), a[0]) != s.end()); - ASSERT_TRUE(std::find(s.begin(), s.end(), a[2]) != s.end()); + ASSERT_TRUE(std::find(s.begin(), s.end(), "a") != s.end()); + ASSERT_TRUE(std::find(s.begin(), s.end(), "c") != s.end()); - index_->LookupIdentifier(s, DICOM_TAG_SERIES_INSTANCE_UID, "0"); + DoLookup(s, ResourceType_Series, DICOM_TAG_SERIES_INSTANCE_UID, "0"); ASSERT_EQ(1u, s.size()); - ASSERT_TRUE(std::find(s.begin(), s.end(), a[3]) != s.end()); + ASSERT_TRUE(std::find(s.begin(), s.end(), "d") != s.end()); - index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "1"); + DoLookup(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, "1"); ASSERT_EQ(1u, s.size()); - ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); + ASSERT_TRUE(std::find(s.begin(), s.end(), "b") != s.end()); - index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "1"); + DoLookup(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, "1"); ASSERT_EQ(1u, s.size()); - ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); + ASSERT_TRUE(std::find(s.begin(), s.end(), "b") != s.end()); - index_->LookupIdentifier(s, DICOM_TAG_SERIES_INSTANCE_UID, "1"); + DoLookup(s, ResourceType_Series, DICOM_TAG_SERIES_INSTANCE_UID, "1"); ASSERT_EQ(0u, s.size()); - /*{ - std::list<std::string> s; - context.GetIndex().LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "1.2.250.1.74.20130819132500.29000036381059"); - for (std::list<std::string>::iterator i = s.begin(); i != s.end(); i++) - { - std::cout << "*** " << *i << std::endl;; - } - }*/ + { + LookupIdentifierQuery query(ResourceType_Study); + query.AddConstraint(DICOM_TAG_STUDY_INSTANCE_UID, IdentifierConstraintType_GreaterOrEqual, "0"); + query.Apply(s, *index_); + ASSERT_EQ(3u, s.size()); + } + + { + LookupIdentifierQuery query(ResourceType_Study); + query.AddConstraint(DICOM_TAG_STUDY_INSTANCE_UID, IdentifierConstraintType_GreaterOrEqual, "0"); + query.AddConstraint(DICOM_TAG_STUDY_INSTANCE_UID, IdentifierConstraintType_SmallerOrEqual, "0"); + query.Apply(s, *index_); + ASSERT_EQ(2u, s.size()); + } + + { + LookupIdentifierQuery query(ResourceType_Study); + query.AddConstraint(DICOM_TAG_STUDY_INSTANCE_UID, IdentifierConstraintType_GreaterOrEqual, "1"); + query.AddConstraint(DICOM_TAG_STUDY_INSTANCE_UID, IdentifierConstraintType_SmallerOrEqual, "1"); + query.Apply(s, *index_); + ASSERT_EQ(1u, s.size()); + } + + { + LookupIdentifierQuery query(ResourceType_Study); + query.AddConstraint(DICOM_TAG_STUDY_INSTANCE_UID, IdentifierConstraintType_GreaterOrEqual, "1"); + query.Apply(s, *index_); + ASSERT_EQ(1u, s.size()); + } + + { + LookupIdentifierQuery query(ResourceType_Study); + query.AddConstraint(DICOM_TAG_STUDY_INSTANCE_UID, IdentifierConstraintType_GreaterOrEqual, "2"); + query.Apply(s, *index_); + ASSERT_EQ(0u, s.size()); + } }