RawDAQDataUnitTest.h
Go to the documentation of this file.
1 /*
2  * File: RawDAQDataUnitTest.h
3  * Author: denis
4  *
5  * Base class for RawDAQData unittest
6  *
7  * Created on September 20, 2012, 4:43 PM
8  */
9 
10 #ifndef RAWDAQDATAUNITTEST_H
11 #define RAWDAQDATAUNITTEST_H
12 #include <cppunit/extensions/HelperMacros.h>
13 //#include "DAQDataFormats/../unittest/RawDAQDataConstructor.h"
14 #include "RawDAQDataConstructor.h"
15 
16 #include <DAQDataFormats/DataFormatException.h>
17 
18 #include <boost/shared_ptr.hpp>
19 
20 namespace daqdataformats {
21 
22 /// Perform some action that depends on iver
23 #define VERSION_LOOP_iver(ACTION) \
24  { \
25  const version_t maximum_version = _dataFormatConstructor->getMaximumVersion(); \
26  if(maximum_version > rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION) { \
27  for(int iver = 0; iver <= maximum_version; ++iver){ \
28  ACTION; \
29  } \
30  } \
31  }
32 
33 
34 /// Assert some action that depends on iver
35 #define ASSERT_VERSION_LOOP_iver(ACTION) VERSION_LOOP_iver(CPPUNIT_ASSERT(ACTION))
36 
37 /// Standard function that checks Deep Copy Constructor
38 #define DEFINE_checkDeepCopyConstructor(CLASS) \
39  void checkDeepCopyConstructor(){ \
40  LOG_DEBUG("UNITTEST")<<__PRETTY_FUNCTION__<<std::endl; \
41  if(_dataFormatConstructor->getMaximumVersion() == rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION) \
42  CPPUNIT_ASSERT(checkDeepCopyConstructor(rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION)); \
43  else \
44  ASSERT_VERSION_LOOP_iver(checkDeepCopyConstructor(iver)); \
45  } \
46  bool checkDeepCopyConstructor(const version_t ver) const { \
47  if(ver != rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION) \
48  LOG_DEBUG("UNITTEST")<<__PRETTY_FUNCTION__<<" for version "<<ver<<std::endl; \
49  boost::shared_ptr<CLASS> format_nonzero((CLASS*)_mainDFConstructor->getFilledDataFormat(ver));\
50  CLASS deep_copy(*(format_nonzero.get())); \
51  if(compareDataFormats(format_nonzero.get(), &deep_copy) != DATAFORMATS_ARE_THE_SAME){ \
52  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<"\n" \
53  <<"Nonzero format:\n" \
54  <<*(format_nonzero.get()) \
55  <<"Copied format:\n" \
56  <<deep_copy; \
57  return false; \
58  } \
59  return true; \
60  }
61 
62 /// Standard function that checks Shallow Copy Constructor
63 #define DEFINE_checkShallowCopyConstructor(CLASS) \
64  void checkShallowCopyConstructor() { \
65  LOG_DEBUG("UNITTEST")<<__PRETTY_FUNCTION__<<std::endl; \
66  if(_dataFormatConstructor->getMaximumVersion() == rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION) \
67  CPPUNIT_ASSERT(checkShallowCopyConstructor(rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION)); \
68  else \
69  ASSERT_VERSION_LOOP_iver(checkShallowCopyConstructor(iver)); \
70  } \
71  bool checkShallowCopyConstructor(const version_t ver) const { \
72  if(ver != rawdaqdataformat::DAQDATAFORMAT_UNKNOWN_VERSION) \
73  LOG_DEBUG("UNITTEST")<<__PRETTY_FUNCTION__<<" for version "<<ver<<std::endl; \
74  boost::shared_ptr<CLASS> format_nonzero((CLASS*)_mainDFConstructor->getFilledDataFormat(ver)); \
75  CLASS shallow_copy((void*)(format_nonzero.get()->getBuffer())); \
76  if(compareDataFormats(format_nonzero.get(), &shallow_copy) != DATAFORMATS_ARE_THE_SAME){ \
77  LOG_ERROR("UNITTEST")<<"Failure in "<<__PRETTY_FUNCTION__<<" at "<<__LINE__<<"\n" \
78  <<"Nonzero format:\n" \
79  <<*(format_nonzero.get()) \
80  <<"Copied format:\n" \
81  <<shallow_copy; \
82  return false; \
83  } \
84  return true; \
85  }
86 
87 #define DEFINE_testReadDataIntoSameVersion \
88  void testReadDataIntoSameVersion() { \
89  LOG_DEBUG("UNITTEST")<<__PRETTY_FUNCTION__<<std::endl; \
90  CPPUNIT_ASSERT(checkReadDataIntoSameVersion()); \
91 }
92 
93 #define DEFINE_testReadDataIntoUnknownVersion \
94  void testReadDataIntoUnknownVersion() {LOG_DEBUG("UNITTEST")<<__PRETTY_FUNCTION__<<std::endl; CPPUNIT_ASSERT(checkReadDataIntoUnknownVersion());}
95 
96 
97 /// Enumeration of the two dataformat comparisson results
103 };
104 
106 
107 
108 /// Base class for RawDAQData unittest
109 class RawDAQDataUnitTest : public CPPUNIT_NS::TestFixture {
110 public:
113 
114  /// Check all field gets and sets for all versions
115  virtual void basicFieldGetAndSetChecks() {
117  };
118 
119  /// Check Deep Copy Constructors for all versions
120  virtual void checkDeepCopyConstructor() {};
121 
122  /// Check Shallow Copy Constructors for all versions
123  virtual void checkShallowCopyConstructor() {};
124 
125  /// Some setup/teardown methods that Unittest require
126  void setUp() {}
127  void tearDown(){}
128 
129 protected:
130 
131  /// Check all field gets and sets for a given version
133 
134  /// Check readData for all versions of the dataformat
135  bool checkReadDataIntoSameVersion() const;
136  /// Check readData for all versions of the dataformat
137  bool checkReadDataIntoUnknownVersion() const;
138 
139  /// Check constructors - deep copy and shallow copy
140  virtual bool checkDeepCopyConstructor (const version_t) const = 0;
141  virtual bool checkShallowCopyConstructor(const version_t) const = 0;
142 
143  /// Are the two data formats the same?
145  virtual bool compareDataFormats(const RawDAQData*, const RawDAQData*, const DATAFORMAT_COMPARE_RESULTS) const;
146 
147  /// Sometimes print() can print "DAQDataFormat is of unknown version"
148  bool isPrintDataFormatUnknownVersion(const RawDAQData*) const;
149 
150 private:
151 
152  /// Check readData of a given version into a dataformat with initially unknown version
153  bool checkReadDataIntoUnknownVersion(const version_t) const;
154  /// Check readData of a given version into a dataformat with initially same version
155  bool checkReadDataIntoSameVersion (const version_t) const;
156 
157  /// Check readData of a given version into a dataformat with a different version
158  /// It is allowed to have either
159  /// 1. (initialformat_version == readingformat_version) AND (initialformat_version != UnknownVersion)
160  /// 2. (initialformat_version != UnknownVersion) AND (readingformat_version == UnknownVersion)
161  bool checkReadData(const version_t initialformat_version, const version_t readingformat_version) const;
162 
163  /// Resize input vector to at least the size of the input dataformats
164  bool resizeBufferToSizeOfDataFormats(std::vector<uint32_t>&, const RawDAQData*) const;
165 
166  /// Resize input vector to the maximum size of two input dataformats
167  bool resizeBufferToSizeOfDataFormats(std::vector<uint32_t>&, const RawDAQData*, const RawDAQData*) const;
168 
171 
172 protected:
173  /// Pointer to RawDAQDataConstructor
175 
176 };
177 
178 }// end of namespace
179 
180 #endif /* RAWDAQDATAUNITTEST_H */
181 
std::string getNameForResults(const DATAFORMAT_COMPARE_RESULTS res)
virtual DATAFORMAT_COMPARE_RESULTS compareDataFormats(const RawDAQData *, const RawDAQData *) const
Are the two data formats the same?
DATAFORMAT_COMPARE_RESULTS
Enumeration of the two dataformat comparisson results.
bool checkReadDataIntoUnknownVersion() const
Check readData for all versions of the dataformat.
virtual void basicFieldGetAndSetChecks()
Check all field gets and sets for all versions.
virtual void checkShallowCopyConstructor()
Check Shallow Copy Constructors for all versions.
Base class for RawDAQData unittest.
bool resizeBufferToSizeOfDataFormats(std::vector< uint32_t > &, const RawDAQData *) const
Resize input vector to at least the size of the input dataformats.
#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.
RawDAQDataConstructor * _dataFormatConstructor
Pointer to RawDAQDataConstructor.
bool checkReadDataIntoSameVersion() const
Check readData for all versions of the dataformat.
void setUp()
Some setup/teardown methods that Unittest require.
virtual void checkDeepCopyConstructor()
Check Deep Copy Constructors for all versions.
int32_t version_t
Definition: RawDAQData.h:72
RawDAQDataUnitTest(RawDAQDataConstructor *)
Class to hold the data from the FEBs in correct formats.
bool checkReadData(const version_t initialformat_version, const version_t readingformat_version) const
std::string getDifferenceBetweenStrings(const std::string, const std::string) const
bool isPrintDataFormatUnknownVersion(const RawDAQData *) const
Sometimes print() can print "DAQDataFormat is of unknown version".
enum BeamMode string