Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
daqdataformats::RawDAQDataUnitTest Class Referenceabstract

Base class for RawDAQData unittest. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-30/DAQDataFormats/cxx/unittest/RawDAQDataUnitTest.h"

Inheritance diagram for daqdataformats::RawDAQDataUnitTest:
daqdataformats::ConfigurationBlockUnitTest daqdataformats::ConfigurationHeaderUnitTest daqdataformats::ConfigurationNameUnitTest daqdataformats::ConfigurationSystemIDUnitTest daqdataformats::ConfigurationTailUnitTest daqdataformats::DataBlockHeaderUnitTest daqdataformats::DataBlockUnitTest daqdataformats::EventHeaderUnitTest daqdataformats::EventTailUnitTest daqdataformats::EventUnitTest daqdataformats::MicroBlockHeaderUnitTest daqdataformats::MicroBlockUnitTest daqdataformats::MicroSliceHeaderUnitTest daqdataformats::MicroSliceUnitTest daqdataformats::MilliSliceHeaderUnitTest daqdataformats::MilliSliceUnitTest daqdataformats::NanoSliceHeaderUnitTest daqdataformats::NanoSliceUnitTest daqdataformats::RunHeaderUnitTest daqdataformats::TimingMarkerUnitTest daqdataformats::TriggerHeaderUnitTest daqdataformats::TriggerMaskUnitTest daqdataformats::TriggerRangeUnitTest daqdataformats::TriggerTimeUnitTest daqdataformats::TriggerTimingMarkerUnitTest daqdataformats::TriggerUnitTest

Public Member Functions

 RawDAQDataUnitTest (RawDAQDataConstructor *)
 
 ~RawDAQDataUnitTest ()
 
virtual void basicFieldGetAndSetChecks ()
 Check all field gets and sets for all versions. More...
 
virtual void checkDeepCopyConstructor ()
 Check Deep Copy Constructors for all versions. More...
 
virtual void checkShallowCopyConstructor ()
 Check Shallow Copy Constructors for all versions. More...
 
void setUp ()
 Some setup/teardown methods that Unittest require. More...
 
void tearDown ()
 

Protected Member Functions

virtual void basicFieldGetAndSetChecksForGivenVersion (const version_t)
 Check all field gets and sets for a given version. More...
 
bool checkReadDataIntoSameVersion () const
 Check readData for all versions of the dataformat. More...
 
bool checkReadDataIntoUnknownVersion () const
 Check readData for all versions of the dataformat. More...
 
virtual bool checkDeepCopyConstructor (const version_t) const =0
 Check constructors - deep copy and shallow copy. More...
 
virtual bool checkShallowCopyConstructor (const version_t) const =0
 
virtual DATAFORMAT_COMPARE_RESULTS compareDataFormats (const RawDAQData *, const RawDAQData *) const
 Are the two data formats the same? More...
 
virtual bool compareDataFormats (const RawDAQData *, const RawDAQData *, const DATAFORMAT_COMPARE_RESULTS) const
 
bool isPrintDataFormatUnknownVersion (const RawDAQData *) const
 Sometimes print() can print "DAQDataFormat is of unknown version". More...
 

Protected Attributes

RawDAQDataConstructor_dataFormatConstructor
 Pointer to RawDAQDataConstructor. More...
 

Private Member Functions

bool checkReadDataIntoUnknownVersion (const version_t) const
 Check readData of a given version into a dataformat with initially unknown version. More...
 
bool checkReadDataIntoSameVersion (const version_t) const
 Check readData of a given version into a dataformat with initially same version. More...
 
bool checkReadData (const version_t initialformat_version, const version_t readingformat_version) const
 
bool resizeBufferToSizeOfDataFormats (std::vector< uint32_t > &, const RawDAQData *) const
 Resize input vector to at least the size of the input dataformats. More...
 
