File indexing completed on 2024-04-06 12:13:14
0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include <string>
0003
0004 #include "FWCore/Utilities/interface/EDMException.h"
0005 #include "FWCore/Utilities/interface/ESInputTag.h"
0006
0007 class testESInputTag : public CppUnit::TestFixture {
0008 CPPUNIT_TEST_SUITE(testESInputTag);
0009 CPPUNIT_TEST(emptyTags);
0010 CPPUNIT_TEST(twoStringConstructor);
0011 CPPUNIT_TEST(encodedTags);
0012 CPPUNIT_TEST(mixedConstructors);
0013 CPPUNIT_TEST_SUITE_END();
0014
0015 public:
0016 void setUp() {}
0017 void tearDown() {}
0018
0019 void emptyTags();
0020 void twoStringConstructor();
0021 void encodedTags();
0022 void mixedConstructors();
0023 };
0024
0025
0026 CPPUNIT_TEST_SUITE_REGISTRATION(testESInputTag);
0027
0028 using edm::ESInputTag;
0029 using namespace std::string_literals;
0030
0031 void testESInputTag::emptyTags() {
0032 auto require_empty = [](ESInputTag const& tag) {
0033 CPPUNIT_ASSERT(tag.module().empty());
0034 CPPUNIT_ASSERT(tag.data().empty());
0035 };
0036
0037 ESInputTag const empty1{};
0038 ESInputTag const empty2{""};
0039 ESInputTag const empty3{":"};
0040 ESInputTag const empty4{"", ""};
0041
0042 require_empty(empty1);
0043 require_empty(empty2);
0044 require_empty(empty3);
0045 require_empty(empty4);
0046
0047
0048 CPPUNIT_ASSERT_EQUAL(empty1, empty2);
0049 CPPUNIT_ASSERT_EQUAL(empty1, empty3);
0050 CPPUNIT_ASSERT_EQUAL(empty1, empty4);
0051 }
0052
0053 void testESInputTag::twoStringConstructor() {
0054 ESInputTag const tag{"ML", "DL"};
0055 CPPUNIT_ASSERT_EQUAL(tag.module(), "ML"s);
0056 CPPUNIT_ASSERT_EQUAL(tag.data(), "DL"s);
0057 }
0058
0059 void testESInputTag::encodedTags() {
0060 auto require_labels = [](ESInputTag const& tag, std::string const& module_label, std::string const& data_label) {
0061 CPPUNIT_ASSERT_EQUAL(tag.module(), module_label);
0062 CPPUNIT_ASSERT_EQUAL(tag.data(), data_label);
0063 };
0064
0065 ESInputTag const moduleOnlywToken{"ML:"};
0066 ESInputTag const dataOnlywToken{":DL"};
0067 ESInputTag const bothFields{"ML:DL"};
0068
0069 require_labels(moduleOnlywToken, "ML", "");
0070 require_labels(dataOnlywToken, "", "DL");
0071 require_labels(bothFields, "ML", "DL");
0072
0073
0074 CPPUNIT_ASSERT_THROW((ESInputTag{"ML:DL:"}), cms::Exception);
0075 CPPUNIT_ASSERT_THROW((ESInputTag{"ML"}), cms::Exception);
0076 }
0077
0078 void testESInputTag::mixedConstructors() {
0079
0080 CPPUNIT_ASSERT_EQUAL((ESInputTag{"", "DL"}), (ESInputTag{":DL"}));
0081
0082
0083 CPPUNIT_ASSERT_EQUAL((ESInputTag{"ML", ""}), (ESInputTag{"ML:"}));
0084
0085
0086 CPPUNIT_ASSERT_EQUAL((ESInputTag{"ML", "DL"}), (ESInputTag{"ML:DL"}));
0087 }