From fae1bad96c277f0f5fe9dbd6f00b7441999837e0 Mon Sep 17 00:00:00 2001 From: Daniel Buckmaster Date: Mon, 29 Sep 2014 11:00:43 +1000 Subject: [PATCH] All unit tests that run now pass. --- .../component/test/simComponentTest.cpp | 28 ++++++++----------- .../platform/test/platformTimerTest.cpp | 2 +- .../threads/test/threadSafeRefCountTest.cpp | 10 +++---- Engine/source/testing/unitTesting.cpp | 1 + 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Engine/source/component/test/simComponentTest.cpp b/Engine/source/component/test/simComponentTest.cpp index b4c8b1509..407e3adce 100644 --- a/Engine/source/component/test/simComponentTest.cpp +++ b/Engine/source/component/test/simComponentTest.cpp @@ -47,10 +47,10 @@ public: public: ////////////////////////////////////////////////////////////////////////// - virtual void registerInterfaces( const SimComponent *owner ) + virtual void registerInterfaces( SimComponent *owner ) { // Register a cached interface for this - registerCachedInterface( NULL, "aU32", this, &mMyId ); + owner->registerCachedInterface( NULL, "aU32", this, &mMyId ); } ////////////////////////////////////////////////////////////////////////// @@ -66,7 +66,7 @@ public: ComponentInterfaceList list; // Enumerate the interfaces on the owner, only ignore interfaces that this object owns - if( !_getOwner()->getInterfaces( &list, NULL, "aU32", this, true ) ) + if( !owner->getInterfaces( &list, NULL, "aU32", this, true ) ) return false; // Sanity check before just assigning all willy-nilly @@ -131,23 +131,19 @@ TEST(SimComponent, Composition) << "testComponent did not properly set the mOwner field of componentB to NULL."; // Register the object with the simulation, kicking off the interface registration - const bool registered = testComponent->registerObject(); - EXPECT_TRUE( registered ) + ASSERT_TRUE( testComponent->registerObject() ) << "Failed to register testComponent"; - // Interface tests - if( registered ) { - { - SCOPED_TRACE("componentA"); - componentA->unit_test(); - } - { - SCOPED_TRACE("componentB"); - componentB->unit_test(); - } - testComponent->deleteObject(); + SCOPED_TRACE("componentA"); + componentA->unit_test(); } + { + SCOPED_TRACE("componentB"); + componentB->unit_test(); + } + + testComponent->deleteObject(); }; #endif \ No newline at end of file diff --git a/Engine/source/platform/test/platformTimerTest.cpp b/Engine/source/platform/test/platformTimerTest.cpp index dddf58830..c8f4db09f 100644 --- a/Engine/source/platform/test/platformTimerTest.cpp +++ b/Engine/source/platform/test/platformTimerTest.cpp @@ -40,7 +40,7 @@ TEST(Platform, Sleep) U32 start = Platform::getRealMilliseconds(); Platform::sleep(500); U32 end = Platform::getRealMilliseconds(); - EXPECT_GE(end - start, 500) + EXPECT_GE(end - start, 500-10) // account for clock resolution << "We didn't sleep at least as long as we requested!"; }; diff --git a/Engine/source/platform/threads/test/threadSafeRefCountTest.cpp b/Engine/source/platform/threads/test/threadSafeRefCountTest.cpp index 698637422..16390dd57 100644 --- a/Engine/source/platform/threads/test/threadSafeRefCountTest.cpp +++ b/Engine/source/platform/threads/test/threadSafeRefCountTest.cpp @@ -105,7 +105,7 @@ TEST(ThreadSafeRefCount, Concurrent) }; mRef = new TestObject; - EXPECT_EQ(mRef->getRefCount(), 2); // increments of 2 + EXPECT_EQ(2, mRef->getRefCount()); // increments of 2 Vector threads; threads.setSize(NUM_THREADS); @@ -122,8 +122,8 @@ TEST(ThreadSafeRefCount, Concurrent) for (U32 i = 0; i < NUM_THREADS; i++) threads[i]->join(); - Con::printf("REF: %i", mRef->getRefCount()); - EXPECT_EQ(mRef->getRefCount(), 2 + ((NUM_ADD_REFS_PER_THREAD + NUM_EXTRA_REFS_PER_THREAD) * NUM_THREADS * 2)); + EXPECT_EQ(2 + ((1 + NUM_ADD_REFS_PER_THREAD + NUM_EXTRA_REFS_PER_THREAD) * NUM_THREADS * 2), + mRef->getRefCount()); // Run phase 2: release references. for (U32 i = 0; i < NUM_THREADS; i++) @@ -136,7 +136,7 @@ TEST(ThreadSafeRefCount, Concurrent) delete threads[i]; } - EXPECT_EQ(mRef->getRefCount(), 2); // increments of two + EXPECT_EQ(2, mRef->getRefCount()); // increments of two mRef = NULL; } @@ -148,7 +148,7 @@ TEST(ThreadSafeRefCount, Tagging) TestObjectRef ref; EXPECT_FALSE(ref.isTagged()); - EXPECT_TRUE(bool(ref)); + EXPECT_FALSE(bool(ref)); EXPECT_FALSE(bool(ref.ptr())); EXPECT_TRUE(ref.trySetFromTo(ref, NULL)); diff --git a/Engine/source/testing/unitTesting.cpp b/Engine/source/testing/unitTesting.cpp index ce92475d0..2724bf637 100644 --- a/Engine/source/testing/unitTesting.cpp +++ b/Engine/source/testing/unitTesting.cpp @@ -86,6 +86,7 @@ DefineConsoleFunction( runAllUnitTests, int, (const char* testSpecs), (""), "@param testSpecs A space-sepatated list of filters for test cases. " "See https://code.google.com/p/googletest/wiki/AdvancedGuide#Running_a_Subset_of_the_Tests " + "and http://stackoverflow.com/a/14021997/945863 " "for a description of the flag format.") { S32 testArgc = 0;