Bug 1313467 - Part 2: Move tests into individual functions. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Fri, 04 Nov 2016 11:13:55 -0700
changeset 320994 2d1eb2bddef98eaf9ab1069c32f16538a5c2a893
parent 320993 7abe65a85676c0f538b6871fee5ecc3ee3a17cba
child 320995 d7335cf91ad0ad8b9f798735490a15876aa05bb8
push id83505
push usererahm@mozilla.com
push dateFri, 04 Nov 2016 18:14:05 +0000
treeherdermozilla-inbound@6ca9d7aa4dc7 [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;
 }