bool resizeBufferToSizeOfDataFormats (std::vector< uint32_t > &, const RawDAQData *, const RawDAQData *) const
 Resize input vector to the maximum size of two input dataformats. More...
 
std::string getDifferenceBetweenStrings (const std::string, const std::string) const
 
std::string getDifferenceBetweenStrings (const RawDAQData *, const RawDAQData *) const
 

Detailed Description

Base class for RawDAQData unittest.

Definition at line 109 of file RawDAQDataUnitTest.h.

Constructor & Destructor Documentation

daqdataformats::RawDAQDataUnitTest::RawDAQDataUnitTest ( RawDAQDataConstructor df)

Definition at line 20 of file RawDAQDataUnitTest.cpp.

20  :
22 {
23 }
RawDAQDataConstructor * _dataFormatConstructor
Pointer to RawDAQDataConstructor.
daqdataformats::RawDAQDataUnitTest::~RawDAQDataUnitTest ( )

Definition at line 26 of file RawDAQDataUnitTest.cpp.

References _dataFormatConstructor.

26  {
28 }
RawDAQDataConstructor * _dataFormatConstructor
Pointer to RawDAQDataConstructor.

Member Function Documentation

virtual void daqdataformats::RawDAQDataUnitTest::basicFieldGetAndSetChecks ( )
inlinevirtual

Check all field gets and sets for all versions.

Reimplemented in daqdataformats::MilliSliceUnitTest, and daqdataformats::MicroSliceUnitTest.

Definition at line 115 of file RawDAQDataUnitTest.h.

References basicFieldGetAndSetChecksForGivenVersion(), and VERSION_LOOP_iver.

Referenced by daqdataformats::MicroSliceHeaderUnitTest::~MicroSliceHeaderUnitTest(), daqdataformats::MilliSliceHeaderUnitTest::~MilliSliceHeaderUnitTest(), and daqdataformats::TimingMarkerUnitTest::~TimingMarkerUnitTest().

115  {
117  };
#define VERSION_LOOP_iver(ACTION)
Perform some action that depends on iver.
virtual void basicFieldGetAndSetChecksForGivenVersion(const version_t)
Check all field gets and sets for a given version.
virtual void daqdataformats::RawDAQDataUnitTest::basicFieldGetAndSetChecksForGivenVersion ( const version_t  )
inlineprotectedvirtual

Check all field gets and sets for a given version.

Reimplemented in daqdataformats::MicroBlockUnitTest.

Definition at line 132 of file RawDAQDataUnitTest.h.

References checkDeepCopyConstructor(), checkReadData(), checkReadDataIntoSameVersion(), checkReadDataIntoUnknownVersion(), checkShallowCopyConstructor(), compareDataFormats(), getDifferenceBetweenStrings(), isPrintDataFormatUnknownVersion(), resizeBufferToSizeOfDataFormats(), and string.

Referenced by basicFieldGetAndSetChecks(), daqdataformats::ConfigurationBlockUnitTest::~ConfigurationBlockUnitTest(), daqdataformats::ConfigurationHeaderUnitTest::~ConfigurationHeaderUnitTest(), daqdataformats::ConfigurationNameUnitTest::~ConfigurationNameUnitTest(), daqdataformats::ConfigurationSystemIDUnitTest::~ConfigurationSystemIDUnitTest(), daqdataformats::ConfigurationTailUnitTest::~ConfigurationTailUnitTest(), daqdataformats::DataBlockHeaderUnitTest::~DataBlockHeaderUnitTest(), daqdataformats::DataBlockUnitTest::~DataBlockUnitTest(), daqdataformats::EventHeaderUnitTest::~EventHeaderUnitTest(), daqdataformats::EventTailUnitTest::~EventTailUnitTest(), daqdataformats::EventUnitTest::~EventUnitTest(), daqdataformats::MicroBlockHeaderUnitTest::~MicroBlockHeaderUnitTest(), daqdataformats::NanoSliceHeaderUnitTest::~NanoSliceHeaderUnitTest(), daqdataformats::NanoSliceUnitTest::~NanoSliceUnitTest(), daqdataformats::RunHeaderUnitTest::~RunHeaderUnitTest(), daqdataformats::TriggerHeaderUnitTest::~TriggerHeaderUnitTest(), daqdataformats::TriggerMaskUnitTest::~TriggerMaskUnitTest(), daqdataformats::TriggerRangeUnitTest::~TriggerRangeUnitTest(), daqdataformats::TriggerTimeUnitTest::~TriggerTimeUnitTest(), daqdataformats::TriggerTimingMarkerUnitTest::~TriggerTimingMarkerUnitTest(), and daqdataformats::TriggerUnitTest::~TriggerUnitTest().

