From 005922d6dc17499af81bbdb1c7ba4db7ce019ae1 Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Wed, 13 Aug 2014 09:02:31 +0000 Subject: [PATCH] - added new method to BitField64 void setValue(unsigned lowWord, unsigned highWord ) - added some simple unit tests for BitField64 --- .../include/DDSegmentation/BitField64.h | 7 ++ DDTest/CMakeLists.txt | 6 ++ DDTest/src/test_bitfield64.cc | 83 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 DDTest/src/test_bitfield64.cc diff --git a/DDSegmentation/include/DDSegmentation/BitField64.h b/DDSegmentation/include/DDSegmentation/BitField64.h index cc19a62ab..e5c3992cf 100644 --- a/DDSegmentation/include/DDSegmentation/BitField64.h +++ b/DDSegmentation/include/DDSegmentation/BitField64.h @@ -77,6 +77,13 @@ namespace DDSegmentation { /** Set a new 64bit value - bits not used in description are set to 0. */ void setValue(long64 value ) { _value = ( _joined & value ) ; } + + /** Set a new 64bit value given as high and low 32bit words. + */ + void setValue(unsigned lowWord, unsigned highWord ) { + + setValue( ( lowWord & 0xffffffffUL ) | ( ( highWord & 0xffffffffUL ) << 32 ) ) ; + } /** Operator for setting a new value and accessing the BitField directly */ BitField64& operator()(long64 val) { setValue( val ) ; return *this ; } diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt index 85b3c8927..ce6c4dcf1 100644 --- a/DDTest/CMakeLists.txt +++ b/DDTest/CMakeLists.txt @@ -43,6 +43,12 @@ ADD_TEST( t_${test_name} "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh" SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "TEST_PASSED" ) SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED" ) +SET( test_name "test_bitfield64" ) +ADD_EXECUTABLE( ${test_name} ./src/${test_name}.cc ) +ADD_TEST( t_${test_name} "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh" + ${EXECUTABLE_OUTPUT_PATH}/${test_name} ${CMAKE_CURRENT_SOURCE_DIR}/units.xml ) +SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "TEST_PASSED" ) +SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED" ) #-------------------------------------------------- diff --git a/DDTest/src/test_bitfield64.cc b/DDTest/src/test_bitfield64.cc new file mode 100644 index 000000000..4a8aff5d1 --- /dev/null +++ b/DDTest/src/test_bitfield64.cc @@ -0,0 +1,83 @@ +#include "DD4hep/DDTest.h" +#include <exception> +#include <iostream> +#include <assert.h> +#include <cmath> + +#include "DDSegmentation/BitField64.h" + + +using namespace std ; +using namespace DD4hep ; +using namespace DDSegmentation ; + +// this should be the first line in your test +DDTest test = DDTest( "bitfield64" ) ; + +//============================================================================= + +int main(int argc, char** argv ){ + + try{ + + // ----- write your tests in here ------------------------------------- + + test.log( "test bitfield64" ); + + + // initialize with a string that uses all 64 bits : + BitField64 bf("system:5,side:-2,layer:9,module:8,sensor:8,x:32:-16,y:-16" ) ; + + BitField64 bf2( bf.fieldDescription() ) ; + BitField64 bf3( bf.fieldDescription() ) ; + + + test( bf.getValue() , 0UL , " initialized with 0 " ); + + // std::cout << " bf value : " << bf << std::endl ; + + bf.setValue( 0xbebafecacafebabe ) ; + + // std::cout << " bf value : " << bf << std::endl ; + + test( bf.getValue() , long64( 0xbebafecacafebabeUL ) , + " initialized with 0xbebafecacafebabeUL - compare as signed " ); + + test( (unsigned long) bf.getValue() , 0xbebafecacafebabeUL , + " initialized with 0xbebafecacafebabeUL - compare as unsigned " ); + + + // set some 'random' values to bf2 + + bf2["layer"] = 373 ; + bf2["module"] = 254 ; + bf2["sensor"] = 202 ; + bf2["side"] = 1 ; + bf2["system"] = 30 ; + bf2["x"] = -310 ; + bf2["y"] = -16710 ; + + + test( bf.getValue() , bf2.getValue() , " same value 0xbebafecacafebabeUL from individual initialization " ); + + // check for setting high and low words indiviually : + + bf3.setValue( bf.lowWord() , bf.highWord() ) ; + + test( bf3.getValue() , bf2.getValue() , " same value 0xbebafecacafebabeUL from stting low and hiigh word " ); + + + // -------------------------------------------------------------------- + + + } catch( exception &e ){ + //} catch( ... ){ + + test.log( e.what() ); + test.error( "exception occurred" ); + } + + return 0; +} + +//============================================================================= -- GitLab