Skip to content
Snippets Groups Projects
Commit 005922d6 authored by Frank Gaede's avatar Frank Gaede
Browse files

- added new method to BitField64

    void setValue(unsigned lowWord, unsigned highWord )
 - added some simple unit tests for BitField64
parent 9ce4923e
No related branches found
No related tags found
No related merge requests found
......@@ -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 ; }
......
......@@ -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" )
#--------------------------------------------------
......
#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;
}
//=============================================================================
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