File indexing completed on 2025-06-17 01:30:10
0001
0002
0003 #include "DataFormats/Common/interface/Wrapper.h"
0004 #include "FWCore/Utilities/interface/TypeDemangler.h"
0005 #include "FWCore/Utilities/interface/TypeID.h"
0006 #include "FWCore/Reflection/interface/TypeWithDict.h"
0007 #include "catch.hpp"
0008 #include <typeinfo>
0009 #include <map>
0010 #include <vector>
0011 #include <string>
0012
0013
0014 namespace {
0015 template <typename T>
0016 void checkIt() {
0017 edm::TypeWithDict type(typeid(T));
0018 if (bool(type)) {
0019 std::string demangledName(edm::typeDemangle(typeid(T).name()));
0020 REQUIRE(type.name() == demangledName);
0021 edm::TypeID tid(typeid(T));
0022 REQUIRE(tid.className() == demangledName);
0023 edm::TypeWithDict typeFromName = edm::TypeWithDict::byName(demangledName);
0024 REQUIRE(typeFromName.name() == demangledName);
0025 if (type.isClass()) {
0026 edm::TypeID tidFromName(typeFromName.typeInfo());
0027 REQUIRE(tidFromName.className() == demangledName);
0028 }
0029 }
0030 }
0031 template <typename T>
0032 void checkDemangling() {
0033 checkIt<std::vector<T> >();
0034 checkIt<edm::Wrapper<T> >();
0035 checkIt<edm::Wrapper<std::vector<T> > >();
0036 checkIt<T>();
0037 checkIt<T[1]>();
0038 }
0039 }
0040
0041 TEST_CASE("DictionaryTools functions", "[DictionaryTools]") {
0042 SECTION("default_is_invalid") {
0043 edm::TypeWithDict t;
0044 REQUIRE(!t);
0045 }
0046
0047 SECTION("no_dictionary_is_invalid") {
0048 edm::TypeWithDict t(edm::TypeWithDict::byName("ThereIsNoTypeWithThisName"));
0049 REQUIRE(!t);
0050 }
0051
0052 SECTION("not_a_template_instance") {
0053 edm::TypeWithDict not_a_template(edm::TypeWithDict::byName("double"));
0054 REQUIRE(not_a_template);
0055 std::string nonesuch(not_a_template.templateName());
0056 REQUIRE(nonesuch.empty());
0057 }
0058
0059 SECTION("demangling") {
0060 checkDemangling<int>();
0061 checkDemangling<unsigned int>();
0062 checkDemangling<unsigned long>();
0063 checkDemangling<long>();
0064 checkDemangling<unsigned long>();
0065 checkDemangling<long long>();
0066 checkDemangling<unsigned long long>();
0067 checkDemangling<short>();
0068 checkDemangling<unsigned short>();
0069 checkDemangling<char>();
0070 checkDemangling<unsigned char>();
0071 checkDemangling<float>();
0072 checkDemangling<double>();
0073 checkDemangling<bool>();
0074 checkDemangling<std::string>();
0075 }
0076 }