1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Test of the DictionaryTools functions.
#include "DataFormats/Common/interface/Wrapper.h"
#include "FWCore/Utilities/interface/TypeDemangler.h"
#include "FWCore/Utilities/interface/TypeID.h"
#include "FWCore/Reflection/interface/TypeWithDict.h"
#include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
#include "cppunit/extensions/HelperMacros.h"
#include <typeinfo>
#include <map>
#include <vector>
class TestDictionaries : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(TestDictionaries);
CPPUNIT_TEST(default_is_invalid);
CPPUNIT_TEST(no_dictionary_is_invalid);
CPPUNIT_TEST(not_a_template_instance);
CPPUNIT_TEST(demangling);
CPPUNIT_TEST_SUITE_END();
public:
TestDictionaries() {}
~TestDictionaries() {}
void setUp() {}
void tearDown() {}
void default_is_invalid();
void no_dictionary_is_invalid();
void not_a_template_instance();
void demangling();
private:
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestDictionaries);
void TestDictionaries::default_is_invalid() {
edm::TypeWithDict t;
CPPUNIT_ASSERT(!t);
}
void TestDictionaries::no_dictionary_is_invalid() {
edm::TypeWithDict t(edm::TypeWithDict::byName("ThereIsNoTypeWithThisName"));
CPPUNIT_ASSERT(!t);
}
void TestDictionaries::not_a_template_instance() {
edm::TypeWithDict not_a_template(edm::TypeWithDict::byName("double"));
CPPUNIT_ASSERT(not_a_template);
std::string nonesuch(not_a_template.templateName());
CPPUNIT_ASSERT(nonesuch.empty());
}
namespace {
template <typename T>
void checkIt() {
edm::TypeWithDict type(typeid(T));
// Test only if class has dictionary
if (bool(type)) {
std::string demangledName(edm::typeDemangle(typeid(T).name()));
CPPUNIT_ASSERT(type.name() == demangledName);
edm::TypeID tid(typeid(T));
CPPUNIT_ASSERT(tid.className() == demangledName);
edm::TypeWithDict typeFromName = edm::TypeWithDict::byName(demangledName);
CPPUNIT_ASSERT(typeFromName.name() == demangledName);
if (type.isClass()) {
edm::TypeID tidFromName(typeFromName.typeInfo());
CPPUNIT_ASSERT(tidFromName.className() == demangledName);
}
}
}
template <typename T>
void checkDemangling() {
checkIt<std::vector<T> >();
checkIt<edm::Wrapper<T> >();
checkIt<edm::Wrapper<std::vector<T> > >();
checkIt<T>();
checkIt<T[1]>();
}
} // namespace
void TestDictionaries::demangling() {
checkDemangling<int>();
checkDemangling<unsigned int>();
checkDemangling<unsigned long>();
checkDemangling<long>();
checkDemangling<unsigned long>();
checkDemangling<long long>();
checkDemangling<unsigned long long>();
checkDemangling<short>();
checkDemangling<unsigned short>();
checkDemangling<char>();
checkDemangling<unsigned char>();
checkDemangling<float>();
checkDemangling<double>();
checkDemangling<bool>();
checkDemangling<std::string>();
}
|