132 {};
virtual void daqdataformats::RawDAQDataUnitTest::checkDeepCopyConstructor ( )
inlinevirtual
virtual bool daqdataformats::RawDAQDataUnitTest::checkDeepCopyConstructor ( const version_t  ) const
protectedpure virtual

Check constructors - deep copy and shallow copy.

bool daqdataformats::RawDAQDataUnitTest::checkReadData ( const version_t  initialformat_version,
const version_t  readingformat_version 
) const
private

Check readData of a given version into a dataformat with a different version It is allowed to have either

  1. (initialformat_version == readingformat_version) AND (initialformat_version != UnknownVersion)
  2. (initialformat_version != UnknownVersion) AND (readingformat_version == UnknownVersion)

Check Versions. they have to be valid:

  1. (initialformat_version == readingformat_version) AND (initialformat_version != UnknownVersion)
  2. (initialformat_version != UnknownVersion) AND (readingformat_version == UnknownVersion)

If versions are not valid, exit now

Construct DataFormats

Check Printout version for format_nonzero

Check Printout version for format_zero

Check Printout version for format_nonzero

Check Printout version for format_zero

Check if DataFormats are the same At this point they should be different

Temporary buffer where we are going to put content of the format_nonzero dataformat

Need to resize buffer to the maxumum size

Now, this is the pointer to the first element of the Temporary buffer

Write the first dataformat (format_nonzero) into a buffer

Read the buffer to the second (empty) dataformat

Check if the two dataformats are now the same At this point they should be the same

All tests succeded

Definition at line 65 of file RawDAQDataUnitTest.cpp.

References _dataFormatConstructor, compareDataFormats(), daqdataformats::rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION, daqdataformats::DATAFORMATS_ARE_DIFFERENT, daqdataformats::DATAFORMATS_ARE_THE_SAME, allTimeWatchdog::endl, getDifferenceBetweenStrings(), daqdataformats::RawDAQDataConstructor::getEmptyDataFormat(), daqdataformats::RawDAQDataConstructor::getFilledDataFormat(), isPrintDataFormatUnknownVersion(), LOG_DEBUG, LOG_ERROR, resizeBufferToSizeOfDataFormats(), and string.

Referenced by basicFieldGetAndSetChecksForGivenVersion(), checkReadDataIntoSameVersion(), and checkReadDataIntoUnknownVersion().

