From 5fcc423565a82e59f939712004d9e1671651d9a1 Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Thu, 31 Jul 2014 13:26:46 -0700 Subject: [PATCH] Switching EnclosedContextTestBase to be a filter rather than a base type --- src/autowiring/test/AnySharedPointerTest.hpp | 3 +- src/autowiring/test/AutoAnchorTest.hpp | 3 +- src/autowiring/test/AutoFilterTest.hpp | 3 +- src/autowiring/test/AutoInjectableTest.hpp | 3 +- src/autowiring/test/AutoPacketFactoryTest.hpp | 3 +- .../test/AutowiringBenchmarkTest.hpp | 3 +- src/autowiring/test/AutowiringTest.cpp | 2 +- src/autowiring/test/AutowiringTest.hpp | 3 +- .../test/AutowiringUtilitiesTest.hpp | 3 +- src/autowiring/test/BasicThreadTest.hpp | 3 +- src/autowiring/test/BoltTest.cpp | 11 ++- src/autowiring/test/BoltTest.hpp | 3 +- src/autowiring/test/CMakeLists.txt | 1 + src/autowiring/test/ContextCleanupTest.cpp | 19 +++-- src/autowiring/test/ContextCleanupTest.hpp | 3 +- src/autowiring/test/ContextCreatorTest.hpp | 3 +- src/autowiring/test/ContextEnumeratorTest.hpp | 2 +- src/autowiring/test/ContextMapTest.hpp | 5 +- src/autowiring/test/ContextMemberTest.hpp | 3 +- src/autowiring/test/CoreContextTest.cpp | 14 ++-- src/autowiring/test/CoreContextTest.hpp | 3 +- src/autowiring/test/CoreJobTest.cpp | 13 ++-- src/autowiring/test/CoreJobTest.hpp | 3 +- src/autowiring/test/CoreThreadTest.cpp | 62 ++++++++++------ src/autowiring/test/CoreThreadTest.hpp | 3 +- .../test/CurrentContextPusherTest.hpp | 1 - src/autowiring/test/DecoratorTest.hpp | 3 +- src/autowiring/test/DispatchQueueTest.cpp | 3 +- src/autowiring/test/DispatchQueueTest.hpp | 3 +- src/autowiring/test/DtorCorrectnessTest.cpp | 1 - src/autowiring/test/DtorCorrectnessTest.hpp | 3 +- .../test/EnclosedContextTestBase.cpp | 61 ++++++++++++++++ .../test/EnclosedContextTestBase.hpp | 73 +++++++++---------- src/autowiring/test/EventReceiverTest.cpp | 5 +- src/autowiring/test/EventReceiverTest.hpp | 3 +- src/autowiring/test/ExceptionFilterTest.cpp | 17 +++-- src/autowiring/test/ExceptionFilterTest.hpp | 4 +- src/autowiring/test/FactoryTest.hpp | 3 +- src/autowiring/test/GlobalInitTest.hpp | 1 - src/autowiring/test/GuardObjectTest.hpp | 1 - .../test/InterlockedRoutinesTest.hpp | 1 - src/autowiring/test/MarshalingTest.hpp | 3 +- src/autowiring/test/MultiInheritTest.hpp | 1 - src/autowiring/test/ObjectPoolTest.cpp | 3 +- src/autowiring/test/ObjectPoolTest.hpp | 3 +- src/autowiring/test/PeerContextTest.cpp | 15 ++-- src/autowiring/test/PeerContextTest.hpp | 3 +- src/autowiring/test/PostConstructTest.cpp | 3 +- src/autowiring/test/PostConstructTest.hpp | 4 +- src/autowiring/test/ScopeTest.cpp | 3 +- src/autowiring/test/ScopeTest.hpp | 3 +- .../test/SelfSelectingFixtureTest.cpp | 3 +- .../test/SelfSelectingFixtureTest.hpp | 3 +- src/autowiring/test/SnoopTest.hpp | 4 +- src/autowiring/test/TeardownNotifierTest.hpp | 1 - src/autowiring/test/TypeRegistryTest.hpp | 3 +- src/autowiring/test/UuidTest.hpp | 1 - src/autowiring/test/gtest-all-guard.cpp | 3 + src/autowiring/test/stdafx.h | 2 +- 59 files changed, 239 insertions(+), 182 deletions(-) create mode 100644 src/autowiring/test/EnclosedContextTestBase.cpp diff --git a/src/autowiring/test/AnySharedPointerTest.hpp b/src/autowiring/test/AnySharedPointerTest.hpp index 8ccdbf02f..75ceb85bb 100644 --- a/src/autowiring/test/AnySharedPointerTest.hpp +++ b/src/autowiring/test/AnySharedPointerTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class AnySharedPointerTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/AutoAnchorTest.hpp b/src/autowiring/test/AutoAnchorTest.hpp index 40231144a..7f4d795b0 100644 --- a/src/autowiring/test/AutoAnchorTest.hpp +++ b/src/autowiring/test/AutoAnchorTest.hpp @@ -1,8 +1,7 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class AutoAnchorTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/AutoFilterTest.hpp b/src/autowiring/test/AutoFilterTest.hpp index 6e217859f..62fe5f7b2 100644 --- a/src/autowiring/test/AutoFilterTest.hpp +++ b/src/autowiring/test/AutoFilterTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class AutoFilterTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/AutoInjectableTest.hpp b/src/autowiring/test/AutoInjectableTest.hpp index 55adde5ce..434ed6d2d 100644 --- a/src/autowiring/test/AutoInjectableTest.hpp +++ b/src/autowiring/test/AutoInjectableTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class AutoInjectableTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/AutoPacketFactoryTest.hpp b/src/autowiring/test/AutoPacketFactoryTest.hpp index 93bf0e915..38cb8cf23 100644 --- a/src/autowiring/test/AutoPacketFactoryTest.hpp +++ b/src/autowiring/test/AutoPacketFactoryTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class AutoPacketFactoryTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/AutowiringBenchmarkTest.hpp b/src/autowiring/test/AutowiringBenchmarkTest.hpp index fa4bef42d..12ba65cba 100644 --- a/src/autowiring/test/AutowiringBenchmarkTest.hpp +++ b/src/autowiring/test/AutowiringBenchmarkTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class AutowiringBenchmarkTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/AutowiringTest.cpp b/src/autowiring/test/AutowiringTest.cpp index 132cc2cf4..b762d3d3a 100644 --- a/src/autowiring/test/AutowiringTest.cpp +++ b/src/autowiring/test/AutowiringTest.cpp @@ -8,7 +8,7 @@ TEST_F(AutowiringTest, VerifyAutowiredFast) { // Add an object: - m_create->Inject(); + AutoCurrentContext()->Inject(); // Verify that AutowiredFast can find this object AutowiredFast sobj; diff --git a/src/autowiring/test/AutowiringTest.hpp b/src/autowiring/test/AutowiringTest.hpp index 13d578303..02dc55fe7 100644 --- a/src/autowiring/test/AutowiringTest.hpp +++ b/src/autowiring/test/AutowiringTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class AutowiringTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/AutowiringUtilitiesTest.hpp b/src/autowiring/test/AutowiringUtilitiesTest.hpp index b106e49f1..69e5f7b0c 100644 --- a/src/autowiring/test/AutowiringUtilitiesTest.hpp +++ b/src/autowiring/test/AutowiringUtilitiesTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class AutowiringUtilitiesTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/BasicThreadTest.hpp b/src/autowiring/test/BasicThreadTest.hpp index d695c947a..e9b8dc534 100644 --- a/src/autowiring/test/BasicThreadTest.hpp +++ b/src/autowiring/test/BasicThreadTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class BasicThreadTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/BoltTest.cpp b/src/autowiring/test/BoltTest.cpp index f8ca6f7e2..74333d12e 100644 --- a/src/autowiring/test/BoltTest.cpp +++ b/src/autowiring/test/BoltTest.cpp @@ -80,9 +80,10 @@ class InjectsIntoEverything: }; TEST_F(BoltTest, VerifySimpleInjection) { + AutoCurrentContext ctxt; AutoEnable(); - auto created = m_create->Create(); + auto created = ctxt->Create(); // Verify that the SimpleObject didn't accidentally get injected out here: { @@ -143,10 +144,11 @@ TEST_F(BoltTest, VerifyCreationBubbling) { } TEST_F(BoltTest, VerifyMultipleInjection) { + AutoCurrentContext ctxt; AutoEnable(); - auto created = m_create->Create(); - auto created2 = m_create->Create(); + auto created = ctxt->Create(); + auto created2 = ctxt->Create(); // Verify that the SimpleObject didn't accidentally get injected out here: { @@ -168,6 +170,7 @@ TEST_F(BoltTest, VerifyMultipleInjection) { } TEST_F(BoltTest, EmptyBolt) { + AutoCurrentContext ctxt; AutoEnable(); Autowired so; EXPECT_FALSE(so.IsAutowired()) << "CountObject injected into outer context"; @@ -180,7 +183,7 @@ TEST_F(BoltTest, EmptyBolt) { ASSERT_EQ(1, innerSo->count) << "ContextCreated() called incorrect number of times"; } - auto created2 = m_create->Create(); + auto created2 = ctxt->Create(); { CurrentContextPusher pshr(created2); Autowired innerSo; diff --git a/src/autowiring/test/BoltTest.hpp b/src/autowiring/test/BoltTest.hpp index 50fb491ad..38e88fbca 100644 --- a/src/autowiring/test/BoltTest.hpp +++ b/src/autowiring/test/BoltTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class BoltTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/CMakeLists.txt b/src/autowiring/test/CMakeLists.txt index 8e7c1c788..e06024281 100644 --- a/src/autowiring/test/CMakeLists.txt +++ b/src/autowiring/test/CMakeLists.txt @@ -42,6 +42,7 @@ set(AutowiringTest_SRCS DtorCorrectnessTest.hpp DtorCorrectnessTest.cpp EnclosedContextTestBase.hpp + EnclosedContextTestBase.cpp ExceptionFilterTest.hpp ExceptionFilterTest.cpp EventReceiverTest.hpp diff --git a/src/autowiring/test/ContextCleanupTest.cpp b/src/autowiring/test/ContextCleanupTest.cpp index 6231db012..d697fc1fa 100644 --- a/src/autowiring/test/ContextCleanupTest.cpp +++ b/src/autowiring/test/ContextCleanupTest.cpp @@ -137,7 +137,8 @@ class ReceivesTeardownNotice: }; TEST_F(ContextCleanupTest, VerifyGracefulThreadCleanup) { - m_create->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); AutoRequired ct; // Just create a CoreThread directly and have it pend some lambdas that will take awhile to run: @@ -148,12 +149,13 @@ TEST_F(ContextCleanupTest, VerifyGracefulThreadCleanup) { *ct += [called] { *called = true; }; // Verify that a graceful shutdown ensures both lambdas are called: - m_create->SignalShutdown(true, ShutdownMode::Graceful); + ctxt->SignalShutdown(true, ShutdownMode::Graceful); ASSERT_TRUE(*called) << "Graceful shutdown did not correctly run down all lambdas"; } TEST_F(ContextCleanupTest, VerifyImmediateThreadCleanup) { - m_create->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); AutoRequired ct; // Just create a CoreThread directly and have it pend some lambdas that will take awhile to run: @@ -172,7 +174,7 @@ TEST_F(ContextCleanupTest, VerifyImmediateThreadCleanup) { *ct += [called] { *called = true; }; // Verify that a graceful shutdown ensures both lambdas are called: - m_create->SignalTerminate(true); + ctxt->SignalTerminate(true); ASSERT_FALSE(*called) << "Immediate shutdown incorrectly ran down the dispatch queue"; } @@ -210,22 +212,23 @@ class TakesALongTimeToExit: TEST_F(ContextCleanupTest, VerifyThreadShutdownInterleave) { // Record the initial use count: - auto initCount = m_create.use_count(); + AutoCurrentContext ctxt; + auto initCount = ctxt.use_count(); // Create a thread that will take awhile to stop: AutoRequired longTime; // We want threads to run as soon as they are added: - m_create->Initiate(); + ctxt->Initiate(); // Make the thread exit before the enclosing context exits: longTime->Continue(); longTime->Stop(); // Now stop the context and perform an explicit wait - m_create->SignalShutdown(true); + ctxt->SignalShutdown(true); // At this point, the thread must have returned AND released its shared pointer to the enclosing context - EXPECT_EQ(initCount, m_create.use_count()) << "Context thread persisted even after it should have fallen out of scope"; + EXPECT_EQ(initCount, ctxt.use_count()) << "Context thread persisted even after it should have fallen out of scope"; } diff --git a/src/autowiring/test/ContextCleanupTest.hpp b/src/autowiring/test/ContextCleanupTest.hpp index 7d04a984e..e32ba5a92 100644 --- a/src/autowiring/test/ContextCleanupTest.hpp +++ b/src/autowiring/test/ContextCleanupTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class ContextCleanupTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/ContextCreatorTest.hpp b/src/autowiring/test/ContextCreatorTest.hpp index 6c91c8969..0a3b96bc2 100644 --- a/src/autowiring/test/ContextCreatorTest.hpp +++ b/src/autowiring/test/ContextCreatorTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class ContextCreatorTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/ContextEnumeratorTest.hpp b/src/autowiring/test/ContextEnumeratorTest.hpp index 77214b2d8..156f63b27 100644 --- a/src/autowiring/test/ContextEnumeratorTest.hpp +++ b/src/autowiring/test/ContextEnumeratorTest.hpp @@ -3,5 +3,5 @@ #include "EnclosedContextTestBase.hpp" class ContextEnumeratorTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/ContextMapTest.hpp b/src/autowiring/test/ContextMapTest.hpp index fe21c0dcd..a559e5e5b 100644 --- a/src/autowiring/test/ContextMapTest.hpp +++ b/src/autowiring/test/ContextMapTest.hpp @@ -1,11 +1,8 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. -#ifndef _CONTEXT_MAP_TEST_H -#define _CONTEXT_MAP_TEST_H -#include +#pragma once class ContextMapTest: public testing::Test { }; -#endif diff --git a/src/autowiring/test/ContextMemberTest.hpp b/src/autowiring/test/ContextMemberTest.hpp index cc76ac744..4f2a7ef81 100644 --- a/src/autowiring/test/ContextMemberTest.hpp +++ b/src/autowiring/test/ContextMemberTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class ContextMemberTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/CoreContextTest.cpp b/src/autowiring/test/CoreContextTest.cpp index c8786a5ff..406883ed5 100644 --- a/src/autowiring/test/CoreContextTest.cpp +++ b/src/autowiring/test/CoreContextTest.cpp @@ -12,6 +12,8 @@ class Bar{}; class Baz{}; TEST_F(CoreContextTest, TestEnumerateChildren) { + AutoCurrentContext ctxt; + // Create a few anonymous children: AutoCreateContext child1; AutoCreateContext child2; @@ -26,7 +28,7 @@ TEST_F(CoreContextTest, TestEnumerateChildren) { ASSERT_EQ(4UL, allChildren.size()) << "Failed to enumerate the correct number of child contexts"; // Verify full membership: - ASSERT_EQ(1UL, allChildren.count(m_create)) << "Failed to find the root context in the returned context collection"; + ASSERT_EQ(1UL, allChildren.count(ctxt)) << "Failed to find the root context in the returned context collection"; const char* childMissing = "Failed to find a child context in the set of children"; ASSERT_EQ(1UL, allChildren.count(child1)) << childMissing; @@ -38,23 +40,25 @@ TEST_F(CoreContextTest, TestEnumerateChildren) { AutoCreateContextT barCtxt; auto childFoo = barCtxt->Create(); - ContextEnumeratorT enumerator1(m_create); + ContextEnumeratorT enumerator1(ctxt); std::vector> onlyFoos(enumerator1.begin(), enumerator1.end()); ASSERT_EQ(2UL, onlyFoos.size()) << "Didn't collect only contexts with 'Foo' sigil"; ASSERT_NE(std::find(onlyFoos.begin(), onlyFoos.end(), fooCtxt), onlyFoos.end()) << "Context not enumerated"; ASSERT_NE(std::find(onlyFoos.begin(), onlyFoos.end(), childFoo), onlyFoos.end()) << "Context not enumerated"; - ContextEnumeratorT enumerator2(m_create); + ContextEnumeratorT enumerator2(ctxt); std::vector> onlyBars(enumerator2.begin(), enumerator2.end()); ASSERT_EQ(1UL, onlyBars.size()) << "Didn't collect only contexts with 'Bar' sigil"; ASSERT_NE(std::find(onlyBars.begin(), onlyBars.end(), barCtxt), onlyBars.end()) << "Context not enumerated"; - ContextEnumeratorT enumerator3(m_create); + ContextEnumeratorT enumerator3(ctxt); std::vector> noBaz(enumerator3.begin(), enumerator3.end()); ASSERT_TRUE(noBaz.empty()) << "Incorrectly collected contexts with 'Baz' sigil"; } TEST_F(CoreContextTest, TestEarlyLambdaReturn) { + AutoCurrentContext ctxt; + // Create three children: AutoCreateContext child1; AutoCreateContext child2; @@ -72,7 +76,7 @@ TEST_F(CoreContextTest, TestEarlyLambdaReturn) { ASSERT_EQ(3UL, allChildren.size()) << "Enumeration routine failed to quit early"; // Verify that the root context is the first one enumerated--needed to assure that we are executing a depth-first search - ASSERT_EQ(m_create, allChildren[0]) << "EnumerateChildContexts did not execute depth-first"; + ASSERT_EQ(ctxt, allChildren[0]) << "EnumerateChildContexts did not execute depth-first"; } /// diff --git a/src/autowiring/test/CoreContextTest.hpp b/src/autowiring/test/CoreContextTest.hpp index d1763c31d..0e6ef29f0 100644 --- a/src/autowiring/test/CoreContextTest.hpp +++ b/src/autowiring/test/CoreContextTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class CoreContextTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/CoreJobTest.cpp b/src/autowiring/test/CoreJobTest.cpp index 051a60f06..e4f9ba001 100644 --- a/src/autowiring/test/CoreJobTest.cpp +++ b/src/autowiring/test/CoreJobTest.cpp @@ -7,25 +7,26 @@ TEST_F(CoreJobTest, VerifySimpleProperties) { AutoRequired jb; + AutoCurrentContext ctxt; - ASSERT_FALSE(m_create->IsInitiated()) << "CoreJob reported it could receive events before its enclosing context was created"; + ASSERT_FALSE(ctxt->IsInitiated()) << "CoreJob reported it could receive events before its enclosing context was created"; // Create a thread which will delay for acceptance, and then quit: - auto future = std::async(std::launch::async, [this] { - m_create->DelayUntilInitiated(); + auto future = std::async(std::launch::async, [this, &ctxt] { + ctxt->DelayUntilInitiated(); }); // Verify that this thread doesn't back out right away: ASSERT_EQ(std::future_status::timeout, future.wait_for(std::chrono::milliseconds(10))) << "CoreJob did not block a client who was waiting for its readiness to accept dispatchers"; // Now start the context and verify that certain properties changed as anticipated: - m_create->Initiate(); - ASSERT_TRUE(m_create->DelayUntilInitiated()) << "CoreJob did not correctly delay for dispatch acceptance"; + ctxt->Initiate(); + ASSERT_TRUE(ctxt->DelayUntilInitiated()) << "CoreJob did not correctly delay for dispatch acceptance"; // Verify that the blocked thread has become unblocked and quits properly: ASSERT_EQ(std::future_status::ready, future.wait_for(std::chrono::seconds(1))) << "CoreJob did not correctly signal a blocked thread that it was ready to accept dispatchers"; - m_create->SignalShutdown(true); + ctxt->SignalShutdown(true); } TEST_F(CoreJobTest, VerifySimpleSubmission) { diff --git a/src/autowiring/test/CoreJobTest.hpp b/src/autowiring/test/CoreJobTest.hpp index 405af10db..79cc310c6 100644 --- a/src/autowiring/test/CoreJobTest.hpp +++ b/src/autowiring/test/CoreJobTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class CoreJobTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/CoreThreadTest.cpp b/src/autowiring/test/CoreThreadTest.cpp index 29440a3cf..ff8ab9e5a 100644 --- a/src/autowiring/test/CoreThreadTest.cpp +++ b/src/autowiring/test/CoreThreadTest.cpp @@ -48,10 +48,12 @@ class SpamguardTest: }; TEST_F(CoreThreadTest, VerifyStartSpam) { + AutoCurrentContext ctxt; + // Create our thread class: AutoRequired instance; - m_create->Initiate(); + ctxt->Initiate(); // This shouldn't cause another thread to be created: instance->Start(std::shared_ptr((Object*) 1, [] (Object*) {})); @@ -71,8 +73,10 @@ class InvokesIndefiniteWait: }; TEST_F(CoreThreadTest, VerifyIndefiniteDelay) { + AutoCurrentContext ctxt; + AutoRequired instance; - m_create->Initiate(); + ctxt->Initiate(); // Verify that the instance does not quit until we pend something: ASSERT_FALSE(instance->WaitFor(std::chrono::milliseconds(10))) << "Thread instance exited prematurely, when it should have been waiting indefinitely"; @@ -83,6 +87,7 @@ TEST_F(CoreThreadTest, VerifyIndefiniteDelay) { } TEST_F(CoreThreadTest, VerifyNestedTermination) { + AutoCurrentContext ctxt; std::shared_ptr st; // Insert a thread into a second-order subcontext: @@ -104,7 +109,7 @@ TEST_F(CoreThreadTest, VerifyNestedTermination) { ASSERT_TRUE(st->IsRunning()) << "Child thread was not running as expected"; // Shut down the enclosing context: - m_create->SignalTerminate(true); + ctxt->SignalTerminate(true); // Verify that the child thread has stopped: ASSERT_FALSE(st->IsRunning()) << "Child thread was running even though the enclosing context was terminated"; @@ -137,7 +142,7 @@ class ListenThread : } }; -TEST_F(CoreThreadTest, VerifyDispatchQueueShutdown) { +TEST_F(CoreThreadTest, AUTOTHROW_VerifyDispatchQueueShutdown) { AutoCreateContext ctxt; CurrentContextPusher pusher(ctxt); @@ -160,7 +165,7 @@ TEST_F(CoreThreadTest, VerifyDispatchQueueShutdown) { } -TEST_F(CoreThreadTest, VerifyNoLeakOnExecptions) { +TEST_F(CoreThreadTest, AUTOTHROW_VerifyNoLeakOnExecptions) { AutoCreateContext ctxt; CurrentContextPusher pshr(ctxt); @@ -182,8 +187,10 @@ TEST_F(CoreThreadTest, VerifyNoLeakOnExecptions) { } TEST_F(CoreThreadTest, VerifyDelayedDispatchQueueSimple) { + AutoCurrentContext ctxt; + // Run our threads immediately, no need to wait - m_create->Initiate(); + ctxt->Initiate(); // Create a thread which we'll use just to pend dispatch events: AutoRequired t; @@ -210,7 +217,8 @@ TEST_F(CoreThreadTest, VerifyDelayedDispatchQueueSimple) { } TEST_F(CoreThreadTest, VerifyNoDelayDoubleFree) { - m_create->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); // We won't actually be referencing this, we just want to make sure it's not destroyed early std::shared_ptr x(new bool); @@ -228,8 +236,10 @@ TEST_F(CoreThreadTest, VerifyNoDelayDoubleFree) { } TEST_F(CoreThreadTest, VerifyDoublePendedDispatchDelay) { + AutoCurrentContext ctxt; + // Immediately pend threads: - m_create->Initiate(); + ctxt->Initiate(); // Some variables that we will set to true as the test proceeds: std::shared_ptr x(new bool(false)); @@ -255,7 +265,8 @@ TEST_F(CoreThreadTest, VerifyDoublePendedDispatchDelay) { } TEST_F(CoreThreadTest, VerifyTimedSort) { - m_create->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); AutoRequired t; std::vector v; @@ -277,7 +288,8 @@ TEST_F(CoreThreadTest, VerifyTimedSort) { } TEST_F(CoreThreadTest, VerifyPendByTimePoint) { - m_create->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); AutoRequired t; // Pend by an absolute time point, nothing really special here @@ -311,17 +323,18 @@ class WaitsALongTimeThenQuits: }; TEST_F(CoreThreadTest, NestedContextWait) { + AutoCurrentContext ctxt; + // Initiate the outer context: - m_create->Initiate(); + ctxt->Initiate(); // Create a subcontext which has our delay thread in it: - AutoCreateContext ctxt; auto waitsAwhile = ctxt->Inject(); ctxt->Initiate(); // Stop and delay on the outer context: - m_create->SignalShutdown(); - m_create->Wait(); + ctxt->SignalShutdown(); + ctxt->Wait(); // Now we verify that our interior thread has actually quit: ASSERT_TRUE(!waitsAwhile->IsRunning()) << "Inner thread was marked running by CoreThread when outer context returned"; @@ -329,11 +342,13 @@ TEST_F(CoreThreadTest, NestedContextWait) { } TEST_F(CoreThreadTest, WaitBeforeInitiate) { + AutoCurrentContext ctxt; + // Wait for the outer context before it's actually initiated: - ASSERT_FALSE(m_create->Wait(std::chrono::seconds(0))) << "A wait operation on a context succeeded even though it was not yet started"; + ASSERT_FALSE(ctxt->Wait(std::chrono::seconds(0))) << "A wait operation on a context succeeded even though it was not yet started"; // Stop the outer context without even starting it - m_create->SignalTerminate(); + ctxt->SignalTerminate(); // Try to add a thread to the context. This should cause the thread to be immediately marked as "stopped" and should allow a Wait // operation on the thread to return right away. @@ -343,7 +358,7 @@ TEST_F(CoreThreadTest, WaitBeforeInitiate) { ASSERT_TRUE(ct->WaitFor(std::chrono::seconds(0))) << "A thread added to an already-stopped context did not correctly respond to a zero-duration wait"; // Wait again. This should suceed right away. - ASSERT_TRUE(m_create->Wait(std::chrono::seconds(0))) << "Failed to wait on a context which should have already been stopped"; + ASSERT_TRUE(ctxt->Wait(std::chrono::seconds(0))) << "Failed to wait on a context which should have already been stopped"; } template @@ -372,6 +387,7 @@ class JustIncrementsANumber: }; TEST_F(CoreThreadTest, ReentrantStopOnTeardown) { + AutoCurrentContext ctxt; std::shared_ptr ct = AutoRequired(); // Our thread will try to stop itself on teardown, this will cause it to trivially deadlock if any locks @@ -381,9 +397,9 @@ TEST_F(CoreThreadTest, ReentrantStopOnTeardown) { }); // Kickoff and then delay: - m_create->Initiate(); - m_create->SignalShutdown(); - ASSERT_TRUE(m_create->Wait(std::chrono::seconds(1))) << "Thread deadlocked when attempting to stop itself from a teardown listener"; + ctxt->Initiate(); + ctxt->SignalShutdown(); + ASSERT_TRUE(ctxt->Wait(std::chrono::seconds(1))) << "Thread deadlocked when attempting to stop itself from a teardown listener"; } class VerifiesCurrentContextOnRundown: @@ -449,10 +465,12 @@ TEST_F(CoreThreadTest, PendAfterShutdown) { #include "windows.h" TEST_F(CoreThreadTest, VerifyCanBoostPriority) { + AutoCurrentContext ctxt; + // Create two spinners and kick them off at the same time: AutoRequired> lower; AutoRequired> higher; - m_create->Initiate(); + ctxt->Initiate(); // We want all of our threads to run on ONE cpu for awhile, and then we want to put it back at exit DWORD_PTR originalAffinity, systemAffinity; @@ -486,7 +504,7 @@ TEST_F(CoreThreadTest, VerifyCanBoostPriority) { } // Need to terminate before we try running a comparison. - m_create->SignalTerminate(); + ctxt->SignalTerminate(); ASSERT_LE(lower->val, higher->val) << "A lower-priority thread was moved out of the sleep queue more frequently than a high-priority thread"; } diff --git a/src/autowiring/test/CoreThreadTest.hpp b/src/autowiring/test/CoreThreadTest.hpp index ee0d9f51d..beba6871c 100644 --- a/src/autowiring/test/CoreThreadTest.hpp +++ b/src/autowiring/test/CoreThreadTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class CoreThreadTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/CurrentContextPusherTest.hpp b/src/autowiring/test/CurrentContextPusherTest.hpp index 8fa2574ae..f64dda87c 100644 --- a/src/autowiring/test/CurrentContextPusherTest.hpp +++ b/src/autowiring/test/CurrentContextPusherTest.hpp @@ -1,6 +1,5 @@ // Copyright (c) 2010 - 2013 Leap Motion. All rights reserved. Proprietary and confidential. #pragma once -#include class CurrentContextPusherTest: public testing::Test diff --git a/src/autowiring/test/DecoratorTest.hpp b/src/autowiring/test/DecoratorTest.hpp index 3bf1543a6..3ab4421fc 100644 --- a/src/autowiring/test/DecoratorTest.hpp +++ b/src/autowiring/test/DecoratorTest.hpp @@ -1,9 +1,8 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class DecoratorTest: - public EnclosedContextTestBase + public testing::Test { public: DecoratorTest(void); diff --git a/src/autowiring/test/DispatchQueueTest.cpp b/src/autowiring/test/DispatchQueueTest.cpp index 38571b4a8..10879131f 100644 --- a/src/autowiring/test/DispatchQueueTest.cpp +++ b/src/autowiring/test/DispatchQueueTest.cpp @@ -48,7 +48,8 @@ TEST_F(DispatchQueueTest, PathologicalStartAndStop){ AutoRequired> t2; AutoRequired> t3; AutoRequired> t4; - m_create->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); // We don't need a strong guarantee that these threads exit in a timely fashion, just that they // do so _eventually_. diff --git a/src/autowiring/test/DispatchQueueTest.hpp b/src/autowiring/test/DispatchQueueTest.hpp index 753f266de..908ac5820 100644 --- a/src/autowiring/test/DispatchQueueTest.hpp +++ b/src/autowiring/test/DispatchQueueTest.hpp @@ -1,10 +1,9 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class DispatchQueue; class DispatchQueueTest: - public EnclosedContextTestBase, + public testing::Test, public DispatchQueue {}; diff --git a/src/autowiring/test/DtorCorrectnessTest.cpp b/src/autowiring/test/DtorCorrectnessTest.cpp index ef9b46e5f..4a179231f 100644 --- a/src/autowiring/test/DtorCorrectnessTest.cpp +++ b/src/autowiring/test/DtorCorrectnessTest.cpp @@ -120,7 +120,6 @@ TEST_F(DtorCorrectnessTest, VerifyDeferringDtors) { EXPECT_TRUE(listener2->m_hitDeferred) << "Failed to hit a listener's deferred call"; // Release all of our pointers: - m_create.reset(); listener1.reset(); listener2.reset(); diff --git a/src/autowiring/test/DtorCorrectnessTest.hpp b/src/autowiring/test/DtorCorrectnessTest.hpp index f0251bf6d..e509afe27 100644 --- a/src/autowiring/test/DtorCorrectnessTest.hpp +++ b/src/autowiring/test/DtorCorrectnessTest.hpp @@ -1,13 +1,12 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class CtorDtorListener; template class MyCtorDtorListenerN; class DtorCorrectnessTest: - public EnclosedContextTestBase + public testing::Test { public: DtorCorrectnessTest(void); diff --git a/src/autowiring/test/EnclosedContextTestBase.cpp b/src/autowiring/test/EnclosedContextTestBase.cpp new file mode 100644 index 000000000..f342860c1 --- /dev/null +++ b/src/autowiring/test/EnclosedContextTestBase.cpp @@ -0,0 +1,61 @@ +#include "stdafx.h" +#include "EnclosedContextTestBase.hpp" + +struct TestInfoProxy { + TestInfoProxy(const testing::TestInfo& info) : + m_info(info) + {} + + const testing::TestInfo& m_info; +}; + +void EnclosedContextTestBase::OnTestStart(const testing::TestInfo& info) { + AutoRequired filter; + + // The context proper. This is automatically assigned as the current + // context when SetUp is invoked. + AutoCreateContext create; + create->Construct(info); + + // Add exception filter in this context: + create->Inject(); + + // Now make it current and let the test run: + create->SetCurrent(); +} + +void EnclosedContextTestBase::OnTestEnd(const testing::TestInfo& info) { + // Verify we can grab the test case back out and that the pointer is correct: + Autowired ti; + Autowired ecef; + auto ctxt = ecef ? ecef->GetContext() : nullptr; + + // Unconditionally reset the global context as the current context + AutoGlobalContext()->SetCurrent(); + + // Global initialization tests are special, we don't bother checking closure principle on them: + if(!strcmp("GlobalInitTest", info.test_case_name())) + return; + + // Need to make sure we got back our exception filter before continuing: + ASSERT_TRUE(ecef.IsAutowired()) << "Failed to find the enclosed context exception filter; unit test may have incorrectly reset the enclosing context before returning"; + + // Now try to tear down the test context enclosure: + ctxt->SignalShutdown(); + + // Do not allow teardown to take more than 250 milliseconds or so + if(!ctxt->Wait(std::chrono::milliseconds(250))) { + // Critical error--took too long to tear down + assert(false); + } + + static const char sc_autothrow[] = "AUTOTHROW_"; + if(!strncmp(sc_autothrow, info.name(), ARRAYCOUNT(sc_autothrow) - 1)) + // Throw expected, end here + return; + + // If an exception occurred somewhere, report it: + ASSERT_FALSE(ecef->m_excepted) + << "An unhandled exception occurred in this context" << std::endl + << "[" << (ecef->m_ti ? ecef->m_ti->name() : "unknown") << "] " << ecef->m_what; +} \ No newline at end of file diff --git a/src/autowiring/test/EnclosedContextTestBase.hpp b/src/autowiring/test/EnclosedContextTestBase.hpp index f8a2aad0b..c320a002e 100644 --- a/src/autowiring/test/EnclosedContextTestBase.hpp +++ b/src/autowiring/test/EnclosedContextTestBase.hpp @@ -1,10 +1,38 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once - -#include -#include #include MEMORY_HEADER +/// +/// General purpose exception filter, used for tracking exceptions thrown from unit test CoreThreads +/// +class EnclosedContextExceptionFilter: + public ContextMember, + public ExceptionFilter +{ +public: + EnclosedContextExceptionFilter(void) : + ContextMember("EnclosedContextExceptionFilter"), + m_excepted(false) + {} + + bool m_excepted; + + const std::type_info* m_ti; + std::string m_what; + + void Filter(void) override { + m_excepted = true; + try { + throw; + } + catch(std::exception& except) { + m_ti = &typeid(except); + m_what = except.what(); + } + catch(...) {} + } +}; + /// /// Provides a test fixture which ensures proper cleanup of a created subcontext /// @@ -15,45 +43,14 @@ /// destructor which performs teardown in a different way. /// class EnclosedContextTestBase: - public testing::Test + public testing::EmptyTestEventListener { -public: - EnclosedContextTestBase(void): - m_pshr(m_create) - { - m_createWeak = m_create; - } - - ~EnclosedContextTestBase(void) { - // Only attempt teardown if it hasn't already happened: - auto ctxt = m_createWeak.lock(); - if(!ctxt) - return; - - ctxt->SignalShutdown(); - - // Do not allow teardown to take more than a millisecond - if(!ctxt->Wait(std::chrono::milliseconds(250))) { - // Critical error--took too long to tear down - assert(false); - } - } - -protected: - // The context proper. This is automatically assigned as the current - // context when SetUp is invoked. - AutoCreateContext m_create; - - // Currency pusher: - CurrentContextPusher m_pshr; - private: // Weak pointer to the created context, used to detect proper context destruction std::weak_ptr m_createWeak; public: - /// - /// True if there are no outstanding pointers to the created context, except the one held by base - /// - bool IsContextClean(void) const {return m_create.unique();} + // Base overrides: + void OnTestStart(const testing::TestInfo& info) override; + void OnTestEnd(const testing::TestInfo& info) override; }; diff --git a/src/autowiring/test/EventReceiverTest.cpp b/src/autowiring/test/EventReceiverTest.cpp index 9aae7adf6..21b38eaab 100644 --- a/src/autowiring/test/EventReceiverTest.cpp +++ b/src/autowiring/test/EventReceiverTest.cpp @@ -304,11 +304,12 @@ TEST_F(EventReceiverTest, PathologicalTransmitterTest) { } TEST_F(EventReceiverTest, VerifyDirectInvocation) { + AutoCurrentContext ctxt; AutoRequired receiver; // Indirect invocation: - m_create->Invoke(&CallableInterface::ZeroArgs)(); - m_create->Invoke(&CallableInterface::OneArg)(100); + ctxt->Invoke(&CallableInterface::ZeroArgs)(); + ctxt->Invoke(&CallableInterface::OneArg)(100); // Verify that stuff happens even when the thread isn't running: EXPECT_TRUE(receiver->m_zero); diff --git a/src/autowiring/test/EventReceiverTest.hpp b/src/autowiring/test/EventReceiverTest.hpp index 9d7a99573..68ea1e3fe 100644 --- a/src/autowiring/test/EventReceiverTest.hpp +++ b/src/autowiring/test/EventReceiverTest.hpp @@ -1,9 +1,8 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class EventReceiverTest: - public EnclosedContextTestBase + public testing::Test { public: EventReceiverTest(void); diff --git a/src/autowiring/test/ExceptionFilterTest.cpp b/src/autowiring/test/ExceptionFilterTest.cpp index d60c58048..76d2e543c 100644 --- a/src/autowiring/test/ExceptionFilterTest.cpp +++ b/src/autowiring/test/ExceptionFilterTest.cpp @@ -82,7 +82,7 @@ class GenericFilter: } }; -TEST_F(ExceptionFilterTest, ExceptionDestruction) { +TEST_F(ExceptionFilterTest, AUTOTHROW_ExceptionDestruction) { // Add the exception filter type to the context first AutoRequired filter; @@ -90,7 +90,7 @@ TEST_F(ExceptionFilterTest, ExceptionDestruction) { AutoRequired> thrower; // Run: - m_create->Initiate(); + AutoCurrentContext()->Initiate(); thrower->Wait(); // Verify that the exception was destroyed the correct number of times: @@ -108,7 +108,7 @@ TEST_F(ExceptionFilterTest, CheckThrowThrow) { EXPECT_THROW(throw example(), std::exception) << "An exception type which throws from its ctor did not throw the expected type"; } -TEST_F(ExceptionFilterTest, ThreadThrowsCheck) { +TEST_F(ExceptionFilterTest, AUTOTHROW_ThreadThrowsCheck) { // Add the exception filter type to the context first AutoRequired filter; @@ -116,7 +116,7 @@ TEST_F(ExceptionFilterTest, ThreadThrowsCheck) { AutoRequired> thrower; // Wait for the thrower to terminate, should be pretty fast: - m_create->Initiate(); + AutoCurrentContext()->Initiate(); thrower->Wait(); // Hopefully the filter got hit in the right spot: @@ -160,10 +160,10 @@ TEST_F(ExceptionFilterTest, FireContainmentCheck) { EXPECT_TRUE(ctxt->IsShutdown()) << "An unhandled exception from a fire call in a context should have signalled it to stop"; // Verify that the parent context was protected: - EXPECT_FALSE(m_create->IsShutdown()) << "An unhandled exception incorrectly terminated a parent context"; + EXPECT_FALSE(AutoCurrentContext()->IsShutdown()) << "An unhandled exception incorrectly terminated a parent context"; } -TEST_F(ExceptionFilterTest, EnclosedThrowCheck) { +TEST_F(ExceptionFilterTest, AUTOTHROW_EnclosedThrowCheck) { // Create our listener: AutoRequired filter; @@ -209,7 +209,8 @@ TEST_F(ExceptionFilterTest, ExceptionFirewall) { } TEST_F(ExceptionFilterTest, VerifySimpleConfinement) { - m_create->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); // Create a subcontext where the errant recipients will live: AutoCreateContext child; @@ -224,7 +225,7 @@ TEST_F(ExceptionFilterTest, VerifySimpleConfinement) { tl(&ThrowingListener::DoThrow)(); // Verify that the parent scope wasn't incorrectly terminated: - EXPECT_FALSE(m_create->IsShutdown()) << "Parent scope was terminated incorrectly due to an exception sourced by a child context"; + EXPECT_FALSE(ctxt->IsShutdown()) << "Parent scope was terminated incorrectly due to an exception sourced by a child context"; // Verify that the child scope was terminated as expected: EXPECT_TRUE(child->IsShutdown()) << "An event recipient in a child scope threw an exception and the child context was not correctly terminated"; diff --git a/src/autowiring/test/ExceptionFilterTest.hpp b/src/autowiring/test/ExceptionFilterTest.hpp index 53a52b898..514746f09 100644 --- a/src/autowiring/test/ExceptionFilterTest.hpp +++ b/src/autowiring/test/ExceptionFilterTest.hpp @@ -1,8 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" - class ExceptionFilterTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/FactoryTest.hpp b/src/autowiring/test/FactoryTest.hpp index 80a449823..7ab0f7a09 100644 --- a/src/autowiring/test/FactoryTest.hpp +++ b/src/autowiring/test/FactoryTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class FactoryTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/GlobalInitTest.hpp b/src/autowiring/test/GlobalInitTest.hpp index a12511ef9..cdc47b078 100644 --- a/src/autowiring/test/GlobalInitTest.hpp +++ b/src/autowiring/test/GlobalInitTest.hpp @@ -1,6 +1,5 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include class GlobalInitTest: public testing::Test diff --git a/src/autowiring/test/GuardObjectTest.hpp b/src/autowiring/test/GuardObjectTest.hpp index d65d9464a..cf0e0b7d9 100644 --- a/src/autowiring/test/GuardObjectTest.hpp +++ b/src/autowiring/test/GuardObjectTest.hpp @@ -1,6 +1,5 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class GuardObjectTest: public testing::Test diff --git a/src/autowiring/test/InterlockedRoutinesTest.hpp b/src/autowiring/test/InterlockedRoutinesTest.hpp index c644aa95d..c85ded92e 100644 --- a/src/autowiring/test/InterlockedRoutinesTest.hpp +++ b/src/autowiring/test/InterlockedRoutinesTest.hpp @@ -1,6 +1,5 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include class InterlockedRoutinesTest: public testing::Test diff --git a/src/autowiring/test/MarshalingTest.hpp b/src/autowiring/test/MarshalingTest.hpp index 1bb8fafe5..1c2dd934c 100644 --- a/src/autowiring/test/MarshalingTest.hpp +++ b/src/autowiring/test/MarshalingTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class MarshalingTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/MultiInheritTest.hpp b/src/autowiring/test/MultiInheritTest.hpp index 4a2f3e12e..e65b5cf77 100644 --- a/src/autowiring/test/MultiInheritTest.hpp +++ b/src/autowiring/test/MultiInheritTest.hpp @@ -1,6 +1,5 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include class MultiInheritTest: public testing::Test diff --git a/src/autowiring/test/ObjectPoolTest.cpp b/src/autowiring/test/ObjectPoolTest.cpp index 694d1101b..31dfa234d 100644 --- a/src/autowiring/test/ObjectPoolTest.cpp +++ b/src/autowiring/test/ObjectPoolTest.cpp @@ -108,6 +108,7 @@ class HoldsSharedPtrThenQuits: }; TEST_F(ObjectPoolTest, EmptyPoolIssuance) { + AutoCurrentContext ctxt; ObjectPool pool; // Create the thread which will hold the shared pointer for awhile: @@ -123,7 +124,7 @@ TEST_F(ObjectPoolTest, EmptyPoolIssuance) { EXPECT_ANY_THROW(pool.Wait()) << "An attempt to obtain an element on an empty pool did not throw an exception as expected"; // Now see if we can delay for the thread to back out: - m_create->Initiate(); + ctxt->Initiate(); pool.Rundown(); // Verify that it got released as expected: diff --git a/src/autowiring/test/ObjectPoolTest.hpp b/src/autowiring/test/ObjectPoolTest.hpp index e38004663..f1e3dbeab 100644 --- a/src/autowiring/test/ObjectPoolTest.hpp +++ b/src/autowiring/test/ObjectPoolTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class ObjectPoolTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/PeerContextTest.cpp b/src/autowiring/test/PeerContextTest.cpp index 393a576a3..91a344b0a 100644 --- a/src/autowiring/test/PeerContextTest.cpp +++ b/src/autowiring/test/PeerContextTest.cpp @@ -10,7 +10,8 @@ struct PeerContextName2 {}; TEST_F(PeerContextTest, VerifySimplePeerage) { // Accept Events - AutoCurrentContext()->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); // Insert a simple receiver first: AutoRequired sr; @@ -29,7 +30,7 @@ TEST_F(PeerContextTest, VerifySimplePeerage) { { // Create a single peer context, make it current, and try to fire: - auto peer = m_create->CreatePeer(); + auto peer = ctxt->CreatePeer(); ASSERT_TRUE(nullptr != peer.get()) << "Peer context creation method returned a null pointer"; CurrentContextPusher pshr(peer); @@ -45,13 +46,14 @@ TEST_F(PeerContextTest, VerifySimplePeerage) { } TEST_F(PeerContextTest, VerifyPeerTransitivity) { - AutoCurrentContext()->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); // Insert our simple receiver: AutoRequired sr; // Now create the first peer context: - auto peer1 = m_create->CreatePeer(); + auto peer1 = ctxt->CreatePeer(); peer1->Initiate(); ASSERT_TRUE(nullptr != peer1.get()); @@ -72,13 +74,14 @@ TEST_F(PeerContextTest, VerifyPeerTransitivity) { TEST_F(PeerContextTest, VerifyNoAutowiringLeakage) { // Accept Events - AutoCurrentContext()->Initiate(); + AutoCurrentContext ctxt; + ctxt->Initiate(); // Insert a simple object in the base context AutoRequired obj1; // Create a peer context and make it current: - auto peer = m_create->CreatePeer(); + auto peer = ctxt->CreatePeer(); CurrentContextPusher pshr(peer); // Verify that, in this peer context, SimpleObject is not visible diff --git a/src/autowiring/test/PeerContextTest.hpp b/src/autowiring/test/PeerContextTest.hpp index ccaaee6c2..db4bcd0d7 100644 --- a/src/autowiring/test/PeerContextTest.hpp +++ b/src/autowiring/test/PeerContextTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class PeerContextTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/PostConstructTest.cpp b/src/autowiring/test/PostConstructTest.cpp index ca84b1e89..8d59ef70b 100644 --- a/src/autowiring/test/PostConstructTest.cpp +++ b/src/autowiring/test/PostConstructTest.cpp @@ -257,9 +257,10 @@ TEST_F(PostConstructTest, VerifyAllInstancesSatisfied) { TEST_F(PostConstructTest, ContextNotifyWhenAutowired) { auto called = std::make_shared(false); + AutoCurrentContext ctxt; // Now we'd like to be notified when SimpleObject gets added: - m_create->NotifyWhenAutowired( + ctxt->NotifyWhenAutowired( [called] { *called = true; } diff --git a/src/autowiring/test/PostConstructTest.hpp b/src/autowiring/test/PostConstructTest.hpp index f8e662c17..9dbb20275 100644 --- a/src/autowiring/test/PostConstructTest.hpp +++ b/src/autowiring/test/PostConstructTest.hpp @@ -1,8 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" - class PostConstructTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/ScopeTest.cpp b/src/autowiring/test/ScopeTest.cpp index 84faf6ea6..cabda8a89 100644 --- a/src/autowiring/test/ScopeTest.cpp +++ b/src/autowiring/test/ScopeTest.cpp @@ -109,6 +109,7 @@ TEST_F(ScopeTest, AutowiringHeapMangle){ } TEST_F(ScopeTest, AutowiringOrdering) { + AutoCurrentContext ctxt; AutoCreateContext outer; CurrentContextPusher outerPshr(outer); AutoCreateContext inner1; @@ -155,7 +156,7 @@ TEST_F(ScopeTest, AutowiringOrdering) { // Verify preconditions and postconditions on autowiring: ASSERT_FALSE(d.IsAutowired()); ASSERT_FALSE(d2.IsAutowired()); - AutoRequired derp(m_create); + AutoRequired derp(ctxt); ASSERT_TRUE(d.IsAutowired()) << "Outer scope autowired field failed to be instantiated on an element created in an interior scope"; ASSERT_TRUE(d2.IsAutowired()) << "Interior scope field failed to be satisfied by a field initiated at an outer context"; diff --git a/src/autowiring/test/ScopeTest.hpp b/src/autowiring/test/ScopeTest.hpp index 020b314e7..dc1fa09c9 100644 --- a/src/autowiring/test/ScopeTest.hpp +++ b/src/autowiring/test/ScopeTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class ScopeTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/SelfSelectingFixtureTest.cpp b/src/autowiring/test/SelfSelectingFixtureTest.cpp index 7229b5680..a7e0f44da 100644 --- a/src/autowiring/test/SelfSelectingFixtureTest.cpp +++ b/src/autowiring/test/SelfSelectingFixtureTest.cpp @@ -28,6 +28,7 @@ class HitCountingBolt: }; TEST_F(SelfSelectingFixtureTest, LocalFixtureTest) { + AutoCurrentContext ctxt; Autowired hcb; ASSERT_FALSE(hcb.IsAutowired()) << "Hit-counting bolt was created before it was enabled"; @@ -38,7 +39,7 @@ TEST_F(SelfSelectingFixtureTest, LocalFixtureTest) { ASSERT_TRUE(hcb.IsAutowired()) << "Bolt not created after being enabled"; // Verify the bolt gets hit: - m_create->Create(); + ctxt->Create(); ASSERT_EQ(1UL, hcb->m_hitCount) << "Bolt was not hit when a matching class was created"; } diff --git a/src/autowiring/test/SelfSelectingFixtureTest.hpp b/src/autowiring/test/SelfSelectingFixtureTest.hpp index f56d9e94c..d6f152d28 100644 --- a/src/autowiring/test/SelfSelectingFixtureTest.hpp +++ b/src/autowiring/test/SelfSelectingFixtureTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class SelfSelectingFixtureTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/SnoopTest.hpp b/src/autowiring/test/SnoopTest.hpp index 5497607a4..f8288cb13 100644 --- a/src/autowiring/test/SnoopTest.hpp +++ b/src/autowiring/test/SnoopTest.hpp @@ -1,8 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" - class SnoopTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/TeardownNotifierTest.hpp b/src/autowiring/test/TeardownNotifierTest.hpp index 4914483ce..5d72901a7 100644 --- a/src/autowiring/test/TeardownNotifierTest.hpp +++ b/src/autowiring/test/TeardownNotifierTest.hpp @@ -1,6 +1,5 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include class TeardownNotifierTest: public testing::Test diff --git a/src/autowiring/test/TypeRegistryTest.hpp b/src/autowiring/test/TypeRegistryTest.hpp index 58c53197b..066e3fdd5 100644 --- a/src/autowiring/test/TypeRegistryTest.hpp +++ b/src/autowiring/test/TypeRegistryTest.hpp @@ -1,7 +1,6 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include "EnclosedContextTestBase.hpp" class TypeRegistryTest: - public EnclosedContextTestBase + public testing::Test {}; diff --git a/src/autowiring/test/UuidTest.hpp b/src/autowiring/test/UuidTest.hpp index 251a4bc7a..37f285805 100644 --- a/src/autowiring/test/UuidTest.hpp +++ b/src/autowiring/test/UuidTest.hpp @@ -1,6 +1,5 @@ // Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. #pragma once -#include class UuidTest: public testing::Test diff --git a/src/autowiring/test/gtest-all-guard.cpp b/src/autowiring/test/gtest-all-guard.cpp index 0d56368eb..4dc76c94e 100644 --- a/src/autowiring/test/gtest-all-guard.cpp +++ b/src/autowiring/test/gtest-all-guard.cpp @@ -4,6 +4,7 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-private-field" #endif +#include "EnclosedContextTestBase.hpp" #include #include @@ -23,6 +24,8 @@ int main(int argc, char* argv[]) g_argc = argc; g_argv = argv; + auto& listeners = testing::UnitTest::GetInstance()->listeners(); + listeners.Append(new EnclosedContextTestBase); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/autowiring/test/stdafx.h b/src/autowiring/test/stdafx.h index eee35a962..0bf9972e9 100644 --- a/src/autowiring/test/stdafx.h +++ b/src/autowiring/test/stdafx.h @@ -3,9 +3,9 @@ #include #include +#include #ifdef _MSC_VER - #include #include #include #endif