Bug 1313467 - Part 2: Move tests into individual functions. r=froydnj
☠☠ backed out by 561b87e98ada ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Thu, 03 Nov 2016 17:48:16 -0700
changeset 320838 6fae1bbd3819833d07fd47f7b9b15b8e42e12452
parent 320837 107eb264a40d19ecdcb1af3d09959a547d397b9d
child 320839 0acc0a131101e59d9b6dbc1dded254ebf6707104
push id83473
push usererahm@mozilla.com
push dateFri, 04 Nov 2016 00:56:12 +0000
treeherdermozilla-inbound@5b5686e1bcd1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1313467
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1313467 - Part 2: Move tests into individual functions. r=froydnj This just moves code into separate functions. No logic changes were made. MozReview-Commit-ID: 98NqhCb4T67
xpcom/tests/TestAutoPtr.cpp
--- a/xpcom/tests/TestAutoPtr.cpp
+++ b/xpcom/tests/TestAutoPtr.cpp
@@ -78,136 +78,164 @@ static void DoSomethingWithTestObjectBas
 }
 
 static void DoSomethingWithConstTestObjectBaseB(const TestObjectBaseB *aIn)
 {
     printf("  Doing something with |const TestObjectBaseB| %p.\n",
            static_cast<const void*>(aIn));
 }
 