66  {
67 
68  LOG_DEBUG("UNITTEST")<<__PRETTY_FUNCTION__<<"\n"
69  <<"Versions :"
70  <<" initialformat_version = "<<initialformat_version
71  <<". readingformat_version = "<<readingformat_version<<"\n";
72 
73  /// Check Versions. they have to be valid:
74  /// 1. (initialformat_version == readingformat_version) AND (initialformat_version != UnknownVersion)
75  /// 2. (initialformat_version != UnknownVersion) AND (readingformat_version == UnknownVersion)
76  {
77  bool are_versions_valid = false;
78  if( (initialformat_version == readingformat_version ) && (initialformat_version != rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION)) are_versions_valid = true;
79  if( (initialformat_version != rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION) && (readingformat_version == rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION)) are_versions_valid = true;
80 
81  /// If versions are not valid, exit now
82  if(! are_versions_valid){
83  LOG_ERROR("UNITTEST")<<"Versions are not valid:"
84  <<" initialformat_version = "<<initialformat_version
85  <<". readingformat_version = "<<readingformat_version;
86  return false;
87  }
88  }// end of checking versions
89 
90  /// Construct DataFormats
91  RawDAQData* format_nonzero_raw = NULL;
92  try {
93  format_nonzero_raw = _dataFormatConstructor->getFilledDataFormat(initialformat_version);
94  }
95  catch(...){
96  LOG_ERROR("UNITTEST")<<"Could not get a FILLED non-zero Data format of version "<<initialformat_version<<"\n";
97  throw;
98  return false;
99  }
100  boost::shared_ptr<RawDAQData> format_nonzero(format_nonzero_raw);
101 
102 
103  RawDAQData* format_zero_raw = NULL;
104  try{
105  format_zero_raw = _dataFormatConstructor->getEmptyDataFormat(readingformat_version);
106  }
107  catch(...){
108  LOG_ERROR("UNITTEST")<<"Could not get an EMPTY zero Data format of version "<<readingformat_version<<"\n";
109  throw;
110  return false;
111  }
112  boost::shared_ptr<RawDAQData> format_zero(format_zero_raw);
113 
114  //LOG_DEBUG("UNITTEST")<<"Version"<<initialformat_version<<"\n";
115  //LOG_DEBUG("UNITTEST")<<*(format_nonzero.get());
116 
117  {
118  /// Check Printout version for format_nonzero
119  if( initialformat_version != rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION
120  && isPrintDataFormatUnknownVersion(format_nonzero.get())){
121  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<"\n"
122  <<"Nonzero format should have print with defined version, but it returns:\n"
123  <<*(format_nonzero.get());
124  return false;
125  }
126 
127  /// Check Printout version for format_zero
128  if( readingformat_version != rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION
129  && isPrintDataFormatUnknownVersion(format_zero.get())){
130  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<"\n"
131  <<"Zero format should have print with defined version, but it returns:\n"
132  <<*(format_zero.get());
133  return false;
134  }
135 
136  /// Check Printout version for format_nonzero
137  if( initialformat_version == rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION
138  && !isPrintDataFormatUnknownVersion(format_nonzero.get())){
139  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<"\n"
140  <<"Nonzero format should have print UNKNOWN format, but it returns:\n"
141  <<*(format_nonzero.get());
142  return false;
143  }
144 
145  /// Check Printout version for format_zero
146  if( initialformat_version == rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION
147  && !isPrintDataFormatUnknownVersion(format_zero.get())){
148  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<"\n"
149  <<"Zero format should have print UNKNOWN format, but it returns:\n"
150  <<*(format_zero.get());
151  return false;
152  }
153  }// end of checking
154  /// Check if DataFormats are the same
155  /// At this point they should be different
156  try{
157  if(compareDataFormats(format_nonzero.get(), format_zero.get()) != DATAFORMATS_ARE_DIFFERENT){
158  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<". "
159  <<"Formats should be Different.\n"
160  <<"Nonzero format:\n"
161  <<*(format_nonzero.get())
162  <<"Copied format:\n"
163  <<*(format_zero.get());
164  return false;
165  }// end of checking if dataformats are different
166  }
167  catch(...){
168  LOG_ERROR("UNITTEST")<<"From "<<__PRETTY_FUNCTION__<<std::endl
169  <<"Could not compare versions "
170  <<initialformat_version<<" and "<<readingformat_version<<std::endl;
171  }
172 
173  /// Temporary buffer where we are going to put content of the format_nonzero dataformat
174  std::vector<uint32_t> buffer_tmp;
175 
176  /// Need to resize buffer to the maxumum size
177  resizeBufferToSizeOfDataFormats(buffer_tmp, format_nonzero.get(), format_nonzero.get());
178 
179  /// Now, this is the pointer to the first element of the Temporary buffer
180  const uint32_t* pbuffer = (uint32_t*)(&buffer_tmp[0]);
181 
182  /// Write the first dataformat (format_nonzero) into a buffer
183  try{
184  format_nonzero->writeData(pbuffer);
185  }
186  catch(...){
187  LOG_ERROR("UNITTEST")<<"From "<<__PRETTY_FUNCTION__<<std::endl
188  <<"Could not write "<<initialformat_version<<std::endl;
189  }
190 
191  /// Read the buffer to the second (empty) dataformat
192  try{
193  format_zero->readData(pbuffer);
194  }
195  catch(...){
196  LOG_ERROR("UNITTEST")<<"From "<<__PRETTY_FUNCTION__
197  <<". Could not read "<<initialformat_version<<std::endl;
198  }
199 
200  /// Check if the two dataformats are now the same
201  /// At this point they should be the same
202  try{
203  if(compareDataFormats(format_nonzero.get(), format_zero.get()) != DATAFORMATS_ARE_THE_SAME){
204  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<". "
205  <<"Formats should be the same. But they are "
206  <<boost::lexical_cast<std::string>(compareDataFormats(format_nonzero.get(), format_zero.get()))
207  <<"\nNonzero format:\n"
208  <<*(format_nonzero.get())
209  <<"Copied format:\n"
210  <<*(format_zero.get())
211  <<"\n Difference:\n"
212  <<getDifferenceBetweenStrings(format_nonzero.get(), format_zero.get());
213  return false;
214  }// end of checking if the dataformats are the same
215  }
216  catch(...){
217  LOG_ERROR("UNITTEST")<<"From "<<__PRETTY_FUNCTION__<<std::endl
218  <<"Could not compare versions after reading"
219  <<initialformat_version<<" and "<<readingformat_version<<"\n";
220  }
221 
222  /// All tests succeded
223  return true;
224 }
virtual daqdataformats::RawDAQData * getFilledDataFormat(const version_t) const =0
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
virtual DATAFORMAT_COMPARE_RESULTS compareDataFormats(const RawDAQData *, const RawDAQData *) const
Are the two data formats the same?
virtual daqdataformats::RawDAQData * getEmptyDataFormat(const version_t) const =0
method to create an empty dataformat with a given version
bool resizeBufferToSizeOfDataFormats(std::vector< uint32_t > &, const RawDAQData *) const
Resize input vector to at least the size of the input dataformats.
RawDAQDataConstructor * _dataFormatConstructor
Pointer to RawDAQDataConstructor.
static const version_t DAQDATAFORMAT_UNKNOWN_VERSION
Definition: RawDAQData.h:81
std::string getDifferenceBetweenStrings(const std::string, const std::string) const
#define LOG_ERROR(stream)
Definition: Messenger.h:129
bool isPrintDataFormatUnknownVersion(const RawDAQData *) const
Sometimes print() can print "DAQDataFormat is of unknown version".
enum BeamMode string
bool daqdataformats::RawDAQDataUnitTest::checkReadDataIntoSameVersion ( ) const
protected

