# HG changeset patch # User Sebastien Jodogne # Date 1606841011 -3600 # Node ID c8d0ffb3047d5b2bac4b9a84378e3e12e0cc060b # Parent 7b17090ed2ab7f78965f9672fdcb805dc2872dbc DicomSource::IsSameSource() diff -r 7b17090ed2ab -r c8d0ffb3047d OrthancStone/Sources/Loaders/DicomSource.cpp --- a/OrthancStone/Sources/Loaders/DicomSource.cpp Tue Dec 01 17:07:32 2020 +0100 +++ b/OrthancStone/Sources/Loaders/DicomSource.cpp Tue Dec 01 17:43:31 2020 +0100 @@ -68,6 +68,47 @@ } + bool DicomSource::IsSameSource(const DicomSource& other) const + { + if (type_ != other.type_) + { + return false; + } + else + { + switch (type_) + { + case DicomSourceType_Orthanc: + return (webService_.GetUrl() == other.webService_.GetUrl() && + webService_.GetUsername() == other.webService_.GetUsername() && + webService_.GetHttpHeaders() == other.webService_.GetHttpHeaders() && + hasOrthancWebViewer1_ == other.hasOrthancWebViewer1_ && + hasOrthancAdvancedPreview_ == other.hasOrthancAdvancedPreview_); + + case DicomSourceType_DicomWeb: + return (webService_.GetUrl() == other.webService_.GetUrl() && + webService_.GetUsername() == other.webService_.GetUsername() && + webService_.GetHttpHeaders() == other.webService_.GetHttpHeaders() && + hasDicomWebRendered_ == other.hasDicomWebRendered_); + + case DicomSourceType_DicomWebThroughOrthanc: + return (webService_.GetUrl() == other.webService_.GetUrl() && + webService_.GetUsername() == other.webService_.GetUsername() && + webService_.GetHttpHeaders() == other.webService_.GetHttpHeaders() && + orthancDicomWebRoot_ == other.orthancDicomWebRoot_ && + serverName_ == other.serverName_ && + hasDicomWebRendered_ == other.hasDicomWebRendered_); + + case DicomSourceType_DicomDir: + return true; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + } + } + + void DicomSource::SetOrthancSource() { Orthanc::WebServiceParameters parameters; diff -r 7b17090ed2ab -r c8d0ffb3047d OrthancStone/Sources/Loaders/DicomSource.h --- a/OrthancStone/Sources/Loaders/DicomSource.h Tue Dec 01 17:07:32 2020 +0100 +++ b/OrthancStone/Sources/Loaders/DicomSource.h Tue Dec 01 17:43:31 2020 +0100 @@ -57,6 +57,9 @@ SetOrthancSource(); } + // Makes a rough comparison to test whether these two sources match + bool IsSameSource(const DicomSource& other) const; + DicomSourceType GetType() const { return type_; diff -r 7b17090ed2ab -r c8d0ffb3047d UnitTestsSources/DicomTests.cpp --- a/UnitTestsSources/DicomTests.cpp Tue Dec 01 17:07:32 2020 +0100 +++ b/UnitTestsSources/DicomTests.cpp Tue Dec 01 17:43:31 2020 +0100 @@ -22,6 +22,7 @@ #include #include "../OrthancStone/Sources/Toolbox/DicomInstanceParameters.h" +#include "../OrthancStone/Sources/Loaders/DicomSource.h" #include @@ -107,3 +108,116 @@ ASSERT_FLOAT_EQ((a + b) / 2.0f, c); ASSERT_FLOAT_EQ(b - a, w); } + + +TEST(DicomSource, Equality) +{ + { + OrthancStone::DicomSource s1; + + { + OrthancStone::DicomSource s2; + ASSERT_TRUE(s1.IsSameSource(s2)); + + s2.SetDicomDirSource(); + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomWebSource("toto"); + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomWebThroughOrthancSource("toto"); + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetOrthancSource(); + ASSERT_TRUE(s1.IsSameSource(s2)); + } + } + + { + OrthancStone::DicomSource s1; + + { + Orthanc::WebServiceParameters p; + p.SetUrl("http://localhost:8042/"); + + OrthancStone::DicomSource s2; + s2.SetOrthancSource(p); + ASSERT_TRUE(s1.IsSameSource(s2)); + + p.SetCredentials("toto", "tutu"); + s2.SetOrthancSource(p); + ASSERT_FALSE(s1.IsSameSource(s2)); + + p.ClearCredentials(); + s2.SetOrthancSource(p); + ASSERT_TRUE(s1.IsSameSource(s2)); + + p.SetUrl("http://localhost:8043/"); + s2.SetOrthancSource(p); + ASSERT_FALSE(s1.IsSameSource(s2)); + } + } + + { + OrthancStone::DicomSource s1; + s1.SetDicomDirSource(); + + { + OrthancStone::DicomSource s2; + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomDirSource(); + ASSERT_TRUE(s1.IsSameSource(s2)); + + s2.SetDicomWebSource("toto"); + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomWebThroughOrthancSource("toto"); + ASSERT_FALSE(s1.IsSameSource(s2)); + } + } + + { + OrthancStone::DicomSource s1; + s1.SetDicomWebSource("http"); + + { + OrthancStone::DicomSource s2; + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomDirSource(); + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomWebSource("http"); + ASSERT_TRUE(s1.IsSameSource(s2)); + + s2.SetDicomWebSource("http2"); + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomWebThroughOrthancSource("toto"); + ASSERT_FALSE(s1.IsSameSource(s2)); + } + } + + { + OrthancStone::DicomSource s1; + s1.SetDicomWebThroughOrthancSource("server"); + + { + OrthancStone::DicomSource s2; + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomDirSource(); + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomWebSource("http"); + ASSERT_FALSE(s1.IsSameSource(s2)); + + s2.SetDicomWebThroughOrthancSource("server"); + ASSERT_TRUE(s1.IsSameSource(s2)); + + s2.SetDicomWebThroughOrthancSource("server2"); + ASSERT_FALSE(s1.IsSameSource(s2)); + } + } +}