From 06fe754032289be87e4a7303e5470a478a8775fa Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Thu, 19 Oct 2017 14:02:04 +0200
Subject: [PATCH] prepared tests for array start and increment. Currently
 failing due to missing implementation

---
 tests/include/serverBasedTestTools.h  | 22 ++++++++++++++++++++++
 tests/src/serverTestSpectrumArray.cpp |  8 ++++++++
 2 files changed, 30 insertions(+)

diff --git a/tests/include/serverBasedTestTools.h b/tests/include/serverBasedTestTools.h
index 755f085..98fa9c2 100644
--- a/tests/include/serverBasedTestTools.h
+++ b/tests/include/serverBasedTestTools.h
@@ -52,4 +52,26 @@ void checkDoocsProperty(std::string const & propertyAddress, bool expected_has_h
   }
 }
 
+void checkSpectrum(std::string const & propertyAddress, bool expected_has_history =  true, bool expected_is_writeable =true, float expected_start = 0.0, float expected_increment = 1.0){
+  checkDoocsProperty<D_spectrum>(propertyAddress, expected_has_history, expected_is_writeable);
+
+  EqAdr ad;
+  EqData ed, res;
+  // obtain location pointer
+  ad.adr(propertyAddress.c_str());
+  EqFct *eqFct = eq_get(&ad);
+  BOOST_REQUIRE_MESSAGE( eqFct, "Could not get location for property "+propertyAddress);
+
+  auto propertyName = ChimeraTK::basenameFromAddress(propertyAddress);
+  D_spectrum * spectrum = dynamic_cast< D_spectrum *>(eqFct->find_property(propertyName));
+  BOOST_REQUIRE_MESSAGE(spectrum, "Could not find property " + propertyName + " (address "<< propertyAddress <<"), or property has unexpected type.");
+
+  std::cout << "The magic 4 " << spectrum->spec_time() << ", "
+            << spectrum->spec_start() << ", "
+            << spectrum->spec_inc() << ", "
+            << spectrum->spec_status() << std::endl;
+  BOOST_CHECK( std::fabs(spectrum->spec_start() - expected_start) < 0.001 );
+  BOOST_CHECK( std::fabs(spectrum->spec_inc() - expected_increment) < 0.001 );
+}
+
 #endif // SERVER_BASED_TEST_TOOLS_H
diff --git a/tests/src/serverTestSpectrumArray.cpp b/tests/src/serverTestSpectrumArray.cpp
index 615c8f0..d7d40ba 100644
--- a/tests/src/serverTestSpectrumArray.cpp
+++ b/tests/src/serverTestSpectrumArray.cpp
@@ -6,6 +6,7 @@
 #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h>
 #include <doocs-server-test-helper/doocsServerTestHelper.h>
 #include <thread>
+#include "serverBasedTestTools.h"
 
 ReferenceTestApplication referenceTestApplication("serverTestSpectrumArray");
 
@@ -35,6 +36,13 @@ void testReadWrite(){
   DoocsServerTestHelper::runUpdate();
   std::cout << "ran update once, let's test " << std::endl;
 
+  checkSpectrum("//INT/TO_DEVICE_ARRAY");
+  checkSpectrum("//DOUBLE/TO_DEVICE_ARRAY");
+  checkSpectrum("//FLOAT/TO_DEVICE_ARRAY");
+  checkSpectrum("//INT/MY_RENAMED_INTARRAY",true, false);
+  checkSpectrum("//DOUBLE/FROM_DEVICE_ARRAY",true, false, 123., 0.56);
+  checkSpectrum("//FLOAT/FROM_DEVICE_ARRAY",true, false);
+  
   DoocsServerTestHelper::doocsSetSpectrum("//INT/TO_DEVICE_ARRAY", {140, 141, 142, 143, 144, 145, 146, 147, 148, 149} ); 
   DoocsServerTestHelper::doocsSetSpectrum("//DOUBLE/TO_DEVICE_ARRAY", {240.3, 241.3, 242.3, 243.3, 244.3, 245.3, 246.3, 247.3, 248.3, 249.3} ); 
   
-- 
GitLab