Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:13

0001 /*
0002  *  datakey_t.cc
0003  *  EDMProto
0004  *
0005  *  Created by Chris Jones on 3/31/05.
0006  *  Changed by Viji Sundararajan on 24-Jun-2005.
0007  */
0008 
0009 #include "cppunit/extensions/HelperMacros.h"
0010 #include <cstring>
0011 #include "FWCore/Framework/interface/DataKey.h"
0012 #include "FWCore/Framework/interface/HCTypeTag.h"
0013 
0014 using namespace edm;
0015 using namespace edm::eventsetup;
0016 
0017 class testDataKey : public CppUnit::TestFixture {
0018   CPPUNIT_TEST_SUITE(testDataKey);
0019 
0020   CPPUNIT_TEST(nametagConstructionTest);
0021   CPPUNIT_TEST(nametagComparisonTest);
0022   CPPUNIT_TEST(nametagCopyTest);
0023   CPPUNIT_TEST(ConstructionTest);
0024   CPPUNIT_TEST(ComparisonTest);
0025   CPPUNIT_TEST(CopyTest);
0026   CPPUNIT_TEST(nocopyConstructionTest);
0027 
0028   CPPUNIT_TEST_SUITE_END();
0029 
0030 public:
0031   void setUp() {}
0032   void tearDown() {}
0033 
0034   void nametagConstructionTest();
0035   void nametagComparisonTest();
0036   void nametagCopyTest();
0037   void ConstructionTest();
0038   void ComparisonTest();
0039   void CopyTest();
0040   void nocopyConstructionTest();
0041 };
0042 
0043 ///registration of the test so that the runner can find it
0044 CPPUNIT_TEST_SUITE_REGISTRATION(testDataKey);
0045 
0046 void testDataKey::nametagConstructionTest() {
0047   const NameTag defaultTag;
0048   CPPUNIT_ASSERT(0 == std::strcmp("", defaultTag.value()));
0049 
0050   const NameTag namedTag("fred");
0051   CPPUNIT_ASSERT(0 == std::strcmp("fred", namedTag.value()));
0052 }
0053 
0054 void testDataKey::nametagComparisonTest() {
0055   const NameTag defaultTag;
0056   CPPUNIT_ASSERT(defaultTag == defaultTag);
0057 
0058   const NameTag fredTag("fred");
0059   CPPUNIT_ASSERT(fredTag == fredTag);
0060 
0061   CPPUNIT_ASSERT(!(defaultTag == fredTag));
0062 
0063   const NameTag barneyTag("barney");
0064 
0065   CPPUNIT_ASSERT(barneyTag < fredTag);
0066 }
0067 
0068 void testDataKey::nametagCopyTest() {
0069   const NameTag defaultTag;
0070   NameTag tester(defaultTag);
0071   CPPUNIT_ASSERT(tester == defaultTag);
0072 
0073   const NameTag fredTag("fred");
0074   tester = fredTag;
0075   CPPUNIT_ASSERT(tester == fredTag);
0076 }
0077 
0078 namespace datakey_t {
0079   class Dummy {};
0080   class Dummy2 {};
0081 }  // namespace datakey_t
0082 using datakey_t::Dummy;
0083 using datakey_t::Dummy2;
0084 
0085 HCTYPETAG_HELPER_METHODS(Dummy)
0086 HCTYPETAG_HELPER_METHODS(Dummy2)
0087 
0088 void testDataKey::ConstructionTest() {
0089   DataKey defaultKey;
0090   CPPUNIT_ASSERT(TypeTag() == defaultKey.type());
0091   CPPUNIT_ASSERT(0 == std::strcmp("", defaultKey.name().value()));
0092 
0093   DataKey dummyKey(DataKey::makeTypeTag<Dummy>(), "");
0094   CPPUNIT_ASSERT(DataKey::makeTypeTag<Dummy>() == dummyKey.type());
0095   CPPUNIT_ASSERT(0 == std::strcmp("", dummyKey.name().value()));
0096 
0097   DataKey namedDummyKey(DataKey::makeTypeTag<Dummy>(), "fred");
0098   CPPUNIT_ASSERT(DataKey::makeTypeTag<Dummy>() == namedDummyKey.type());
0099   CPPUNIT_ASSERT(0 == std::strcmp("fred", namedDummyKey.name().value()));
0100 }
0101 
0102 void testDataKey::ComparisonTest() {
0103   const DataKey defaultKey;
0104   CPPUNIT_ASSERT(defaultKey == defaultKey);
0105   CPPUNIT_ASSERT(!(defaultKey < defaultKey));
0106 
0107   const DataKey dummyKey(DataKey::makeTypeTag<Dummy>(), "");
0108   const DataKey fredDummyKey(DataKey::makeTypeTag<Dummy>(), "fred");
0109   const DataKey barneyDummyKey(DataKey::makeTypeTag<Dummy>(), "barney");
0110 
0111   CPPUNIT_ASSERT(!(defaultKey == dummyKey));
0112   CPPUNIT_ASSERT(dummyKey == dummyKey);
0113   CPPUNIT_ASSERT(!(dummyKey == fredDummyKey));
0114 
0115   CPPUNIT_ASSERT(barneyDummyKey == barneyDummyKey);
0116   CPPUNIT_ASSERT(barneyDummyKey < fredDummyKey);
0117   CPPUNIT_ASSERT(!(fredDummyKey < barneyDummyKey));
0118   CPPUNIT_ASSERT(!(barneyDummyKey == fredDummyKey));
0119 
0120   const DataKey dummy2Key(DataKey::makeTypeTag<Dummy2>(), "");
0121 
0122   CPPUNIT_ASSERT(!(dummy2Key == dummyKey));
0123 }
0124 
0125 void testDataKey::CopyTest() {
0126   const DataKey defaultKey;
0127   DataKey tester(defaultKey);
0128   CPPUNIT_ASSERT(tester == defaultKey);
0129 
0130   const DataKey dummyKey(DataKey::makeTypeTag<Dummy>(), "");
0131   tester = dummyKey;
0132   CPPUNIT_ASSERT(tester == dummyKey);
0133   const DataKey fredDummyKey(DataKey::makeTypeTag<Dummy>(), "fred");
0134   tester = fredDummyKey;
0135   CPPUNIT_ASSERT(tester == fredDummyKey);
0136 
0137   DataKey tester2(fredDummyKey);
0138   CPPUNIT_ASSERT(tester2 == fredDummyKey);
0139 }
0140 
0141 void testDataKey::nocopyConstructionTest() {
0142   const DataKey fredDummyKey(DataKey::makeTypeTag<Dummy>(), "fred");
0143   const DataKey noCopyFredDummyKey(DataKey::makeTypeTag<Dummy>(), "fred", DataKey::kDoNotCopyMemory);
0144 
0145   CPPUNIT_ASSERT(fredDummyKey == noCopyFredDummyKey);
0146 
0147   const DataKey copyFredDummyKey(noCopyFredDummyKey);
0148   CPPUNIT_ASSERT(copyFredDummyKey == noCopyFredDummyKey);
0149 
0150   DataKey copy2FredDummyKey;
0151   copy2FredDummyKey = noCopyFredDummyKey;
0152   CPPUNIT_ASSERT(copy2FredDummyKey == noCopyFredDummyKey);
0153 
0154   DataKey noCopyBarneyDummyKey(DataKey::makeTypeTag<Dummy>(), "barney", DataKey::kDoNotCopyMemory);
0155 
0156   noCopyBarneyDummyKey = noCopyFredDummyKey;
0157   CPPUNIT_ASSERT(noCopyBarneyDummyKey == noCopyFredDummyKey);
0158 }