Check readData for all versions of the dataformat.

Definition at line 32 of file RawDAQDataUnitTest.cpp.

References allTimeWatchdog::endl, LOG_DEBUG, and VERSION_LOOP_iver.

Referenced by basicFieldGetAndSetChecksForGivenVersion().

32  {
34  LOG_DEBUG("UNITTEST")<<"checkReadDataIntoSameVersion for version "<<iver<<std::endl;
35  if(!checkReadDataIntoSameVersion(iver)) return false;
36  )
37  return true;
38 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
#define VERSION_LOOP_iver(ACTION)
Perform some action that depends on iver.
bool checkReadDataIntoSameVersion() const
Check readData for all versions of the dataformat.
bool daqdataformats::RawDAQDataUnitTest::checkReadDataIntoSameVersion ( const version_t  ver) const
private

Check readData of a given version into a dataformat with initially same version.

Definition at line 54 of file RawDAQDataUnitTest.cpp.

References checkReadData().

54  {
55  return checkReadData(ver, ver);
56 }
bool checkReadData(const version_t initialformat_version, const version_t readingformat_version) const
bool daqdataformats::RawDAQDataUnitTest::checkReadDataIntoUnknownVersion ( ) const
protected

Check readData for all versions of the dataformat.

Definition at line 41 of file RawDAQDataUnitTest.cpp.

