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: ");
51 virtual void DoRun (
void);
52 enum { HashChainFlag = 0x80000000};
56 :
TestCase (
"Check uniqueness of all TypeIds")
67 cout <<
suite << endl;
73 uint32_t nids = TypeId::GetRegisteredN ();
75 cout <<
suite <<
"UniqueTypeIdTestCase: nids: " << nids << endl;
76 cout <<
suite <<
"TypeId list:" << endl;
77 cout <<
suite <<
"TypeId Chain hash Name" << endl;
79 for (uint16_t i = 0; i < nids; ++i)
81 const TypeId tid = TypeId::GetRegistered (i);
82 cout <<
suite <<
"" << std::setw(6) << tid.
GetUid ();
91 cout <<
" 0x" << std::setfill (
'0') << std::hex << std::setw (8)
92 << tid.
GetHash () << std::dec << std::setfill (
' ')
97 TypeId::LookupByName (tid.
GetName ()).GetUid (),
98 "LookupByName returned different TypeId for " 104 "TypeId .hash and Hash32 (.name) unequal for " 108 TypeId::LookupByHash (tid.
GetHash ()).GetUid (),
109 "LookupByHash returned different TypeId for " 114 cout <<
suite <<
"<-- end TypeId list -->" << endl;
128 virtual void DoRun (
void);
133 :
TestCase (
"Check behavior when type names collide")
144 cout <<
suite << endl;
149 string t1Name =
"daemon";
150 string t2Name =
"unerring";
151 cout <<
suite <<
"creating colliding types " 152 <<
"'" << t1Name <<
"', '" << t2Name <<
"'" 153 <<
" in alphabetical order:" 155 TypeId t1 (t1Name.c_str ());
156 TypeId t2 (t2Name.c_str ());
160 "First and lesser TypeId has HashChainFlag set");
161 cout <<
suite <<
"collision: first,lesser not chained: OK" << endl;
164 "Second and greater TypeId does not have HashChainFlag set");
165 cout <<
suite <<
"collision: second,greater chained: OK" << endl;
170 string t3Name =
"trigonon";
171 string t4Name =
"seriation";
172 cout <<
suite <<
"creating colliding types " 173 <<
"'" << t3Name <<
"', '" << t4Name <<
"'" 174 <<
" in reverse alphabetical order:" 176 TypeId t3 (t3Name.c_str ());
177 TypeId t4 (t4Name.c_str ());
181 "First and greater TypeId does not have HashChainFlag set");
182 cout <<
suite <<
"collision: first,greater chained: OK" << endl;
185 "Second and lesser TypeId has HashChainFlag set");
186 cout <<
suite <<
"collision: second,lesser not chained: OK" << endl;
222 .AddAttribute (
"attribute",
226 MakeIntegerChecker<int> ())
228 .AddAttribute (
"oldAttribute",
232 MakeIntegerChecker<int> (),
234 "use 'attribute' instead")
236 .AddAttribute (
"obsoleteAttribute",
237 "the obsolete attribute",
242 "refactor to use 'attribute'")
245 .AddTraceSource (
"trace",
248 "ns3::TracedValueCallback::Double")
250 .AddTraceSource (
"oldTrace",
251 "the old trace source",
253 "ns3::TracedValueCallback::Double",
255 "use 'trace' instead")
257 .AddTraceSource (
"obsoleteTraceSource",
258 "the obsolete trace source",
260 "ns3::TracedValueCallback::Void",
262 "refactor to use 'trace'");
276 virtual void DoRun (
void);
281 :
TestCase (
"Check deprecated Attributes and TraceSources")
292 cerr <<
suite << endl;
296 cerr <<
suite <<
"DeprecatedAttribute TypeId: " << tid.
GetUid () << endl;
301 "lookup new attribute");
302 cerr <<
suite <<
"lookup new attribute:" 303 << (ainfo.
supportLevel == TypeId::SUPPORTED ?
"supported" :
"error")
307 "lookup old attribute");
308 cerr <<
suite <<
"lookup old attribute:" 309 << (ainfo.
supportLevel == TypeId::DEPRECATED ?
"deprecated" :
"error")
317 cerr <<
suite <<
"lookup new trace source:" 318 << (tinfo.
supportLevel == TypeId::SUPPORTED ?
"supported" :
"error")
323 cerr <<
suite <<
"lookup old trace source:" 324 << (tinfo.
supportLevel == TypeId::DEPRECATED ?
"deprecated" :
"error")
341 void Report (
const std::string how,
const uint32_t delta)
const ;
347 :
TestCase (
"Measure average lookup time")
358 cout <<
suite << endl;
361 uint32_t nids = TypeId::GetRegisteredN ();
363 int start = clock ();
366 for (uint16_t i = 0; i < nids; ++i)
368 const TypeId tid = TypeId::GetRegistered (i);
378 for (uint16_t i = 0; i < nids; ++i)
380 const TypeId tid = TypeId::GetRegistered (i);
392 uint32_t nids = TypeId::GetRegisteredN ();
395 <<
", num TypeId's: " << nids
402 const uint32_t delta)
const 404 double nids = TypeId::GetRegisteredN ();
407 double per = 1E6 * double(delta) / (reps * double(CLOCKS_PER_SEC));
409 cout <<
suite <<
"Lookup time: by " << how <<
": " 410 <<
"ticks: " << delta
412 <<
" microsec/lookup" 452 :
TestSuite (
"type-id-perf", PERFORMANCE)
virtual ~DeprecatedAttribute()
uint32_t GetHash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer.
std::string GetName(void) const
Get the name.
Serious error messages only.
static TypeIdTestSuite g_TypeIdTestSuite
hash_t GetHash(void) const
Get the hash.
Smart pointer class similar to boost::intrusive_ptr.
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Hold a signed integer type.
virtual void DoRun(void)
Implementation to actually run this TestCase.
#define NS_UNUSED(x)
Mark a local variable as unused.
static TypeIdPerformanceSuite g_TypeIdPerformanceSuite
static Ptr< const AttributeAccessor > MakeEmptyAttributeAccessor()
Create an empty AttributeAccessor.
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
DeprecatedAttributeTestCase()
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual ~CollisionTestCase()
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual ~LookupTimeTestCase()
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
A class for an empty attribute value.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
#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.
virtual ~UniqueTypeIdTestCase()
void DoRun(void)
Implementation to actually run this TestCase.
uint16_t GetUid(void) const
Get the internal id of this TypeId.
void DoSetup(void)
Implementation to do any local setup required for this TestCase.
Hasher & clear(void)
Restore initial state.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Report(const std::string how, const uint32_t delta) const
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~DeprecatedAttributeTestCase()
LogLevel
Logging severity classes and levels.
const std::string suite("type-id: ")
std::string GetName(void) const
#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...
Prefix all trace prints with function.
TracedValue< double > m_trace
static Ptr< AttributeChecker > MakeEmptyAttributeChecker()
Create an empty AttributeChecker.
A base class which provides memory management and object aggregation.
static Ptr< const TraceSourceAccessor > MakeEmptyTraceSourceAccessor()
Create an empty TraceSourceAccessor.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
static TypeId GetTypeId(void)
Generic Hash function interface.