Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:47

0001 // Unit test for L1GctInternHtMiss class.
0002 //
0003 // Author Robert Frazier
0004 
0005 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctInternHtMiss.h"
0006 
0007 #include <cassert>
0008 #include <iostream>
0009 #include <sstream>
0010 #include <cstdlib>
0011 
0012 using namespace std;
0013 
0014 uint16_t gCapBlockVal = 0x582;
0015 uint16_t gCapIndexVal = 3;
0016 int16_t gBxVal = 55;
0017 uint32_t gRawVal1 = 0xf9ef8ecf;
0018 uint32_t gRawVal2 = 0x394e1d9f;
0019 
0020 // Prototypes
0021 void terminateIfAssertNotWorking();
0022 void testMethodsOfNullVariant();
0023 void testMethodsOfHtxVariant();
0024 void testMethodsOfHtyVariant();
0025 void testMethodsOfHtxHtyVariant();
0026 void testInequalityOperatorsBetweenCtors();
0027 
0028 int main() {
0029   terminateIfAssertNotWorking();
0030 
0031   testMethodsOfNullVariant();
0032   testMethodsOfHtxVariant();
0033   testMethodsOfHtyVariant();
0034   testMethodsOfHtxHtyVariant();
0035   testInequalityOperatorsBetweenCtors();
0036 
0037   cout << "Unit test for L1GctInternHtMiss passed successfully." << endl;
0038   return 0;
0039 }
0040 
0041 void terminateIfAssertNotWorking() {
0042   bool assertsWork = false;
0043   assert(assertsWork = true);
0044   if (assertsWork) {
0045     return;
0046   }
0047 
0048   cout << "ERROR! Cannot run unit test as the assert() function is being\n"
0049           "optimised away by the compiler.  Please recompile test with\n"
0050           "the debug options enabled and without #define NDEBUG"
0051        << endl;
0052   exit(1);
0053 }
0054 
0055 void testMethodsOfNullVariant() {
0056   L1GctInternHtMiss testObj1;
0057 
0058   assert(testObj1.type() == L1GctInternHtMiss::nulltype);
0059   assert(testObj1.capBlock() == 0);
0060   assert(testObj1.capIndex() == 0);
0061   assert(testObj1.bx() == 0);
0062   assert(testObj1.isThereHtx() == false);
0063   assert(testObj1.isThereHty() == false);
0064   assert(testObj1.raw() == 0);  // The non-data in the raw data (BC0, etc) is masked off.
0065   assert(testObj1.htx() == 0);
0066   assert(testObj1.hty() == 0);
0067   assert(testObj1.overflow() == false);
0068 
0069   ostringstream oss;
0070   oss << testObj1;
0071   string expectedStr =
0072       " L1GctInternHtMiss:  htx=n/a, hty=n/a;"
0073       " cap block=0x0, index=0, BX=0";
0074   assert(oss.str() == expectedStr);
0075 }
0076 
0077 void testMethodsOfHtxVariant() {
0078   L1GctInternHtMiss testObj1 = L1GctInternHtMiss::unpackerMissHtx(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal1);
0079 
0080   assert(testObj1.type() == L1GctInternHtMiss::miss_htx);
0081   assert(testObj1.capBlock() == gCapBlockVal);
0082   assert(testObj1.capIndex() == gCapIndexVal);
0083   assert(testObj1.bx() == gBxVal);
0084   assert(testObj1.isThereHtx() == true);
0085   assert(testObj1.isThereHty() == false);
0086   assert(testObj1.raw() == (gRawVal1 & 0x4000ffff));  // The non-data in the raw data (BC0, etc) is masked off.
0087   assert(testObj1.htx() == -28977);
0088   assert(testObj1.hty() == 0);
0089   assert(testObj1.overflow() == true);
0090 
0091   L1GctInternHtMiss testObj2 = L1GctInternHtMiss::unpackerMissHtx(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal2);
0092   assert(testObj2.raw() == (gRawVal2 & 0x4000ffff));  // The non-data in the raw data (BC0, etc) is masked off.
0093   assert(testObj2.htx() == 7583);
0094   assert(testObj2.hty() == 0);
0095   assert(testObj2.overflow() == false);
0096 
0097   L1GctInternHtMiss testObj3(testObj1);  // Copy constructor
0098 
0099   assert(testObj1 == testObj3);  // Test equality & copy ctor.
0100   assert(testObj1 != testObj2);  // Test inequality.
0101 
0102   testObj2 = testObj3;  // Assignment operator
0103 
0104   assert(testObj1 == testObj2);  // Test Assignment operator + equality
0105 
0106   ostringstream oss;
0107   oss << testObj1;
0108   string expectedStr =
0109       " L1GctInternHtMiss:  htx=-28977, hty=n/a; overflow set;"
0110       " cap block=0x582, index=3, BX=55";
0111   assert(oss.str() == expectedStr);
0112 }
0113 
0114 void testMethodsOfHtyVariant() {
0115   L1GctInternHtMiss testObj1 = L1GctInternHtMiss::unpackerMissHty(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal1);
0116 
0117   assert(testObj1.type() == L1GctInternHtMiss::miss_hty);
0118   assert(testObj1.capBlock() == gCapBlockVal);
0119   assert(testObj1.capIndex() == gCapIndexVal);
0120   assert(testObj1.bx() == gBxVal);
0121   assert(testObj1.isThereHtx() == false);
0122   assert(testObj1.isThereHty() == true);
0123   assert(testObj1.raw() == (gRawVal1 & 0x4000ffff));  // The non-data in the raw data (BC0, etc) is masked off.
0124   assert(testObj1.htx() == 0);
0125   assert(testObj1.hty() == -28977);
0126   assert(testObj1.overflow() == true);
0127 
0128   L1GctInternHtMiss testObj2 = L1GctInternHtMiss::unpackerMissHty(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal2);
0129   assert(testObj2.raw() == (gRawVal2 & 0x4000ffff));  // The non-data in the raw data (BC0, etc) is masked off.
0130   assert(testObj2.htx() == 0);
0131   assert(testObj2.hty() == 7583);
0132   assert(testObj2.overflow() == false);
0133 
0134   L1GctInternHtMiss testObj3(testObj1);  // Copy constructor
0135 
0136   assert(testObj1 == testObj3);  // Test equality & copy ctor.
0137   assert(testObj1 != testObj2);  // Test inequality.
0138 
0139   testObj2 = testObj3;  // Assignment operator
0140 
0141   assert(testObj1 == testObj2);  // Test Assignment operator + equality
0142 
0143   ostringstream oss;
0144   oss << testObj1;
0145   string expectedStr =
0146       " L1GctInternHtMiss:  htx=n/a, hty=-28977; overflow set;"
0147       " cap block=0x582, index=3, BX=55";
0148   assert(oss.str() == expectedStr);
0149 }
0150 
0151 void testMethodsOfHtxHtyVariant() {
0152   L1GctInternHtMiss testObj1 = L1GctInternHtMiss::unpackerMissHtxHty(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal1);
0153 
0154   assert(testObj1.type() == L1GctInternHtMiss::miss_htx_and_hty);
0155   assert(testObj1.capBlock() == gCapBlockVal);
0156   assert(testObj1.capIndex() == gCapIndexVal);
0157   assert(testObj1.bx() == gBxVal);
0158   assert(testObj1.isThereHtx() == true);
0159   assert(testObj1.isThereHty() == true);
0160   assert(testObj1.raw() == (gRawVal1 & 0x3fffbfff));  // The non-data in the raw data (BC0, etc) is masked off.
0161   assert(testObj1.htx() == 3791);
0162   assert(testObj1.hty() == -1553);
0163   assert(testObj1.overflow() == true);
0164 
0165   L1GctInternHtMiss testObj2 = L1GctInternHtMiss::unpackerMissHtxHty(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal2);
0166   assert(testObj2.raw() == (gRawVal2 & 0x3fffbfff));  // The non-data in the raw data (BC0, etc) is masked off.
0167   assert(testObj2.htx() == 7583);
0168   assert(testObj2.hty() == -1714);
0169   assert(testObj2.overflow() == false);
0170 
0171   L1GctInternHtMiss testObj3(testObj1);  // Copy constructor
0172 
0173   assert(testObj1 == testObj3);  // Test equality & copy ctor.
0174   assert(testObj1 != testObj2);  // Test inequality.
0175 
0176   testObj2 = testObj3;  // Assignment operator
0177 
0178   assert(testObj1 == testObj2);  // Test Assignment operator + equality
0179 
0180   ostringstream oss;
0181   oss << testObj1;
0182   string expectedStr =
0183       " L1GctInternHtMiss:  htx=3791, hty=-1553; overflow set;"
0184       " cap block=0x582, index=3, BX=55";
0185   assert(oss.str() == expectedStr);
0186 }
0187 
0188 void testInequalityOperatorsBetweenCtors() {
0189   L1GctInternHtMiss testObj1 = L1GctInternHtMiss::unpackerMissHtx(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal1);
0190   L1GctInternHtMiss testObj2 = L1GctInternHtMiss::unpackerMissHty(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal1);
0191   L1GctInternHtMiss testObj3 = L1GctInternHtMiss::unpackerMissHtxHty(gCapBlockVal, gCapIndexVal, gBxVal, gRawVal1);
0192 
0193   assert(testObj1 != testObj2);
0194   assert(testObj1 != testObj3);
0195   assert(testObj2 != testObj3);
0196 }