#include #include #include // Unbelievably ugly hack to let me test private methods. #define private public #define protected public #include "IChannelId.hxx" #undef private #undef protected namespace tut { struct baseTChannelId { baseTChannelId() { // Run before each test. } ~baseTChannelId() { // Run after each test. } }; // Declare the test typedef test_group::object testTChannelId; test_group groupTChannelId("IChannelId"); // Test the default constructor and destructor. template<> template<> void testTChannelId::test<1> () { COMET::IChannelId g1(1); COMET::IChannelId g2; g2 = g1; ensure_equals("IChannelId value matchs", g2.AsUInt(), unsigned(1)); ensure("IChannelId values are equal", g1 == g2); } // Test the validity checks in IChannelId. template<> template<> void testTChannelId::test<2> () { COMET::IChannelId g1(0x00000000); ensure("Invalid guard and sub-detector",!g1.IsValid()); COMET::IChannelId g2; g2.SetGuardBit(); ensure("Sub-detector not set", !g2.IsValid()); COMET::IChannelId g3; g3.SetGuardBit(); g3.SetSubDetector(COMET::IChannelId::kMaxDetector); ensure("Sub-detector out of range", !g3.IsValid()); COMET::IChannelId g4; g4.SetSubDetector(COMET::IChannelId::kCTH); ensure("Invalid guard bit", !g4.IsValid()); COMET::IChannelId g5; g5.SetGuardBit(); g5.SetSubDetector(COMET::IChannelId::kCTH); ensure("Valid channel id.", g5.IsValid()); } // Test the kCTH subdetector getter and setter. template<> template<> void testTChannelId::test<3> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(COMET::IChannelId::kCTH); ensure("Valid channel id", g1.IsValid()); ensure_equals("Correct CTH sub-detector value", COMET::IChannelId::kCTH,2); ensure_equals("Correct sub-detector value in channel id", g1.GetSubDetector(),COMET::IChannelId::kCTH); ensure_equals("Correct sub-detector name ", g1.SubDetAsString(),"CTH"); ensure("Is a CTH channel",g1.IsCTHChannel()); ensure("Is not an ECAL channel",!g1.IsECALChannel()); ensure("Is not a StrawTrk channel",!g1.IsStrawTrkChannel()); } /* // Test the kP0D subdetector getter and setter. template<> template<> void testTChannelId::test<3> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(COMET::IChannelId::kP0D); ensure("Valid channel id", g1.IsValid()); ensure_equals("Correct P0D sub-detector value", COMET::IChannelId::kP0D,1); ensure_equals("Correct sub-detector value in channel id", g1.GetSubDetector(),COMET::IChannelId::kP0D); ensure_equals("Correct sub-detector name ", g1.SubDetAsString(),"P0D"); ensure("Is a TFB channel",g1.IsTFBChannel()); ensure("Is not a TPC channel",!g1.IsTPCChannel()); ensure("Is not a FGD channel",!g1.IsFGDChannel()); } // Test the kTPC subdetector getter and setter. template<> template<> void testTChannelId::test<4> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(COMET::IChannelId::kTPC); ensure("Valid channel id", g1.IsValid()); ensure_equals("Correct TPC sub-detector value", COMET::IChannelId::kTPC,2); ensure_equals("Correct sub-detector value in channel id", g1.GetSubDetector(),COMET::IChannelId::kTPC); ensure_equals("Correct sub-detector name ", g1.SubDetAsString(),"TPC"); ensure("Is a TPC channel",g1.IsTPCChannel()); ensure("Is not a TFB channel",!g1.IsTFBChannel()); ensure("Is not a FGD channel",!g1.IsFGDChannel()); } // Test the kFGD subdetector getter and setter. template<> template<> void testTChannelId::test<5> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(COMET::IChannelId::kFGD); ensure("Valid channel id", g1.IsValid()); ensure_equals("Correct FGD sub-detector value", COMET::IChannelId::kFGD,3); ensure_equals("Correct sub-detector value in channel id", g1.GetSubDetector(),COMET::IChannelId::kFGD); ensure_equals("Correct sub-detector name ", g1.SubDetAsString(),"FGD"); ensure("Is a FGD channel",g1.IsFGDChannel()); ensure("Is not a TFB channel",!g1.IsTFBChannel()); ensure("Is not a TPC channel",!g1.IsTPCChannel()); } // Test the kECal subdetector getter and setter. template<> template<> void testTChannelId::test<6> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(COMET::IChannelId::kECal); ensure("Valid channel id", g1.IsValid()); ensure_equals("Correct ECal sub-detector value", COMET::IChannelId::kECal,4); ensure_equals("Correct sub-detector value in channel id", g1.GetSubDetector(),COMET::IChannelId::kECal); ensure_equals("Correct sub-detector name ", g1.SubDetAsString(),"ECal"); ensure("Is a TFB channel",g1.IsTFBChannel()); ensure("Is not a TPC channel",!g1.IsTPCChannel()); ensure("Is not a FGD channel",!g1.IsFGDChannel()); } // Test the kSMRD subdetector getter and setter. template<> template<> void testTChannelId::test<9> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(COMET::IChannelId::kSMRD); ensure("Valid channel id", g1.IsValid()); ensure_equals("Correct SMRD sub-detector value", COMET::IChannelId::kSMRD,7); ensure_equals("Correct sub-detector value in channel id", g1.GetSubDetector(),COMET::IChannelId::kSMRD); ensure_equals("Correct sub-detector name ", g1.SubDetAsString(),"SMRD"); ensure("Is a TFB channel",g1.IsTFBChannel()); ensure("Is not a TPC channel",!g1.IsTPCChannel()); ensure("Is not a FGD channel",!g1.IsFGDChannel()); } // Test the kINGRID subdetector getter and setter. template<> template<> void testTChannelId::test<10> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(COMET::IChannelId::kINGRID); ensure("Valid channel id", g1.IsValid()); ensure_equals("Correct INGRID sub-detector value", COMET::IChannelId::kINGRID,8); ensure_equals("Correct sub-detector value in channel id", g1.GetSubDetector(),COMET::IChannelId::kINGRID); ensure_equals("Correct sub-detector name ", g1.SubDetAsString(),"INGRID"); ensure("Is a TFB channel",g1.IsTFBChannel()); ensure("Is not a TPC channel",!g1.IsTPCChannel()); ensure("Is not a FGD channel",!g1.IsFGDChannel()); } */ // Test that subdetector zero is correctly flaged as a "bad" sub-detector // value, but that the correct value is still saved. template <> template <> void testTChannelId::test<11> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(0); ensure_equals("Set a zero value for sub-detector", g1.GetSubDetector(), 0); ensure("Out of range sub-detector id is not valid", !g1.IsValid()); } // Test that subdetector "kMaxDetector" is correctly flaged as a "bad" // sub-detector value, but that the correct value is still saved. template <> template <> void testTChannelId::test<12> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(COMET::IChannelId::kMaxDetector); ensure_equals("Set a MaxDetector value for sub-detector", g1.GetSubDetector(),COMET::IChannelId::kMaxDetector); ensure("Out of range sub-detector id is not valid", !g1.IsValid()); } // Test out of range detector values. These values cannot be saved in the // bit field, so the field should be set to zero. template <> template <> void testTChannelId::test<13> () { COMET::IChannelId g1; g1.SetGuardBit(); g1.SetSubDetector(-1); ensure_equals("Set a negative value for sub-detector", g1.GetSubDetector(), 0); ensure("Out of range sub-detector id is not valid", !g1.IsValid()); g1.SetSubDetector(99999); ensure_equals("Set a huge value for sub-detector", g1.GetSubDetector(), 0); ensure("Out of range sub-detector id is not valid", !g1.IsValid()); } // Test that the full range of the bit field can be set. template <> template <> void testTChannelId::test<14> () { for (int i=0; i<64; ++i) { COMET::IChannelId g1; g1.SetSubDetector(i); ensure_equals("Sub detector field value saved", g1.GetSubDetector(), i); ensure_equals("Field doesn't over flow", (g1.AsUInt()&COMET::IChannelId::kGuard_Mask), (unsigned) 0); } } };