+void test_assignment()
+{
+  {
+    printf("Should create one |TestObject|:\n");
+    nsAutoPtr<TestObject> pobj( new TestObject() );
+    printf("Should destroy one |TestObject|:\n");
+  }
+
+  {
+    printf("Should create one |TestObject|:\n");
+    nsAutoPtr<TestObject> pobj( new TestObject() );
+    printf("Should create one |TestObject| and then destroy one:\n");
+    pobj = new TestObject();
+    printf("Should destroy one |TestObject|:\n");
+  }
+}
+
+void test_getter_Transfers()
+{
+  printf("\nTesting getter_Transfers.\n");
+
+  {
+    nsAutoPtr<TestObject> ptr;
+    printf("Should create one |TestObject|:\n");
+    CreateTestObject(getter_Transfers(ptr));
+    printf("Should destroy one |TestObject|:\n");
+  }
+}
+
+void test_casting()
+{
+  printf("\nTesting casts and equality tests.\n");
+
+  // This comparison is always false, as it should be. The extra parens
+  // suppress a -Wunreachable-code warning about printf being unreachable.
+  if (((void*)(TestObject*)0x1000) ==
+      ((void*)(TestObjectBaseB*)(TestObject*)0x1000))
+    printf("\n\nAll these tests are meaningless!\n\n\n");
+
+  {
+    nsAutoPtr<TestObject> p1(new TestObject());
+    TestObjectBaseB *p2 = p1;
+    printf("equality %s.\n",
+        ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
+         (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
+        ? "OK" : "broken");
+  }
+
+  {
+    TestObject *p1 = new TestObject();
+    nsAutoPtr<TestObjectBaseB> p2(p1);
+    printf("equality %s.\n",
+        ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
+         (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
+        ? "OK" : "broken");
+  }
+}
+
+void test_forget()
+{
+  printf("\nTesting |forget()|.\n");
+
+  {
+    printf("Should create one |TestObject|:\n");
+    nsAutoPtr<TestObject> pobj( new TestObject() );
+    printf("Should do nothing:\n");
+    nsAutoPtr<TestObject> pobj2( pobj.forget() );
+    printf("Should destroy one |TestObject|:\n");
+  }
+}
+
+void test_construction()
+{
+  printf("\nTesting construction.\n");
+
+  {
+    printf("Should create one |TestObject|:\n");
+    nsAutoPtr<TestObject> pobj(new TestObject());
+    printf("Should destroy one |TestObject|:\n");
+  }
+}
+
+void test_implicit_conversion()
+{
+  printf("\nTesting calling of functions (including array access and casts).\n");
+
+  {
+    printf("Should create one |TestObject|:\n");
+    nsAutoPtr<TestObject> pobj(new TestObject());
+    printf("Should do something with one |TestObject|:\n");
+    DoSomethingWithTestObject(pobj);
+    printf("Should do something with one |TestObject|:\n");
+    DoSomethingWithConstTestObject(pobj);
+    printf("Should destroy one |TestObject|:\n");
+  }
+
+  {
+    printf("Should create one |TestObject|:\n");
+    nsAutoPtr<TestObject> pobj(new TestObject());
+    printf("Should do something with one |TestObject|:\n");
+    DoSomethingWithTestObjectBaseB(pobj);
+    printf("Should do something with one |TestObject|:\n");
+    DoSomethingWithConstTestObjectBaseB(pobj);
+    printf("Should destroy one |TestObject|:\n");
+  }
+
+  {
+    printf("Should create one |TestObject|:\n");
+    const nsAutoPtr<TestObject> pobj(new TestObject());
+    printf("Should do something with one |TestObject|:\n");
+    DoSomethingWithTestObject(pobj);
+    printf("Should do something with one |TestObject|:\n");
+    DoSomethingWithConstTestObject(pobj);
+    printf("Should destroy one |TestObject|:\n");
+  }
+
+  {
+    printf("Should create one |TestObject|:\n");
+    const nsAutoPtr<TestObject> pobj(new TestObject());
+    printf("Should do something with one |TestObject|:\n");
+    DoSomethingWithTestObjectBaseB(pobj);
+    printf("Should do something with one |TestObject|:\n");
+    DoSomethingWithConstTestObjectBaseB(pobj);
+    printf("Should destroy one |TestObject|:\n");
+  }
+}
+
+void test_arrow_operator()
+{
+  {
+    int test = 1;
+    void (TestObjectBaseA::*fPtr)( int, int*, int& ) = &TestObjectBaseA::MemberFunction;
+    void (TestObjectBaseA::*fVPtr)( int, int*, int& ) = &TestObjectBaseA::VirtualMemberFunction;
+    void (TestObjectBaseA::*fVCPtr)( int, int*, int& ) const = &TestObjectBaseA::VirtualConstMemberFunction;
+    printf("Should create one |TestObject|:\n");
+    nsAutoPtr<TestObjectBaseA> pobj(new TestObject());
+    printf("Should do something with operator->*:\n");
+    (pobj->*fPtr)(test, &test, test);
+    (pobj->*fVPtr)(test, &test, test);
+    (pobj->*fVCPtr)(test, &test, test);
+    printf("Should destroy one |TestObject|:\n");
+  }
+}
+
 int main()
 {
-    {
-        printf("Should create one |TestObject|:\n");
-        nsAutoPtr<TestObject> pobj( new TestObject() );
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    {
-        printf("Should create one |TestObject|:\n");
-        nsAutoPtr<TestObject> pobj( new TestObject() );
-        printf("Should create one |TestObject| and then destroy one:\n");
-        pobj = new TestObject();
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    printf("\nTesting getter_Transfers.\n");
-
-    {
-        nsAutoPtr<TestObject> ptr;
-        printf("Should create one |TestObject|:\n");
-        CreateTestObject(getter_Transfers(ptr));
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    printf("\nTesting casts and equality tests.\n");
-
-    // This comparison is always false, as it should be. The extra parens
-    // suppress a -Wunreachable-code warning about printf being unreachable.
-    if (((void*)(TestObject*)0x1000) ==
-        ((void*)(TestObjectBaseB*)(TestObject*)0x1000))
-        printf("\n\nAll these tests are meaningless!\n\n\n");
-
-    {
-        nsAutoPtr<TestObject> p1(new TestObject());
-        TestObjectBaseB *p2 = p1;
-        printf("equality %s.\n",
-               ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
-                (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
-               ? "OK" : "broken");
-    }
-
-    {
-        TestObject *p1 = new TestObject();
-        nsAutoPtr<TestObjectBaseB> p2(p1);
-        printf("equality %s.\n",
-               ((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
-                (p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
-               ? "OK" : "broken");
-    }
-
-    printf("\nTesting |forget()|.\n");
-
-    {
-        printf("Should create one |TestObject|:\n");
-        nsAutoPtr<TestObject> pobj( new TestObject() );
-        printf("Should do nothing:\n");
-        nsAutoPtr<TestObject> pobj2( pobj.forget() );
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    printf("\nTesting construction.\n");
+  test_assignment();
+  test_getter_Transfers();
+  test_casting();
+  test_forget();
+  test_construction();
+  test_implicit_conversion();
+  test_arrow_operator(); //???
 
-    {
-        printf("Should create one |TestObject|:\n");
-        nsAutoPtr<TestObject> pobj(new TestObject());
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    printf("\nTesting calling of functions (including array access and casts).\n");
-
-    {
-        printf("Should create one |TestObject|:\n");
-        nsAutoPtr<TestObject> pobj(new TestObject());
-        printf("Should do something with one |TestObject|:\n");
-        DoSomethingWithTestObject(pobj);
-        printf("Should do something with one |TestObject|:\n");
-        DoSomethingWithConstTestObject(pobj);
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    {
-        printf("Should create one |TestObject|:\n");
-        nsAutoPtr<TestObject> pobj(new TestObject());
-        printf("Should do something with one |TestObject|:\n");
-        DoSomethingWithTestObjectBaseB(pobj);
-        printf("Should do something with one |TestObject|:\n");
-        DoSomethingWithConstTestObjectBaseB(pobj);
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    {
-        printf("Should create one |TestObject|:\n");
-        const nsAutoPtr<TestObject> pobj(new TestObject());
-        printf("Should do something with one |TestObject|:\n");
-        DoSomethingWithTestObject(pobj);
-        printf("Should do something with one |TestObject|:\n");
-        DoSomethingWithConstTestObject(pobj);
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    {
-        printf("Should create one |TestObject|:\n");
-        const nsAutoPtr<TestObject> pobj(new TestObject());
-        printf("Should do something with one |TestObject|:\n");
-        DoSomethingWithTestObjectBaseB(pobj);
-        printf("Should do something with one |TestObject|:\n");
-        DoSomethingWithConstTestObjectBaseB(pobj);
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-
-    {
-        int test = 1;
-        void (TestObjectBaseA::*fPtr)( int, int*, int& ) = &TestObjectBaseA::MemberFunction;
-        void (TestObjectBaseA::*fVPtr)( int, int*, int& ) = &TestObjectBaseA::VirtualMemberFunction;
-        void (TestObjectBaseA::*fVCPtr)( int, int*, int& ) const = &TestObjectBaseA::VirtualConstMemberFunction;
-        printf("Should create one |TestObject|:\n");
-        nsAutoPtr<TestObjectBaseA> pobj(new TestObject());
-        printf("Should do something with operator->*:\n");
-        (pobj->*fPtr)(test, &test, test);
-        (pobj->*fVPtr)(test, &test, test);
-        (pobj->*fVCPtr)(test, &test, test);
-        printf("Should destroy one |TestObject|:\n");
-    }
-
-    return 0;
+  return 0;
 }