From 8216b8fe1940ddc8c5a659b6e8370c5f027bbb5c Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Wed, 18 Dec 2024 13:27:17 +0000
Subject: [PATCH] TEST: Test that interp/extrap settings are propagated to
 shadowvolume instances

---
 ...wovolume_cache.cc => test_shadowvolume.cc} | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 rename test/{test_shadwovolume_cache.cc => test_shadowvolume.cc} (58%)

diff --git a/test/test_shadwovolume_cache.cc b/test/test_shadowvolume.cc
similarity index 58%
rename from test/test_shadwovolume_cache.cc
rename to test/test_shadowvolume.cc
index 99277c2..5e4135b 100644
--- a/test/test_shadwovolume_cache.cc
+++ b/test/test_shadowvolume.cc
@@ -1,3 +1,4 @@
+#define EXPOSE_TREACHEROUS
 #include "newimage/newimageall.h"
 #include "utils/threading.h"
 #include <stdlib.h>
@@ -132,3 +133,56 @@ BOOST_FIXTURE_TEST_CASE(test_splinterp, F)
                 testvol[t].interpolate(5, 5, 5));
   }
 }
+
+// test that changes to interp/extrap settings on a
+// 4D volume are propagated to its ShadowVolume instances
+BOOST_FIXTURE_TEST_CASE(test_interp_settings_delegated, F)
+{
+  testvol.setinterpolationmethod(nearestneighbour);
+  testvol.setextrapolationmethod(mirror);
+  testvol.setpadvalue(12345);
+  testvol.setsplineorder(5);
+  testvol.setextrapolationvalidity(false, true, false);
+  for (int i = 0; i < tsz; i++) {
+    BOOST_CHECK(testvol[i].getinterpolationmethod() == nearestneighbour);
+    BOOST_CHECK(testvol[i].getextrapolationmethod() == mirror);
+    BOOST_CHECK(testvol[i].getpadvalue() == 12345);
+    BOOST_CHECK(testvol[i].getsplineorder() == 5);
+    std::vector<bool> expvalidity = {false, true, false};
+    BOOST_CHECK(testvol[i].getextrapolationvalidity() == expvalidity);
+  }
+
+  testvol.setinterpolationmethod(sinc);
+  testvol.setextrapolationmethod(periodic);
+  testvol.setpadvalue(54321);
+  testvol.setsplineorder(2);
+  testvol.setextrapolationvalidity(true, false, true);
+  for (int i = 0; i < tsz; i++) {
+    BOOST_CHECK(testvol[i].getinterpolationmethod() == sinc);
+    BOOST_CHECK(testvol[i].getextrapolationmethod() == periodic);
+    BOOST_CHECK(testvol[i].getpadvalue() == 54321);
+    BOOST_CHECK(testvol[i].getsplineorder() == 2);
+    std::vector<bool> expvalidity = {true, false, true};
+    BOOST_CHECK(testvol[i].getextrapolationvalidity() == expvalidity);
+  }
+
+  // Force the ShadowVolume cache to be cleared
+  testvol.setinterpolationmethod(spline);
+  testvol.invalidateSplines();
+
+  // make sure settings still the same
+  for (int i = 0; i < tsz; i++) {
+    BOOST_CHECK(testvol[i].getinterpolationmethod() == spline);
+    BOOST_CHECK(testvol[i].getextrapolationmethod() == periodic);
+    BOOST_CHECK(testvol[i].getpadvalue() == 54321);
+    BOOST_CHECK(testvol[i].getsplineorder() == 2);
+    std::vector<bool> expvalidity = {true, false, true};
+    BOOST_CHECK(testvol[i].getextrapolationvalidity() == expvalidity);
+  }
+
+  // Attempting to change settings
+  // on a SV should error
+  BOOST_CHECK_THROW(
+    testvol[0].setinterpolationmethod(trilinear),
+    NEWMAT::Exception);
+}
-- 
GitLab