25 #include "ns3/type-id.h" 
   34 const std::string 
suite(
"type-id: ");
 
   46   virtual void DoRun (
void);
 
   47   enum { HashChainFlag = 0x80000000};
 
   51   : 
TestCase (
"Check uniqueness of all TypeIds")
 
   62   cout << 
suite << endl;
 
   68   uint32_t nids = TypeId::GetRegisteredN ();
 
   70   cout << 
suite << 
"UniqueTypeIdTestCase: nids: " << nids << endl;
 
   71   cout << 
suite << 
"TypeId list:" << endl;
 
   72   cout << 
suite << 
"TypeId  Chain  hash          Name" << endl;
 
   74   for (uint32_t i = 0; i < nids; ++i)
 
   76       const TypeId tid = TypeId::GetRegistered (i);
 
   77       cout << 
suite << 
"" << std::setw(6) << tid.
GetUid ();
 
   86       cout << 
"  0x"     << std::setfill (
'0') << std::hex << std::setw (8)
 
   87            << tid.
GetHash () << std::dec << std::setfill (
' ')
 
   92                              TypeId::LookupByName (tid.
GetName ()).GetUid (),
 
   93                              "LookupByName returned different TypeId for " 
   99                              "TypeId .hash and Hash32 (.name) unequal for " 
  103                              TypeId::LookupByHash (tid.
GetHash ()).GetUid (),
 
  104                              "LookupByHash returned different TypeId for " 
  109   cout << 
suite << 
"<-- end TypeId list -->" << endl;
 
  123   virtual void DoRun (
void);
 
  128   : 
TestCase (
"Check behavour when type names collide")
 
  139   cout << 
suite << endl;
 
  144   string t1Name = 
"daemon";
 
  145   string t2Name = 
"unerring";
 
  146   cout << 
suite << 
"creating colliding types " 
  147        << 
"'" << t1Name << 
"', '" << t2Name << 
"'" 
  148        << 
" in alphabetical order:" 
  150   TypeId t1 (t1Name.c_str ());
 
  151   TypeId t2 (t2Name.c_str ());
 
  155                          "First and lesser TypeId has HashChainFlag set");
 
  156   cout << 
suite << 
"collision: first,lesser  not chained: OK" << endl;
 
  159                          "Second and greater TypeId does not have HashChainFlag set");
 
  160   cout << 
suite << 
"collision: second,greater    chained: OK" << endl;
 
  165   string t3Name = 
"trigonon";
 
  166   string t4Name = 
"seriation";
 
  167   cout << 
suite << 
"creating colliding types " 
  168        << 
"'" << t3Name << 
"', '" << t4Name << 
"'" 
  169        << 
" in reverse alphabetical order:" 
  171   TypeId t3 (t3Name.c_str ());
 
  172   TypeId t4 (t4Name.c_str ());
 
  176                           "First and greater TypeId does not have HashChainFlag set");
 
  177   cout << 
suite << 
"collision: first,greater     chained: OK" << endl;
 
  180                           "Second and lesser TypeId has HashChainFlag set");
 
  181   cout << 
suite << 
"collision: second,lesser not chained: OK" << endl;
 
  203   void Report (
const std::string how, 
const uint32_t delta) 
const ;
 
  209   : 
TestCase (
"Measure average lookup time")
 
  220   cout << 
suite << endl;
 
  223   uint32_t nids = TypeId::GetRegisteredN ();
 
  225   int start = clock ();
 
  228       for (uint32_t i = 0; i < nids; ++i)
 
  230           const TypeId tid = TypeId::GetRegistered (i);
 
  235   Report (
"name", stop - start);
 
  240       for (uint32_t i = 0; i < nids; ++i)
 
  242           const TypeId tid = TypeId::GetRegistered (i);
 
  247   Report (
"hash", stop - start);
 
  254   uint32_t nids = TypeId::GetRegisteredN ();
 
  257        << 
", num TypeId's: " << nids
 
  264                             const uint32_t    delta)
 const 
  266   double nids = TypeId::GetRegisteredN ();
 
  269   double per = 1E6 * double(delta) / (reps * double(CLOCKS_PER_SEC));
 
  271   cout << 
suite << 
"Lookup time: by " << how << 
": " 
  272        << 
"ticks: " << delta
 
  274        << 
" microsec/lookup" 
  313   : 
TestSuite (
"type-id-perf", PERFORMANCE)
 
static TypeIdTestSuite g_TypeIdTestSuite
 
virtual void DoRun(void)
Implementation to actually run this TestCase. 
 
virtual void DoRun(void)
Implementation to actually run this TestCase. 
 
static TypeIdPerformanceSuite g_TypeIdPerformanceSuite
 
virtual ~CollisionTestCase()
 
Serious error messages only. 
 
virtual ~LookupTimeTestCase()
 
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component. 
 
void AddTestCase(TestCase *testCase, enum TestDuration duration)
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()
 
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer. 
 
void DoRun(void)
Implementation to actually run this TestCase. 
 
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. 
 
Prefix all trace prints with function. 
 
std::string GetName(void) const 
Get the name. 
 
uint16_t GetUid(void) const 
Get the internal id of this TypeId. 
 
void Report(const std::string how, const uint32_t delta) const 
 
hash_t GetHash(void) const 
Get the hash. 
 
const std::string suite("type-id: ")
 
#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...
 
LogLevel
Logging severity classes and levels. 
 
std::string GetName(void) const 
 
a unique identifier for an interface. 
 
Generic Hash function interface.