References allTimeWatchdog::endl, LOG_DEBUG, and VERSION_LOOP_iver.

Referenced by basicFieldGetAndSetChecksForGivenVersion().

41  {
42 
44  LOG_DEBUG("UNITTEST")<<"checkReadDataIntoUnknownVersion for version "<<iver<<std::endl;
46  return false;
47  )
48 
49  return true;
50 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
bool checkReadDataIntoUnknownVersion() const
Check readData for all versions of the dataformat.
#define VERSION_LOOP_iver(ACTION)
Perform some action that depends on iver.
bool daqdataformats::RawDAQDataUnitTest::checkReadDataIntoUnknownVersion ( const version_t  ver) const
private

Check readData of a given version into a dataformat with initially unknown version.

Definition at line 60 of file RawDAQDataUnitTest.cpp.

References checkReadData(), and daqdataformats::rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION.

60  {
62 }
static const version_t DAQDATAFORMAT_UNKNOWN_VERSION
Definition: RawDAQData.h:81
bool checkReadData(const version_t initialformat_version, const version_t readingformat_version) const
virtual void daqdataformats::RawDAQDataUnitTest::checkShallowCopyConstructor ( )
inlinevirtual
virtual bool daqdataformats::RawDAQDataUnitTest::checkShallowCopyConstructor ( const version_t  ) const
protectedpure virtual
DATAFORMAT_COMPARE_RESULTS daqdataformats::RawDAQDataUnitTest::compareDataFormats ( const RawDAQData format1,
const RawDAQData format2 
) const
protectedvirtual

Are the two data formats the same?

Print the first input dataformat into a string

Print the first input dataformat into a string

Compare the two strings and see if they are the same

See if first string contains second

See if second string contains first

Definition at line 227 of file RawDAQDataUnitTest.cpp.

References daqdataformats::DATAFORMATS_ARE_DIFFERENT, daqdataformats::DATAFORMATS_ARE_THE_SAME, daqdataformats::FIRST_CONTAINS_SECOND, daqdataformats::RawDAQData::print(), daqdataformats::SECOND_CONTAINS_FIRST, and string.

Referenced by daqdataformats::MicroSliceUnitTest::basicFieldGetAndSetChecks(), daqdataformats::MilliSliceUnitTest::basicFieldGetAndSetChecks(), basicFieldGetAndSetChecksForGivenVersion(), checkReadData(), daqdataformats::ConfigurationBlockUnitTest::~ConfigurationBlockUnitTest(), daqdataformats::DataBlockUnitTest::~DataBlockUnitTest(), daqdataformats::EventUnitTest::~EventUnitTest(), daqdataformats::NanoSliceUnitTest::~NanoSliceUnitTest(), and daqdataformats::TriggerUnitTest::~TriggerUnitTest().

