Bug 1313469 - Part 1: Split out test functions. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Fri, 04 Nov 2016 16:21:58 -0700
changeset 347899 2d4477c3e98f5759db56a626a521231f71b0d5e2
parent 347898 825b955d94df324138255e4ee8e5a4e241171a0d
child 347900 7b730d2d279442ae03e6f42e7c6141a5a904e9af
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
bugs1313469
milestone52.0a1
Bug 1313469 - Part 1: Split out test functions. r=froydnj This just splits out the test functions, no logic is changed. MozReview-Commit-ID: KjUA9rQ7iOS
xpcom/tests/TestCOMArray.cpp
--- a/xpcom/tests/TestCOMArray.cpp
+++ b/xpcom/tests/TestCOMArray.cpp
@@ -121,24 +121,18 @@ Bar::Release(void)
   if (mRefCnt == 0) {
     mRefCnt = 1; /* stabilize */
     delete this;
     return 0;
   }
   return mRefCnt;
 }
 
-
-int main(int argc, char **argv)
+void Sizing()
 {
-  ScopedXPCOM xpcom("nsCOMArrayTests");
-  if (xpcom.failed()) {
-    return 1;
-  }
-
   int rv = 0;
 
   Array arr;
 
   for (int32_t i = 0; i < 20; ++i) {
     nsCOMPtr<IFoo> foo = new Foo(i);
     arr.AppendObject(foo);
   }
@@ -173,16 +167,20 @@ int main(int argc, char **argv)
   for (int32_t i = 10; i < 30; ++i) {
 	if (arr[i] != nullptr) {
       fail("nsCOMArray elements should be null");
       rv = 1;
 	  break;
     }
   }
 
+}
+
+void ObjectFunctions()
+{
   int32_t base;
   {
     Array2 arr2;
 
     IBar *thirdObject = nullptr,
          *fourthObject = nullptr,
          *fifthObject = nullptr,
          *ninthObject = nullptr;
@@ -254,17 +252,21 @@ int main(int argc, char **argv)
       fail("RemoveObjectsAt should work for removing the last element");
     }
 
     arr2.Clear();
     if (Bar::sReleaseCalled != base + 20) {
       fail("Release called multiple times for Clear");
     }
   }
+}
 
+void ElementFunctions()
+{
+  int32_t base;
   {
     Array2 arr2;
 
     IBar *thirdElement = nullptr,
          *fourthElement = nullptr,
          *fifthElement = nullptr,
          *ninthElement = nullptr;
     for (int32_t i = 0; i < 20; ++i) {
@@ -335,17 +337,21 @@ int main(int argc, char **argv)
       fail("RemoveElementsAt should work for removing the last element");
     }
 
     arr2.Clear();
     if (Bar::sReleaseCalled != base + 20) {
       fail("Release called multiple times for Clear");
     }
   }
+}
 
+void Destructor()
+{
+  int32_t base;
   Bar::sReleaseCalled = 0;
 
   {
     Array2 arr2;
 
     for (int32_t i = 0; i < 20; ++i) {
       nsCOMPtr<IBar> bar  = new Bar(arr2);
       arr2.AppendObject(bar);
@@ -353,11 +359,24 @@ int main(int argc, char **argv)
 
     base = Bar::sReleaseCalled;
 
     // Let arr2 be destroyed
   }
   if (Bar::sReleaseCalled != base + 20) {
     fail("Release called multiple times for nsCOMArray::~nsCOMArray");
   }
+}
 
-  return rv;
+int main(int argc, char **argv)
+{
+  ScopedXPCOM xpcom("nsCOMArrayTests");
+  if (xpcom.failed()) {
+    return 1;
+  }
+
+  Sizing();
+  ObjectFunctions();
+  ElementFunctions();
+  Destructor();
+
+  return 0;
 }