Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:48:02

0001 #include "catch.hpp"
0002 #include "FWCore/Utilities/interface/InputTag.h"
0003 #include "FWCore/Utilities/interface/TypeID.h"
0004 
0005 #include <cstdlib>
0006 #include <iostream>
0007 #include <string>
0008 
0009 namespace edm {
0010   class ProductRegistry;
0011 }
0012 
0013 namespace {
0014   class TypeToTestInputTag1 {};
0015   class TypeToTestInputTag2 {};
0016 }  // namespace
0017 
0018 TEST_CASE("test edm::InputTag", "[InputTag]") {
0019   constexpr TypeToTestInputTag1 typeToTestInputTag1;
0020   constexpr TypeToTestInputTag2 typeToTestInputTag2;
0021 
0022   const edm::TypeID testTypeID1(typeToTestInputTag1);
0023   const edm::TypeID testTypeID2(typeToTestInputTag2);
0024 
0025   SECTION("default constructor") {
0026     const edm::InputTag tag1;
0027 
0028     REQUIRE(tag1.label() == "");
0029     REQUIRE(tag1.instance() == "");
0030     REQUIRE(tag1.process() == "");
0031     REQUIRE(not tag1.willSkipCurrentProcess());
0032   }
0033 
0034   SECTION("InputTag(string,string,string)") {
0035     const edm::InputTag tag2(std::string("a"), std::string("b"), std::string("c"));
0036     REQUIRE(tag2.label() == "a");
0037     REQUIRE(tag2.instance() == "b");
0038     REQUIRE(tag2.process() == "c");
0039     REQUIRE(not tag2.willSkipCurrentProcess());
0040   }
0041 
0042   SECTION("InputTag(char*,char*,char*)") {
0043     const edm::InputTag tag3("d", "e", "f");
0044     REQUIRE(tag3.label() == "d");
0045     REQUIRE(tag3.instance() == "e");
0046     REQUIRE(tag3.process() == "f");
0047     REQUIRE(not tag3.willSkipCurrentProcess());
0048   }
0049 
0050   SECTION("InputTag(string) 3 parts") {
0051     const edm::InputTag tag4("g:h:i");
0052     REQUIRE(tag4.label() == "g");
0053     REQUIRE(tag4.instance() == "h");
0054     REQUIRE(tag4.process() == "i");
0055     REQUIRE(not tag4.willSkipCurrentProcess());
0056   }
0057 
0058   SECTION("InputTag(string) 2 parts") {
0059     const edm::InputTag tag5("g:h");
0060     REQUIRE(tag5.label() == "g");
0061     REQUIRE(tag5.instance() == "h");
0062     REQUIRE(tag5.process() == "");
0063     REQUIRE(not tag5.willSkipCurrentProcess());
0064   }
0065 
0066   SECTION("InputTag(string) 1 part") {
0067     const edm::InputTag tag6("g");
0068     REQUIRE(tag6.label() == "g");
0069     REQUIRE(tag6.instance() == "");
0070     REQUIRE(tag6.process() == "");
0071     REQUIRE(not tag6.willSkipCurrentProcess());
0072   }
0073 
0074   SECTION("operator==") {
0075     const edm::InputTag tag2(std::string("a"), std::string("b"), std::string("c"));
0076     const edm::InputTag tag4("g:h:i");
0077     const edm::InputTag tag5("g:h");
0078     const edm::InputTag tag6("g");
0079     const edm::InputTag tag7(std::string("a"), std::string("b"), std::string("c"));
0080     const edm::InputTag tag8(std::string("x"), std::string("b"), std::string("c"));
0081     REQUIRE(tag2 == tag7);
0082     REQUIRE(!(tag4 == tag5));
0083     REQUIRE(!(tag5 == tag6));
0084     REQUIRE(!(tag7 == tag8));
0085   }
0086 
0087   SECTION("encode") {
0088     const edm::InputTag tag5("g:h");
0089     const edm::InputTag tag6("g");
0090     const edm::InputTag tag7(std::string("a"), std::string("b"), std::string("c"));
0091 
0092     REQUIRE(tag7.encode() == std::string("a:b:c"));
0093     REQUIRE(tag5.encode() == std::string("g:h"));
0094     REQUIRE(tag6.encode() == std::string("g"));
0095   }
0096 
0097   SECTION("copy ctr") {
0098     const edm::InputTag tag8(std::string("x"), std::string("b"), std::string("c"));
0099     const edm::InputTag tag9(tag8);
0100     REQUIRE(tag8 == tag9);
0101   }
0102   SECTION("move ctr") {
0103     const edm::InputTag tag7(std::string("a"), std::string("b"), std::string("c"));
0104     edm::InputTag tag11("a:b:c");
0105     const edm::InputTag tag10(std::move(tag11));
0106     REQUIRE(tag10 == tag7);
0107   }
0108   SECTION("operator=") {
0109     edm::InputTag tag6("g");
0110     const edm::InputTag tag10("a:b:c");
0111     tag6 = tag10;
0112     REQUIRE(tag10 == tag6);
0113   }
0114   SECTION("move operator=") {
0115     const edm::InputTag tag10("a:b:c");
0116     edm::InputTag tag5("g:h");
0117     tag5 = edm::InputTag("a:b:c");
0118     REQUIRE(tag5 == tag10);
0119   }
0120 
0121   SECTION("skipCurrentProcess") {
0122     SECTION("construct with char*") {
0123       const edm::InputTag tag12("d", "e", "@skipCurrentProcess");
0124       REQUIRE(tag12.label() == "d");
0125       REQUIRE(tag12.instance() == "e");
0126       REQUIRE(tag12.process() == "@skipCurrentProcess");
0127       REQUIRE(tag12.willSkipCurrentProcess());
0128     }
0129     SECTION("construct with std::string") {
0130       const edm::InputTag tag12a(std::string("d"), std::string("e"), std::string("@skipCurrentProcess"));
0131       REQUIRE(tag12a.label() == "d");
0132       REQUIRE(tag12a.instance() == "e");
0133       REQUIRE(tag12a.process() == "@skipCurrentProcess");
0134       REQUIRE(tag12a.willSkipCurrentProcess());
0135     }
0136     const edm::InputTag tag12b("d:e:@skipCurrentProcess");
0137     SECTION("construct with one value") {
0138       REQUIRE(tag12b.label() == "d");
0139       REQUIRE(tag12b.instance() == "e");
0140       REQUIRE(tag12b.process() == "@skipCurrentProcess");
0141       REQUIRE(tag12b.willSkipCurrentProcess());
0142     }
0143     SECTION("copy ctr") {
0144       const edm::InputTag tag12c(tag12b);
0145       REQUIRE(tag12c.willSkipCurrentProcess());
0146     }
0147     SECTION("operator=") {
0148       edm::InputTag tag12d;
0149       const edm::InputTag tag12a(std::string("d"), std::string("e"), std::string("@skipCurrentProcess"));
0150       tag12d = tag12a;
0151       REQUIRE(tag12d.willSkipCurrentProcess());
0152     }
0153     SECTION("test wrong tag") {
0154       const edm::InputTag tag13("d", "e", "@skipCurrentProcessx");
0155       REQUIRE(not tag13.willSkipCurrentProcess());
0156 
0157       const edm::InputTag tag14("d", "e", "@skipCurrentProces");
0158       REQUIRE(not tag14.willSkipCurrentProcess());
0159 
0160       const edm::InputTag tag15("d", "e", "@skipCurrentProcesx");
0161       REQUIRE(not tag15.willSkipCurrentProcess());
0162     }
0163   }
0164   SECTION("indexFor") {
0165     // This is just for the test. Do not dereference the pointers.
0166     // They points to nothing legal.
0167     edm::ProductRegistry* reg1 = reinterpret_cast<edm::ProductRegistry*>(1);
0168     edm::ProductRegistry* reg2 = reinterpret_cast<edm::ProductRegistry*>(2);
0169 
0170     edm::InputTag tag5("g:h");
0171 
0172     unsigned int index = tag5.indexFor(testTypeID1, edm::InRun, reg1);
0173     REQUIRE(index == edm::ProductResolverIndexInvalid);
0174 
0175     tag5.tryToCacheIndex(5, testTypeID1, edm::InRun, reg1);
0176     tag5.tryToCacheIndex(6, testTypeID1, edm::InRun, reg1);
0177 
0178     index = tag5.indexFor(testTypeID1, edm::InRun, reg1);
0179     REQUIRE(index == 5);
0180 
0181     REQUIRE(tag5.indexFor(testTypeID1, edm::InLumi, reg1) == edm::ProductResolverIndexInvalid);
0182     REQUIRE(tag5.indexFor(testTypeID1, edm::InRun, reg2) == edm::ProductResolverIndexInvalid);
0183     REQUIRE(tag5.indexFor(testTypeID2, edm::InRun, reg1) == edm::ProductResolverIndexInvalid);
0184   }
0185 }