228 {
229  /// Print the first input dataformat into a string
230  std::string string1;
231  format1->print(string1);
232 
233  /// Print the first input dataformat into a string
234  std::string string2;
235  format2->print(string2);
236 
237  /// Compare the two strings and see if they are the same
238  if(string1.compare(string2) == 0) return DATAFORMATS_ARE_THE_SAME;
239 
240  /// See if first string contains second
241  if(string1.find(string2) != std::string::npos) return FIRST_CONTAINS_SECOND;
242 
243  /// See if second string contains first
244  if(string2.find(string1) != std::string::npos) return SECOND_CONTAINS_FIRST;
245 
247 }
enum BeamMode string
bool daqdataformats::RawDAQDataUnitTest::compareDataFormats ( const RawDAQData format1,
const RawDAQData format2,
const DATAFORMAT_COMPARE_RESULTS  what_it_should_be 
) const
protectedvirtual

Print the first input dataformat into a string

Print the first input dataformat into a string

Compare the two strings and see if they are the same

Definition at line 250 of file RawDAQDataUnitTest.cpp.

References daqdataformats::DATAFORMATS_ARE_DIFFERENT, daqdataformats::DATAFORMATS_ARE_THE_SAME, daqdataformats::FIRST_CONTAINS_SECOND, getDifferenceBetweenStrings(), daqdataformats::getNameForResults(), LOG_ERROR, daqdataformats::RawDAQData::print(), fillBadChanDBTables::result, daqdataformats::SECOND_CONTAINS_FIRST, and string.

254 {
255 
256  /// Print the first input dataformat into a string
257  std::string string1;
258  format1->print(string1);
259 
260  /// Print the first input dataformat into a string
261  std::string string2;
262  format2->print(string2);
263 
264 
266 
267  /// Compare the two strings and see if they are the same
268  if (string1.compare(string2) == 0) result = DATAFORMATS_ARE_THE_SAME;
269  else if(string1.find(string2) != std::string::npos) result = FIRST_CONTAINS_SECOND;
270  else if(string2.find(string1) != std::string::npos) result = SECOND_CONTAINS_FIRST;
271 
272 
273  if(result != what_it_should_be){
274  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<". "
275  <<"Formats should be "<<daqdataformats::getNameForResults(what_it_should_be)
276  <<". But they are " <<daqdataformats::getNameForResults(result)
277  <<"\nFirst format:"<<string1
278  <<"\nSecond format:"<<string2
279  <<"\n Difference:\n"
280  <<getDifferenceBetweenStrings(string1, string2);
281  return false;
282  }// end of checking if the dataformats are the same
283 
284  return(result == what_it_should_be);
285 }
std::string getNameForResults(const DATAFORMAT_COMPARE_RESULTS res)
DATAFORMAT_COMPARE_RESULTS
Enumeration of the two dataformat comparisson results.
std::string getDifferenceBetweenStrings(const std::string, const std::string) const
#define LOG_ERROR(stream)
Definition: Messenger.h:129
enum BeamMode string
std::string daqdataformats::RawDAQDataUnitTest::getDifferenceBetweenStrings ( const std::string  str1,
const std::string  str2 
) const
private

Definition at line 326 of file RawDAQDataUnitTest.cpp.

References compare(), release_diff::diff, std::min(), and string.

Referenced by basicFieldGetAndSetChecksForGivenVersion(), checkReadData(), compareDataFormats(), and getDifferenceBetweenStrings().

326  {
327 
328  std::istringstream string_stream_str1(str1);
329  std::istringstream string_stream_str2(str2);
330 
331  std::vector<std::string> lines_str1;
332  std::vector<std::string> lines_str2;
333 
334  std::string line_tmp;
335  while(std::getline(string_stream_str1, line_tmp)){
336  lines_str1.push_back(line_tmp);
337  }
338  while(std::getline(string_stream_str2, line_tmp)){
339  lines_str2.push_back(line_tmp);
340  }
341 
342 
343  const uint32_t min_lines = std::min(lines_str1.size(), lines_str2.size());
344 
346 
347  for(uint32_t iline = 0; iline < min_lines; ++iline){
348  if(lines_str1[iline].compare(lines_str1[iline]) != 0){
349  diff += "line " + boost::lexical_cast<std::string>(iline) + ": ";
350  diff += lines_str1[iline] +"VS" + lines_str2[iline] + "\n";
351  }
352  }
353 
354  diff += "ENDOFDIFF";
355 
356  return diff;
357 }
bool compare(const GFluxGenerator &g1, const GFluxGenerator &g2)
T min(const caf::Proxy< T > &a, T b)
enum BeamMode string
std::string daqdataformats::RawDAQDataUnitTest::getDifferenceBetweenStrings ( const RawDAQData df1,
const RawDAQData df2 
) const
private

