Bug 1313475 - Part 1: Split out test functions. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Fri, 04 Nov 2016 16:23:22 -0700
changeset 351264 43bc6883159435d392d1340daf3874a4c9d9bba5
parent 351263 52f7c6687d175c0d37359a02a504dfdf62e80b6b
child 351265 ce050e1aab2f73e214566fdb9bd00e2d45aff281
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1313475
milestone52.0a1
Bug 1313475 - Part 1: Split out test functions. r=froydnj MozReview-Commit-ID: EHmr48RpGq0
xpcom/tests/TestNsRefPtr.cpp
--- a/xpcom/tests/TestNsRefPtr.cpp
+++ b/xpcom/tests/TestNsRefPtr.cpp
@@ -385,27 +385,18 @@ class ObjectForConstPtr
         printf("const member function is invoked by RefPtr<const T>->*.\n");
       }
 };
 #undef NS_INLINE_DECL_THREADSAFE_MUTABLE_REFCOUNTING
 
 
 RefPtr<Foo> gFoop;
 
-int
-main()
+void AddRefAndRelease()
 {
-  printf(">>main()\n");
-
-  printf("sizeof(RefPtr<Foo>) --> %u\n", unsigned(sizeof(RefPtr<Foo>)));
-
-  TestBloat_Raw_Unsafe();
-  TestBloat_Smart();
-
-
   {
     printf("\n### Test  1: will a |nsCOMPtr| call |AddRef| on a pointer assigned into it?\n");
     RefPtr<Foo> foop( do_QueryObject(new Foo) );
 
     printf("\n### Test  2: will a |nsCOMPtr| |Release| its old pointer when a new one is assigned in?\n");
     foop = do_QueryObject(new Foo);
 
     // [Shouldn't compile] Is it a compile time error to try to |AddRef| by hand?
@@ -422,21 +413,36 @@ main()
 
     printf("\n### Test  4: can you |Release| if you must?\n");
     static_cast<Foo*>(foop)->Release();
 
     printf("\n### Test  5: will a |nsCOMPtr| |Release| when it goes out of scope?\n");
   }
 
   {
+    printf("\n### setup for Test 24\n");
+    RefPtr<Foo> fooP( do_QueryObject(new Foo) );
+
+    printf("### Test 24: does |forget| avoid an AddRef/Release when assigning to another nsCOMPtr?\n");
+    RefPtr<Foo> fooP2( fooP.forget() );
+  }
+  printf("### End Test 24\n");
+}
+
+void VirtualDestructor()
+{
+  {
     printf("\n### Test  6: will a |nsCOMPtr| call the correct destructor?\n");
     RefPtr<Foo> foop( do_QueryObject(new Bar) );
     mozilla::Unused << foop;
   }
+}
 
+void Equality()
+{
   {
     printf("\n### Test  7: can you compare one |nsCOMPtr| with another [!=]?\n");
 
     RefPtr<Foo> foo1p( do_QueryObject(new Foo) );
 
     // [Shouldn't compile] Is it a compile time error to omit |getter_[doesnt_]AddRef[s]|?
     //AnFooPtrPtrContext(&foo1p);
 
@@ -507,17 +513,20 @@ main()
 
 #if 0
     if ( foo1p == 1 )
       printf("foo1p allowed compare with in\n");
 #endif
 
     printf("\n### Test 14: how about when two |nsCOMPtr|s referring to the same object go out of scope?\n");
   }
+}
 
+void AddRefHelpers()
+{
   {
     printf("\n### Test 15,16 ...setup...\n");
     Foo* raw_foo1p = new Foo;
     raw_foo1p->AddRef();
 
     Foo* raw_foo2p = new Foo;
     raw_foo2p->AddRef();
 
@@ -525,22 +534,16 @@ main()
     RefPtr<Foo> foo1p( dont_AddRef(raw_foo1p) );
     //RefPtr<Foo> foo1p = dont_AddRef(raw_foo1p);
 
     printf("\n### Test 16: what if I don't want to |AddRef| when I assign in?\n");
     RefPtr<Foo> foo2p;
     foo2p = dont_AddRef(raw_foo2p);
   }
 
-
-
-
-
-
-
   {
     printf("\n### setup for Test 17\n");
     RefPtr<Foo> foop;
     printf("### Test 17: basic parameter behavior?\n");
     CreateFoo( RefPtrGetterAddRefs<Foo>(foop) );
   }
   printf("### End Test 17\n");
 
@@ -559,17 +562,20 @@ main()
     RefPtr<Foo> foop;
     printf("### Test 19: reference parameter behavior?\n");
     set_a_Foo(address_of(foop));
 
     printf("### Test 20: return value behavior?\n");
     foop = return_a_Foo();
   }
   printf("### End Test 19, 20\n");
+}
 
+void QueryInterface()
+{
   {
     printf("\n### setup for Test 21\n");
     RefPtr<Foo> fooP;
 
     printf("### Test 21: is |QueryInterface| called on assigning in a raw pointer?\n");
     fooP = do_QueryObject(new Foo);
   }
   printf("### End Test 21\n");
@@ -592,27 +598,20 @@ main()
 
     printf("### Test 23: is |QueryInterface| called when assigning in a smart-pointer of a different type?\n");
 
     RefPtr<Foo> fooP( do_QueryObject(barP) );
     if ( fooP )
       printf("an Bar* is an Foo*\n");
   }
   printf("### End Test 23\n");
-
-
-  {
-    printf("\n### setup for Test 24\n");
-    RefPtr<Foo> fooP( do_QueryObject(new Foo) );
+}
 
-    printf("### Test 24: does |forget| avoid an AddRef/Release when assigning to another nsCOMPtr?\n");
-    RefPtr<Foo> fooP2( fooP.forget() );
-  }
-  printf("### End Test 24\n");
-
+void TestsThatWillBeDeleted()
+{
   {
     RefPtr<Foo> fooP;
 
     AnFooPtrPtrContext( getter_AddRefs(fooP) );
     AVoidPtrPtrContext( getter_AddRefs(fooP) );
   }
 
   {
@@ -627,17 +626,16 @@ main()
 
     // [Shouldn't compile] Is it a compile time error to call a non-const method on an |RefPtr<const T>|?
     //constFooP->NonconstMethod();
 
     // [Shouldn't compile] Is it a compile time error to construct an |RefPtr<T> from an |RefPtr<const T>|?
     //RefPtr<Foo> otherFooP(constFooP);
   }
 
-
   printf("\n### Test 26: will a static |nsCOMPtr| |Release| before program termination?\n");
   gFoop = do_QueryObject(new Foo);
 
   {
     printf("\n### setup for Test 26, 27, 28\n");
     RefPtr<Foo> foop = new Foo;
     RefPtr<Foo> foop2 = new Bar;
     RefPtr<const ObjectForConstPtr> foop3 = new ObjectForConstPtr;
@@ -655,13 +653,28 @@ main()
     (foop2->*fVPtr)(test, &test, test);
     (foop2->*fVCPtr)(test, &test, test);
     printf("### End Test 27\n");
 
     printf("### Test 28: invoke virtual const member function via RefPtr<const T> operator ->*\n");
     (foop3->*fCPtr2)(test, &test, test);
     printf("### End Test 28\n");
   }
+}
 
+int
+main()
+{
+  printf(">>main()\n");
+
+  printf("sizeof(RefPtr<Foo>) --> %u\n", unsigned(sizeof(RefPtr<Foo>)));
+
+  TestBloat_Raw_Unsafe();
+  TestBloat_Smart();
+  AddRefAndRelease();
+  VirtualDestructor();
+  Equality();
+  AddRefHelpers();
+  QueryInterface();
 
   printf("<<main()\n");
   return 0;
 }