Mercurial > hg > orthanc
diff OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 4735:e17fdc43ef6c
optimized version of DicomPath::IsMatch()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 05 Jul 2021 17:03:46 +0200 |
parents | b51c08bd5c38 |
children | bf852fd773b7 |
line wrap: on
line diff
--- a/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp Mon Jul 05 16:12:10 2021 +0200 +++ b/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp Mon Jul 05 17:03:46 2021 +0200 @@ -2261,6 +2261,31 @@ } +static bool MyIsMatch(const DicomPath& a, + const DicomPath& b) +{ + bool expected = DicomPath::IsMatch(a, b); + + std::vector<DicomTag> prefixTags; + std::vector<size_t> prefixIndexes; + + for (size_t i = 0; i < b.GetPrefixLength(); i++) + { + prefixTags.push_back(b.GetPrefixTag(i)); + prefixIndexes.push_back(b.GetPrefixIndex(i)); + } + + if (expected == DicomPath::IsMatch(a, prefixTags, prefixIndexes, b.GetFinalTag())) + { + return expected; + } + else + { + throw OrthancException(ErrorCode_InternalError); + } +} + + TEST(DicomModification, DicomPath) { // Those are samples inspired by those from "man dcmodify" @@ -2366,30 +2391,30 @@ ASSERT_THROW(DicomPath::Parse("(0010,0010)0].PatientID"), OrthancException); ASSERT_THROW(DicomPath::Parse("(0010,0010)[-1].PatientID"), OrthancException); - ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)"), - DicomPath::Parse("(0010,0010)"))); - ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)"), - DicomPath::Parse("(0010,0020)"))); - ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)"), - DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); - ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), - DicomPath::Parse("(0010,0010)"))); - ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), - DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); - ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[*].(0010,0020)"), - DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); - ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[2].(0010,0020)"), - DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); - ASSERT_THROW(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), - DicomPath::Parse("(0010,0010)[*].(0010,0020)")), OrthancException); - ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[*].(0010,0020)[*].(0010,0030)"), - DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); - ASSERT_TRUE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)"), - DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); - ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)[3].(0010,0030)"), - DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); - ASSERT_FALSE(DicomPath::IsMatch(DicomPath::Parse("(0010,0010)[2].(0010,0020)[2].(0010,0030)"), - DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); + ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)"), + DicomPath::Parse("(0010,0010)"))); + ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)"), + DicomPath::Parse("(0010,0020)"))); + ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)"), + DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); + ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), + DicomPath::Parse("(0010,0010)"))); + ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), + DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); + ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)[*].(0010,0020)"), + DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); + ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)[2].(0010,0020)"), + DicomPath::Parse("(0010,0010)[1].(0010,0020)"))); + ASSERT_THROW(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)"), + DicomPath::Parse("(0010,0010)[*].(0010,0020)")), OrthancException); + ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)[*].(0010,0020)[*].(0010,0030)"), + DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); + ASSERT_TRUE(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)"), + DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); + ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)[1].(0010,0020)[3].(0010,0030)"), + DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); + ASSERT_FALSE(MyIsMatch(DicomPath::Parse("(0010,0010)[2].(0010,0020)[2].(0010,0030)"), + DicomPath::Parse("(0010,0010)[1].(0010,0020)[2].(0010,0030)[3].(0010,0040)"))); }