Definition at line 318 of file RawDAQDataUnitTest.cpp.

References getDifferenceBetweenStrings(), daqdataformats::RawDAQData::print(), and string.

318  {
319  std::string str1, str2;
320  df1->print(str1);
321  df2->print(str2);
322  return getDifferenceBetweenStrings(str1, str2);
323 }
std::string getDifferenceBetweenStrings(const std::string, const std::string) const
enum BeamMode string
bool daqdataformats::RawDAQDataUnitTest::isPrintDataFormatUnknownVersion ( const RawDAQData df) const
protected

Sometimes print() can print "DAQDataFormat is of unknown version".

Print the first input dataformat into a string

See if first string contains second

Definition at line 291 of file RawDAQDataUnitTest.cpp.

References daqdataformats::RawDAQData::print(), and string.

Referenced by daqdataformats::MilliSliceUnitTest::basicFieldGetAndSetChecks(), basicFieldGetAndSetChecksForGivenVersion(), and checkReadData().

291  {
292 
293  /// Print the first input dataformat into a string
294  std::string string1;
295  df->print(string1);
296 
297  /// See if first string contains second
298  if(string1.find("DAQDataFormat is of unknown version") != std::string::npos) return true;
299 
300  return false;
301 }
enum BeamMode string
bool daqdataformats::RawDAQDataUnitTest::resizeBufferToSizeOfDataFormats ( std::vector< uint32_t > &  buf,
const RawDAQData f1 
) const
private

Resize input vector to at least the size of the input dataformats.

Definition at line 304 of file RawDAQDataUnitTest.cpp.

References daqdataformats::RawDAQData::sizeofdata().

Referenced by basicFieldGetAndSetChecksForGivenVersion(), checkReadData(), and resizeBufferToSizeOfDataFormats().

304  {
305 
306  if(buf.size() < f1->sizeofdata())
307  buf.resize(f1->sizeofdata());
308 
309  return true;
310 }
Float_t f1
bool daqdataformats::RawDAQDataUnitTest::resizeBufferToSizeOfDataFormats ( std::vector< uint32_t > &  buf,
const RawDAQData f1,
const RawDAQData f2 
) const
private

Resize input vector to the maximum size of two input dataformats.

Definition at line 312 of file RawDAQDataUnitTest.cpp.

References resizeBufferToSizeOfDataFormats().

312  {
314  return resizeBufferToSizeOfDataFormats(buf, f2);
315 }
Float_t f2
bool resizeBufferToSizeOfDataFormats(std::vector< uint32_t > &, const RawDAQData *) const
Resize input vector to at least the size of the input dataformats.
Float_t f1
void daqdataformats::RawDAQDataUnitTest::setUp ( )
inline

Some setup/teardown methods that Unittest require.

Definition at line 126 of file RawDAQDataUnitTest.h.

126 {}
void daqdataformats::RawDAQDataUnitTest::tearDown ( )
inline

Definition at line 127 of file RawDAQDataUnitTest.h.

127 {}

Member Data Documentation

RawDAQDataConstructor* daqdataformats::RawDAQDataUnitTest::_dataFormatConstructor
protected

Pointer to RawDAQDataConstructor.

Definition at line 174 of file RawDAQDataUnitTest.h.

Referenced by checkReadData(), and ~RawDAQDataUnitTest().


The documentation for this class was generated from the following files: