Skip to content
Snippets Groups Projects
Commit 331fba7a authored by janwych's avatar janwych
Browse files

getWithoutCallback, internal cache, fillVector

git-svn-id: https://svnsrv.desy.de/desy/mtca4u_applications/DOOCS_Adapter/trunk@57 688d77b5-b833-4f6b-b27f-eb88d88625d6
parent 4c016d51
No related branches found
No related tags found
No related merge requests found
......@@ -161,12 +161,15 @@ public:
std::vector<T> const & getWithoutCallback()
{
//~ if (_onGetCallbackFunction){
//~ _onGetCallbackFunction(*this);
//~ }
//~ return _container;
throw std::logic_error("\"get\" - The method or operation is not implemented.");
//~ return m4uD_array_T->read_whole_spectrum_without_callback();
return m4uD_array_T->read_whole_spectrum_without_callback();
}
void fillVector(std::vector <T> & toBeFilled)
{
if (toBeFilled.size() != size()){
throw std::out_of_range("Assigned vector size mismatch.");
}
m4uD_array_T->fillVector(toBeFilled);
}
virtual float & operator[](size_t index){
......
......@@ -138,6 +138,14 @@ public:
return _cache;
}
void fillVector(std::vector <T> & toBeFilled)
{
sync_cache();
std::copy(_cache.begin(), _cache.end(), toBeFilled.begin());
}
};
......
......@@ -27,11 +27,14 @@ public:
typedef std::vector<float> const & CVRef;
typedef std::vector<float> Vectorf;
struct TestFixture {
size_t const N_ELEMENTS;
float const G_FILL_VALUE; // for gCALLBACK
//~ size_t const SOME_NUMBER; // just some number to add so the content if not equal to the index
std::vector<float> referenceVector;
std::vector<float> toolarge_referenceVector;
......@@ -396,41 +399,59 @@ BOOST_FIXTURE_TEST_CASE( testSet, TestFixture )
//~ BOOST_FIXTURE_TEST_CASE( testGetWithoutCallback, TestFixture )
//~ {
//~ // fill something known so we can check that it changed
//~ _process_array.fill(5);
//~
//~
//~ std::vector<T> const & theGetResult = _stubProcessArray.getWithoutCallback();
//~ BOOST_CHECK( __getCallbackCounter == 1 );
//~ // the get should have changed everything to SOME_NUMBER
//~ for( typename ProcessArray<T>::const_iterator it = _process_array.cbegin();
//~ it != _process_array.cend(); ++it ){
//~ BOOST_CHECK( *it == static_cast<T>(SOME_NUMBER) );
//~ }
//~ // the get should have changed everything to SOME_NUMBER
//~ for( typename std::vector<T>::const_iterator it = theGetResult.begin();
//~ it != theGetResult.end(); ++it ){
//~ BOOST_CHECK( *it == static_cast<T>(SOME_NUMBER) );
//~ }
BOOST_FIXTURE_TEST_CASE( testGetWithoutCallback, TestFixture )
{
// fill something known so we can check that it changed
_process_array.fill(5);
CVRef result_of_get = doocs_process_array.getWithoutCallback();
for (size_t i=0; i<N_ELEMENTS; ++i)
{
BOOST_CHECK_EQUAL( result_of_get[i], darray->read_spectrum ((int)i));
}
//~ _process_array.fill(4);
//~ result_of_get = _process_array.getWithoutCallback(); FIXME: class mtca4u::ProcessArray<float>’ has no member named ‘getWithoutCallback'
//~
//~ // clear the getter callback function
//~ _process_array.clearOnGetCallbackFunction();
//~ _process_array.fill(5);
//~
//~ std::vector<T> const & anotherGetResult = _stubProcessArray.getWithoutCallback();
//~ BOOST_CHECK( __getCallbackCounter == 1 );
//~ // everything still has to be 5
//~ for( typename ProcessArray<T>::const_iterator it = _process_array.cbegin();
//~ it != _process_array.cend(); ++it ){
//~ BOOST_CHECK( *it == 5 );
//~ }
//~ for( typename std::vector<T>::const_iterator it = anotherGetResult.begin();
//~ it != anotherGetResult.end(); ++it ){
//~ BOOST_CHECK( *it == 5 );
//~ }
//~ }
//~ for (size_t i=0; i<N_ELEMENTS; ++i)
//~ {
//~ BOOST_CHECK_EQUAL( result_of_get[i], darray->read_spectrum ((int)i));
//~ }
// FIXME: assign_test_reference_process_array?
BOOST_CHECK_EQUAL( __setCallbackCounter, 0 );
BOOST_CHECK_EQUAL( __getCallbackCounter, 0 );
}
BOOST_FIXTURE_TEST_CASE( test_fillvector, TestFixture )
{
_process_array = referenceVector;
Vectorf v(N_ELEMENTS);
doocs_process_array.fillVector(v);
for (size_t i=0; i<N_ELEMENTS; ++i)
{
BOOST_CHECK_EQUAL( v[i], referenceVector[i] );
}
// toolarges
BOOST_CHECK_THROW( doocs_process_array.fillVector( toolarge_referenceVector ), std::out_of_range );
BOOST_CHECK_EQUAL( __setCallbackCounter, 0 );
BOOST_CHECK_EQUAL( __getCallbackCounter, 0 );
}
BOOST_FIXTURE_TEST_CASE( testAssignment, TestFixture )
......
......@@ -17,6 +17,9 @@ using namespace boost::unit_test;
// ============================================================================
typedef std::vector<float> Vectorf;
struct CallbacksTestFixture {
mtca4u::m4uD_array<float> mydarray;
......@@ -269,6 +272,11 @@ BOOST_FIXTURE_TEST_SUITE( test_operation, CallbacksTestFixture ) // operation ch
Vectorf v(4);
mydarray.fillVector(v);
BOOST_CHECK_EQUAL(mydarray.__is_cache_synced_flag(), true);
BOOST_CHECK_EQUAL(mydarray.__is_cache_synced_vect(), true);
// FIXME: a series for callbacks presence advised?
/*
// vec_test = [0,0,0,0]
......@@ -353,6 +361,19 @@ BOOST_FIXTURE_TEST_SUITE( test_operation, CallbacksTestFixture ) // operation ch
}
BOOST_AUTO_TEST_CASE( test_fillvector )
{
// vec_test = [1,1,1,1]
vec_test.assign(4, 1.0);
mydarray.fill_whole_spectrum(vec_test, pa);
Vectorf v(4);
mydarray.fillVector(v);
BOOST_CHECK_EQUAL_COLLECTIONS(v.begin(), v.end(), vec_test.begin(), vec_test.end());
}
BOOST_AUTO_TEST_SUITE_END()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment