Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:36

0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003 #include "FWCore/Common/interface/TriggerNames.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include <memory>
0006 
0007 TEST_CASE("Test TriggerNames", "[TriggerNames]") {
0008   edm::ParameterSet pset;
0009   const std::vector<std::string> names = {{"b1"}, {"b2"}, {"a1"}, {"z5"}};
0010   pset.addParameter<std::vector<std::string>>("@trigger_paths", names);
0011   pset.registerIt();
0012 
0013   SECTION("Default constructed") {
0014     edm::TriggerNames defaultConst;
0015 
0016     REQUIRE(defaultConst.size() == 0);
0017     REQUIRE(defaultConst.triggerNames().empty());
0018     REQUIRE(defaultConst.triggerIndex("not here") == defaultConst.size());
0019     REQUIRE_THROWS_AS(defaultConst.triggerName(0), std::exception);
0020   }
0021 
0022   SECTION("No names") {
0023     edm::ParameterSet pset;
0024     const std::vector<std::string> names;
0025     pset.addParameter<std::vector<std::string>>("@trigger_paths", names);
0026     pset.registerIt();
0027 
0028     edm::TriggerNames noNames(pset);
0029 
0030     REQUIRE(noNames.size() == 0);
0031     REQUIRE(noNames.triggerNames().empty());
0032     REQUIRE(noNames.parameterSetID() == pset.id());
0033     REQUIRE(noNames.triggerIndex("not here") == noNames.size());
0034     REQUIRE_THROWS_AS(noNames.triggerName(0), std::exception);
0035   }
0036 
0037   SECTION("multiple names") {
0038     edm::TriggerNames tNames(pset);
0039 
0040     REQUIRE(tNames.size() == names.size());
0041     REQUIRE(tNames.triggerNames() == names);
0042     REQUIRE(tNames.parameterSetID() == pset.id());
0043     REQUIRE(tNames.triggerIndex("not here") == tNames.size());
0044     REQUIRE(tNames.triggerIndex("b1") == 0);
0045     REQUIRE(tNames.triggerIndex("b2") == 1);
0046     REQUIRE(tNames.triggerIndex("a1") == 2);
0047     REQUIRE(tNames.triggerIndex("z5") == 3);
0048     REQUIRE(tNames.triggerName(0) == "b1");
0049     REQUIRE(tNames.triggerName(1) == "b2");
0050     REQUIRE(tNames.triggerName(2) == "a1");
0051     REQUIRE(tNames.triggerName(3) == "z5");
0052     REQUIRE_THROWS_AS(tNames.triggerName(names.size()), std::exception);
0053   }
0054 
0055   SECTION("copy constructor") {
0056     auto temp = std::make_unique<edm::TriggerNames>(pset);
0057 
0058     edm::TriggerNames tNames(*temp);
0059     temp.release();
0060 
0061     REQUIRE(tNames.size() == names.size());
0062     REQUIRE(tNames.triggerNames() == names);
0063     REQUIRE(tNames.parameterSetID() == pset.id());
0064     REQUIRE(tNames.triggerIndex("not here") == tNames.size());
0065     REQUIRE(tNames.triggerIndex("b1") == 0);
0066     REQUIRE(tNames.triggerIndex("b2") == 1);
0067     REQUIRE(tNames.triggerIndex("a1") == 2);
0068     REQUIRE(tNames.triggerIndex("z5") == 3);
0069     REQUIRE(tNames.triggerName(0) == "b1");
0070     REQUIRE(tNames.triggerName(1) == "b2");
0071     REQUIRE(tNames.triggerName(2) == "a1");
0072     REQUIRE(tNames.triggerName(3) == "z5");
0073     REQUIRE_THROWS_AS(tNames.triggerName(names.size()), std::exception);
0074   }
0075 
0076   SECTION("move constructor") {
0077     auto temp = std::make_unique<edm::TriggerNames>(pset);
0078 
0079     edm::TriggerNames tNames(std::move(*temp));
0080     temp.release();
0081 
0082     REQUIRE(tNames.size() == names.size());
0083     REQUIRE(tNames.triggerNames() == names);
0084     REQUIRE(tNames.parameterSetID() == pset.id());
0085     REQUIRE(tNames.triggerIndex("not here") == tNames.size());
0086     REQUIRE(tNames.triggerIndex("b1") == 0);
0087     REQUIRE(tNames.triggerIndex("b2") == 1);
0088     REQUIRE(tNames.triggerIndex("a1") == 2);
0089     REQUIRE(tNames.triggerIndex("z5") == 3);
0090     REQUIRE(tNames.triggerName(0) == "b1");
0091     REQUIRE(tNames.triggerName(1) == "b2");
0092     REQUIRE(tNames.triggerName(2) == "a1");
0093     REQUIRE(tNames.triggerName(3) == "z5");
0094     REQUIRE_THROWS_AS(tNames.triggerName(names.size()), std::exception);
0095   }
0096 
0097   SECTION("operator=") {
0098     auto temp = std::make_unique<edm::TriggerNames>(pset);
0099 
0100     edm::TriggerNames tNames;
0101     tNames = (*temp);
0102     temp.release();
0103 
0104     REQUIRE(tNames.size() == names.size());
0105     REQUIRE(tNames.triggerNames() == names);
0106     REQUIRE(tNames.parameterSetID() == pset.id());
0107     REQUIRE(tNames.triggerIndex("not here") == tNames.size());
0108     REQUIRE(tNames.triggerIndex("b1") == 0);
0109     REQUIRE(tNames.triggerIndex("b2") == 1);
0110     REQUIRE(tNames.triggerIndex("a1") == 2);
0111     REQUIRE(tNames.triggerIndex("z5") == 3);
0112     REQUIRE(tNames.triggerName(0) == "b1");
0113     REQUIRE(tNames.triggerName(1) == "b2");
0114     REQUIRE(tNames.triggerName(2) == "a1");
0115     REQUIRE(tNames.triggerName(3) == "z5");
0116     REQUIRE_THROWS_AS(tNames.triggerName(names.size()), std::exception);
0117   }
0118 
0119   SECTION("operator= with move") {
0120     auto temp = std::make_unique<edm::TriggerNames>(pset);
0121 
0122     edm::TriggerNames tNames;
0123     tNames = std::move(*temp);
0124     temp.release();
0125 
0126     REQUIRE(tNames.size() == names.size());
0127     REQUIRE(tNames.triggerNames() == names);
0128     REQUIRE(tNames.parameterSetID() == pset.id());
0129     REQUIRE(tNames.triggerIndex("not here") == tNames.size());
0130     REQUIRE(tNames.triggerIndex("b1") == 0);
0131     REQUIRE(tNames.triggerIndex("b2") == 1);
0132     REQUIRE(tNames.triggerIndex("a1") == 2);
0133     REQUIRE(tNames.triggerIndex("z5") == 3);
0134     REQUIRE(tNames.triggerName(0) == "b1");
0135     REQUIRE(tNames.triggerName(1) == "b2");
0136     REQUIRE(tNames.triggerName(2) == "a1");
0137     REQUIRE(tNames.triggerName(3) == "z5");
0138     REQUIRE_THROWS_AS(tNames.triggerName(names.size()), std::exception);
0139   }
0140 }