Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:05

0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003 
0004 #include "DataFormats/Provenance/interface/ElementID.h"
0005 
0006 #include <sstream>
0007 
0008 TEST_CASE("ElementID", "[ElementID]") {
0009   SECTION("Default construction is invalid") { REQUIRE(edm::ElementID{}.isValid() == false); }
0010 
0011   SECTION("Basic operations") {
0012     edm::ElementID id{edm::ProductID{1, 2}, 3};
0013     REQUIRE(id.isValid() == true);
0014     REQUIRE(id.id() == edm::ProductID{1, 2});
0015     REQUIRE(id.key() == 3);
0016     REQUIRE(id.index() == 3);
0017 
0018     edm::ElementID id2;
0019     edm::swap(id, id2);
0020     REQUIRE(id.isValid() == false);
0021     REQUIRE(id2.id() == edm::ProductID{1, 2});
0022     REQUIRE(id2.key() == 3);
0023     REQUIRE(id2.index() == 3);
0024 
0025     REQUIRE(id2 == edm::ElementID{edm::ProductID{1, 2}, 3});
0026     REQUIRE(id2 != edm::ElementID{edm::ProductID{2, 2}, 3});
0027     REQUIRE(id2 != edm::ElementID{edm::ProductID{1, 3}, 3});
0028     REQUIRE(id2 != edm::ElementID{edm::ProductID{1, 2}, 4});
0029 
0030     REQUIRE(id2 < edm::ElementID{edm::ProductID{1, 2}, 4});
0031     REQUIRE(id2 < edm::ElementID{edm::ProductID{1, 3}, 3});
0032     REQUIRE(id2 < edm::ElementID{edm::ProductID{2, 2}, 3});
0033 
0034     REQUIRE(not(id2 < id2));
0035 
0036     REQUIRE(edm::ElementID{edm::ProductID{1, 2}, 2} < id2);
0037     REQUIRE(edm::ElementID{edm::ProductID{1, 1}, 3} < id2);
0038     REQUIRE(edm::ElementID{edm::ProductID{0, 2}, 3} < id2);
0039 
0040     std::stringstream ss;
0041     ss << id2;
0042     REQUIRE(ss.str() == "1:2:3");
0043 
0044     id2.reset();
0045     REQUIRE(id2.isValid() == false);
0046   }
0047 }