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
This commit is contained in:
Eric Rahm 2016-11-03 17:48:16 -07:00
parent 1c09ee8cf0
commit d99dcde62e

View File

@ -83,131 +83,159 @@ static void DoSomethingWithConstTestObjectBaseB(const TestObjectBaseB *aIn)
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");
}
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 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");
{
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;
}