25 #include "ns3/integer.h"
26 #include "ns3/double.h"
27 #include "ns3/object.h"
28 #include "ns3/traced-value.h"
29 #include "ns3/type-id.h"
32 #include "ns3/unused.h"
39 const std::string
suite (
"type-id: ");
52 virtual void DoRun (
void);
55 HashChainFlag = 0x80000000
60 :
TestCase (
"Check uniqueness of all TypeIds")
69 cout <<
suite << endl;
75 uint32_t nids = TypeId::GetRegisteredN ();
77 cout <<
suite <<
"UniqueTypeIdTestCase: nids: " << nids << endl;
78 cout <<
suite <<
"TypeId list:" << endl;
79 cout <<
suite <<
"TypeId Chain hash Name" << endl;
81 for (uint16_t i = 0; i < nids; ++i)
83 const TypeId tid = TypeId::GetRegistered (i);
84 cout <<
suite <<
"" << std::setw (6) << tid.
GetUid ();
93 cout <<
" 0x" << std::setfill (
'0') << std::hex << std::setw (8)
94 << tid.
GetHash () << std::dec << std::setfill (
' ')
99 TypeId::LookupByName (tid.
GetName ()).GetUid (),
100 "LookupByName returned different TypeId for "
106 "TypeId .hash and Hash32 (.name) unequal for "
110 TypeId::LookupByHash (tid.
GetHash ()).GetUid (),
111 "LookupByHash returned different TypeId for "
116 cout <<
suite <<
"<-- end TypeId list -->" << endl;
131 virtual void DoRun (
void);
139 :
TestCase (
"Check behavior when type names collide")
148 cout <<
suite << endl;
153 string t1Name =
"daemon";
154 string t2Name =
"unerring";
155 cout <<
suite <<
"creating colliding types "
156 <<
"'" << t1Name <<
"', '" << t2Name <<
"'"
157 <<
" in alphabetical order:"
159 TypeId t1 (t1Name.c_str ());
160 TypeId t2 (t2Name.c_str ());
164 "First and lesser TypeId has HashChainFlag set");
165 cout <<
suite <<
"collision: first,lesser not chained: OK" << endl;
168 "Second and greater TypeId does not have HashChainFlag set");
169 cout <<
suite <<
"collision: second,greater chained: OK" << endl;
174 string t3Name =
"trigonon";
175 string t4Name =
"seriation";
176 cout <<
suite <<
"creating colliding types "
177 <<
"'" << t3Name <<
"', '" << t4Name <<
"'"
178 <<
" in reverse alphabetical order:"
180 TypeId t3 (t3Name.c_str ());
181 TypeId t4 (t4Name.c_str ());
185 "First and greater TypeId does not have HashChainFlag set");
186 cout <<
suite <<
"collision: first,greater chained: OK" << endl;
189 "Second and lesser TypeId has HashChainFlag set");
190 cout <<
suite <<
"collision: second,lesser not chained: OK" << endl;
231 .AddAttribute (
"attribute",
235 MakeIntegerChecker<int> ())
237 .AddAttribute (
"oldAttribute",
241 MakeIntegerChecker<int> (),
243 "use 'attribute' instead")
245 .AddAttribute (
"obsoleteAttribute",
246 "the obsolete attribute",
251 "refactor to use 'attribute'")
254 .AddTraceSource (
"trace",
257 "ns3::TracedValueCallback::Double")
259 .AddTraceSource (
"oldTrace",
260 "the old trace source",
262 "ns3::TracedValueCallback::Double",
264 "use 'trace' instead")
266 .AddTraceSource (
"obsoleteTraceSource",
267 "the obsolete trace source",
269 "ns3::TracedValueCallback::Void",
271 "refactor to use 'trace'");
286 virtual void DoRun (
void);
291 :
TestCase (
"Check deprecated Attributes and TraceSources")
300 cerr <<
suite << endl;
304 cerr <<
suite <<
"DeprecatedAttribute TypeId: " << tid.
GetUid () << endl;
309 "lookup new attribute");
310 cerr <<
suite <<
"lookup new attribute:"
311 << (ainfo.
supportLevel == TypeId::SUPPORTED ?
"supported" :
"error")
315 "lookup old attribute");
316 cerr <<
suite <<
"lookup old attribute:"
317 << (ainfo.
supportLevel == TypeId::DEPRECATED ?
"deprecated" :
"error")
325 cerr <<
suite <<
"lookup new trace source:"
326 << (tinfo.
supportLevel == TypeId::SUPPORTED ?
"supported" :
"error")
331 cerr <<
suite <<
"lookup old trace source:"
332 << (tinfo.
supportLevel == TypeId::DEPRECATED ?
"deprecated" :
"error")
350 void Report (
const std::string how,
const uint32_t delta)
const;
359 :
TestCase (
"Measure average lookup time")
368 cout <<
suite << endl;
371 uint32_t nids = TypeId::GetRegisteredN ();
373 int start = clock ();
376 for (uint16_t i = 0; i < nids; ++i)
378 const TypeId tid = TypeId::GetRegistered (i);
388 for (uint16_t i = 0; i < nids; ++i)
390 const TypeId tid = TypeId::GetRegistered (i);
402 uint32_t nids = TypeId::GetRegisteredN ();
405 <<
", num TypeId's: " << nids
412 const uint32_t delta)
const
414 double nids = TypeId::GetRegisteredN ();
417 double per = 1E6 * double(delta) / (reps * double(CLOCKS_PER_SEC));
419 cout <<
suite <<
"Lookup time: by " << how <<
": "
420 <<
"ticks: " << delta
422 <<
" microsec/lookup"
462 :
TestSuite (
"type-id-perf", PERFORMANCE)
virtual ~CollisionTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~DeprecatedAttribute()
static TypeId GetTypeId(void)
TracedValue< double > m_trace
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~DeprecatedAttributeTestCase()
DeprecatedAttributeTestCase()
virtual ~LookupTimeTestCase()
void DoSetup(void)
Implementation to do any local setup required for this TestCase.
void Report(const std::string how, const uint32_t delta) const
void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~UniqueTypeIdTestCase()
A class for an empty attribute value.
Generic Hash function interface.
uint32_t GetHash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer.
Hasher & clear(void)
Restore initial state.
Hold a signed integer type.
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
std::string GetName(void) const
a unique identifier for an interface.
uint16_t GetUid(void) const
Get the internal id of this TypeId.
hash_t GetHash(void) const
Get the hash.
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName(void) const
Get the name.
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
static Ptr< AttributeChecker > MakeEmptyAttributeChecker()
Create an empty AttributeChecker.
static Ptr< const AttributeAccessor > MakeEmptyAttributeAccessor()
Create an empty AttributeAccessor.
#define NS_UNUSED(x)
Mark a local variable as unused.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
static Ptr< const TraceSourceAccessor > MakeEmptyTraceSourceAccessor()
Create an empty TraceSourceAccessor.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LogLevel
Logging severity classes and levels.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_ERROR
Serious error messages only.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
const std::string suite("type-id: ")
static TypeIdTestSuite g_TypeIdTestSuite
static TypeIdPerformanceSuite g_TypeIdPerformanceSuite