changeset 1725:c8d0ffb3047d

DicomSource::IsSameSource()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 01 Dec 2020 17:43:31 +0100
parents 7b17090ed2ab
children 0257339b0884
files OrthancStone/Sources/Loaders/DicomSource.cpp OrthancStone/Sources/Loaders/DicomSource.h UnitTestsSources/DicomTests.cpp
diffstat 3 files changed, 158 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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_;
--- 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 <gtest/gtest.h>
 
 #include "../OrthancStone/Sources/Toolbox/DicomInstanceParameters.h"
+#include "../OrthancStone/Sources/Loaders/DicomSource.h"
 
 #include <OrthancException.h>
 
@@ -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));
+    }
+  }
+}