Bug 1313473 - Part 1: Split out test functions. r=froydnj
☠☠ backed out by 561b87e98ada ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Mon, 31 Oct 2016 16:34:24 -0700
changeset 347693 643bdd25166eef38dafe3428eca0a2b0c2e62946
parent 347692 9a33c84ab30a6e67a605b73337feb9ab7744458f
child 347694 e8d20bdd13d447998e73974644d42787afe2dc43
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1313473
milestone52.0a1
Bug 1313473 - Part 1: Split out test functions. r=froydnj MozReview-Commit-ID: 4A0JgxyXWPz
xpcom/tests/TestHashtables.cpp
--- a/xpcom/tests/TestHashtables.cpp
+++ b/xpcom/tests/TestHashtables.cpp
@@ -312,18 +312,18 @@ CreateIFoo( IFoo** result )
     printf("<<CreateIFoo()\n");
     return NS_OK;
   }
 
 } // namespace TestHashtables
 
 using namespace TestHashtables;
 
-int
-main(void) {
+void THashtable()
+{
   // check an nsTHashtable
   printf("Initializing nsTHashtable...");
   nsTHashtable<EntityToUnicodeEntry> EntityToUnicode(ENTITY_COUNT);
   printf("OK\n");
 
   printf("Partially filling nsTHashtable:\n");
   testTHashtable(EntityToUnicode, 5);
 
@@ -352,38 +352,40 @@ main(void) {
 
   printf("Check enumeration...");
   count = nsTIterPrint(EntityToUnicode);
   if (count != 0) {
     printf("entries remain in table!\n");
     exit (9);
   }
   printf("OK\n");
+}
 
+void DataHashtable()
+{
   //
   // now check a data-hashtable
   //
 
   printf("Initializing nsDataHashtable...");
   nsDataHashtable<nsUint32HashKey,const char*> UniToEntity(ENTITY_COUNT);
   printf("OK\n");
 
   printf("Filling hash with %u entries.\n", ENTITY_COUNT);
 
-  uint32_t i;
-  for (i = 0; i < ENTITY_COUNT; ++i) {
+  for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Putting entry %u...", gEntities[i].mUnicode);
     UniToEntity.Put(gEntities[i].mUnicode, gEntities[i].mStr);
     printf("OK...\n");
   }
 
   printf("Testing Get:\n");
   const char* str;
 
-  for (i = 0; i < ENTITY_COUNT; ++i) {
+  for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Getting entry %u...", gEntities[i].mUnicode);
     if (!UniToEntity.Get(gEntities[i].mUnicode, &str)) {
       printf("FAILED\n");
       exit (12);
     }
 
     printf("Found %s\n", str);
   }
@@ -393,17 +395,17 @@ main(void) {
     printf("FOUND! BAD!\n");
     exit (13);
   }
 
   printf("not found; good.\n");
 
   printf("Enumerating:\n");
 
-  count = 0;
+  uint32_t count = 0;
   for (auto iter = UniToEntity.Iter(); !iter.Done(); iter.Next()) {
     printf("  enumerated %u = \"%s\"\n", iter.Key(), iter.UserData());
     count++;
   }
   if (count != ENTITY_COUNT) {
     printf("  Bad count!\n");
     exit (14);
   }
@@ -419,39 +421,42 @@ main(void) {
     count++;
   }
   if (count != 0) {
     printf("  Clear did not remove all entries.\n");
     exit (15);
   }
 
   printf("OK\n");
+}
 
+void ClassHashtable()
+{
   //
   // now check a class-hashtable
   //
 
   printf("Initializing nsClassHashtable...");
   nsClassHashtable<nsCStringHashKey,TestUniChar> EntToUniClass(ENTITY_COUNT);
   printf("OK\n");
 
   printf("Filling hash with %u entries.\n", ENTITY_COUNT);
 
-  for (i = 0; i < ENTITY_COUNT; ++i) {
+  for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Putting entry %u...", gEntities[i].mUnicode);
     TestUniChar* temp = new TestUniChar(gEntities[i].mUnicode);
 
     EntToUniClass.Put(nsDependentCString(gEntities[i].mStr), temp);
     printf("OK...\n");
   }
 
   printf("Testing Get:\n");
   TestUniChar* myChar;
 
-  for (i = 0; i < ENTITY_COUNT; ++i) {
+  for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Getting entry %s...", gEntities[i].mStr);
     if (!EntToUniClass.Get(nsDependentCString(gEntities[i].mStr), &myChar)) {
       printf("FAILED\n");
       exit (18);
     }
 
     printf("Found %c\n", myChar->GetChar());
   }
@@ -461,17 +466,17 @@ main(void) {
     printf("FOUND! BAD!\n");
     exit (19);
   }
 
   printf("not found; good.\n");
 
   printf("Enumerating:\n");
 
-  count = 0;
+  uint32_t count = 0;
   for (auto iter = EntToUniClass.Iter(); !iter.Done(); iter.Next()) {
     printf("  enumerated \"%s\" = %c\n",
            PromiseFlatCString(iter.Key()).get(), iter.UserData()->GetChar());
     count++;
   }
   if (count != ENTITY_COUNT) {
     printf("  Bad count!\n");
     exit (20);
@@ -489,45 +494,48 @@ main(void) {
     count++;
   }
   if (count != 0) {
     printf("  Clear did not remove all entries.\n");
     exit (21);
   }
 
   printf("OK\n");
+}
 
+void DataHashtableWithInterfaceKey()
+{
   //
   // now check a data-hashtable with an interface key
   //
 
   printf("Initializing nsDataHashtable with interface key...");
   nsDataHashtable<nsISupportsHashKey,uint32_t> EntToUniClass2(ENTITY_COUNT);
   printf("OK\n");
 
   printf("Filling hash with %u entries.\n", ENTITY_COUNT);
 
   nsCOMArray<IFoo> fooArray;
 
-  for (i = 0; i < ENTITY_COUNT; ++i) {
+  for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Putting entry %u...", gEntities[i].mUnicode);
     nsCOMPtr<IFoo> foo;
     CreateIFoo(getter_AddRefs(foo));
     foo->SetString(nsDependentCString(gEntities[i].mStr));
 
     fooArray.InsertObjectAt(foo, i);
 
     EntToUniClass2.Put(foo, gEntities[i].mUnicode);
     printf("OK...\n");
   }
 
   printf("Testing Get:\n");
   uint32_t myChar2;
 
-  for (i = 0; i < ENTITY_COUNT; ++i) {
+  for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Getting entry %s...", gEntities[i].mStr);
 
     if (!EntToUniClass2.Get(fooArray[i], &myChar2)) {
       printf("FAILED\n");
       exit (24);
     }
 
     printf("Found %c\n", myChar2);
@@ -538,17 +546,17 @@ main(void) {
     printf("FOUND! BAD!\n");
     exit (25);
   }
 
   printf("not found; good.\n");
 
   printf("Enumerating:\n");
 
-  count = 0;
+  uint32_t count = 0;
   for (auto iter = EntToUniClass2.Iter(); !iter.Done(); iter.Next()) {
     nsAutoCString s;
     nsCOMPtr<IFoo> foo = do_QueryInterface(iter.Key());
     foo->GetString(s);
     printf("  enumerated \"%s\" = %u\n", s.get(), iter.UserData());
     count++;
   }
   if (count != ENTITY_COUNT) {
@@ -570,40 +578,43 @@ main(void) {
     count++;
   }
   if (count != 0) {
     printf("  Clear did not remove all entries.\n");
     exit (27);
   }
 
   printf("OK\n");
+}
 
+void InterfaceHashtable()
+{
   //
   // now check an interface-hashtable with an uint32_t key
   //
 
   printf("Initializing nsInterfaceHashtable...");
   nsInterfaceHashtable<nsUint32HashKey,IFoo> UniToEntClass2(ENTITY_COUNT);
   printf("OK\n");
 
   printf("Filling hash with %u entries.\n", ENTITY_COUNT);
 
-  for (i = 0; i < ENTITY_COUNT; ++i) {
+  for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Putting entry %u...", gEntities[i].mUnicode);
     nsCOMPtr<IFoo> foo;
     CreateIFoo(getter_AddRefs(foo));
     foo->SetString(nsDependentCString(gEntities[i].mStr));
 
     UniToEntClass2.Put(gEntities[i].mUnicode, foo);
     printf("OK...\n");
   }
 
   printf("Testing Get:\n");
 
-  for (i = 0; i < ENTITY_COUNT; ++i) {
+  for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Getting entry %s...", gEntities[i].mStr);
 
     nsCOMPtr<IFoo> myEnt;
     if (!UniToEntClass2.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt))) {
       printf("FAILED\n");
       exit (30);
     }
 
@@ -618,17 +629,17 @@ main(void) {
     printf("FOUND! BAD!\n");
     exit (31);
   }
 
   printf("not found; good.\n");
 
   printf("Enumerating:\n");
 
-  count = 0;
+  uint32_t count = 0;
   for (auto iter = UniToEntClass2.Iter(); !iter.Done(); iter.Next()) {
     nsAutoCString s;
     iter.UserData()->GetString(s);
     printf("  enumerated %u = \"%s\"\n", iter.Key(), s.get());
     count++;
   }
   if (count != ENTITY_COUNT) {
     printf("  Bad count!\n");
@@ -648,11 +659,20 @@ main(void) {
     count++;
   }
   if (count != 0) {
     printf("  Clear did not remove all entries.\n");
     exit (33);
   }
 
   printf("OK\n");
+}
+
+int
+main(void) {
+  THashtable();
+  DataHashtable();
+  ClassHashtable();
+  DataHashtableWithInterfaceKey();
+  InterfaceHashtable();
 
   return 0;
 }