Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:48

0001 // Test of the DictionaryTools functions.
0002 
0003 #include "FWCore/Utilities/interface/TypeDemangler.h"
0004 #include "FWCore/Reflection/interface/TypeWithDict.h"
0005 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0006 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0007 
0008 #include "cppunit/extensions/HelperMacros.h"
0009 
0010 #include <typeinfo>
0011 #include <vector>
0012 
0013 class TestDictionaries : public CppUnit::TestFixture {
0014   CPPUNIT_TEST_SUITE(TestDictionaries);
0015   CPPUNIT_TEST(enum_is_valid);
0016   CPPUNIT_TEST(enum_by_name_is_valid);
0017   CPPUNIT_TEST(enum_member_is_valid);
0018   CPPUNIT_TEST(array_member_is_valid);
0019   CPPUNIT_TEST(demangling);
0020   CPPUNIT_TEST_SUITE_END();
0021 
0022 public:
0023   TestDictionaries() {}
0024   ~TestDictionaries() {}
0025   void setUp() {}
0026   void tearDown() {}
0027 
0028   void enum_is_valid();
0029   void enum_by_name_is_valid();
0030   void enum_member_is_valid();
0031   void array_member_is_valid();
0032   void demangling();
0033 
0034 private:
0035 };
0036 
0037 CPPUNIT_TEST_SUITE_REGISTRATION(TestDictionaries);
0038 
0039 void TestDictionaries::enum_is_valid() {
0040   edm::TypeWithDict t(typeid(edmtest::EnumProduct::TheEnumProduct));
0041   CPPUNIT_ASSERT(t);
0042 }
0043 
0044 void TestDictionaries::enum_by_name_is_valid() {
0045   edm::TypeWithDict t = edm::TypeWithDict::byName("edmtest::EnumProduct::TheEnumProduct");
0046   CPPUNIT_ASSERT(t);
0047 }
0048 
0049 void TestDictionaries::enum_member_is_valid() {
0050   edm::TypeWithDict t = edm::TypeWithDict::byName("edmtest::EnumProduct");
0051   edm::MemberWithDict m = t.dataMemberByName("value");
0052   edm::TypeWithDict t2 = m.typeOf();
0053   edm::TypeWithDict t3 = edm::TypeWithDict::byName("edmtest::EnumProduct::TheEnumProduct");
0054   CPPUNIT_ASSERT(t2);
0055   CPPUNIT_ASSERT(t3);
0056   CPPUNIT_ASSERT(t2 == t3);
0057 }
0058 
0059 void TestDictionaries::array_member_is_valid() {
0060   edm::TypeWithDict t = edm::TypeWithDict::byName("edmtest::ArrayProduct");
0061   edm::MemberWithDict m = t.dataMemberByName("value");
0062   CPPUNIT_ASSERT(m.isArray());
0063   edm::TypeWithDict t2 = m.typeOf();
0064   edm::TypeWithDict t3 = edm::TypeWithDict::byName("int[1]");
0065   CPPUNIT_ASSERT(t2);
0066   CPPUNIT_ASSERT(t3);
0067   CPPUNIT_ASSERT(t2.qualifiedName() == "int[1]");
0068   CPPUNIT_ASSERT(t2 == t3);
0069 }
0070 
0071 namespace {
0072   template <typename T>
0073   void checkIt() {
0074     edm::TypeWithDict type(typeid(T));
0075     // Test only if class has dictionary
0076     if (bool(type)) {
0077       std::string demangledName(edm::typeDemangle(typeid(T).name()));
0078       CPPUNIT_ASSERT(type.name() == demangledName);
0079     }
0080   }
0081 
0082   template <typename T>
0083   void checkDemangling() {
0084     checkIt<T>();
0085     checkIt<std::vector<T> >();
0086   }
0087 }  // namespace
0088 
0089 void TestDictionaries::demangling() { checkDemangling<edmtest::EnumProduct::TheEnumProduct>(); }