Skip to content

Commit

Permalink
Merge pull request #17 from leapmotion/ref-tests
Browse files Browse the repository at this point in the history
Switching EnclosedContextTestBase to be a filter rather than a base type
  • Loading branch information
gtremper committed Jul 31, 2014
2 parents c9ff391 + 5fcc423 commit fb55296
Show file tree
Hide file tree
Showing 59 changed files with 239 additions and 182 deletions.
3 changes: 1 addition & 2 deletions src/autowiring/test/AnySharedPointerTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
3 changes: 1 addition & 2 deletions src/autowiring/test/AutoAnchorTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};

3 changes: 1 addition & 2 deletions src/autowiring/test/AutoFilterTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
3 changes: 1 addition & 2 deletions src/autowiring/test/AutoInjectableTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
3 changes: 1 addition & 2 deletions src/autowiring/test/AutoPacketFactoryTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
3 changes: 1 addition & 2 deletions src/autowiring/test/AutowiringBenchmarkTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
2 changes: 1 addition & 1 deletion src/autowiring/test/AutowiringTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

TEST_F(AutowiringTest, VerifyAutowiredFast) {
// Add an object:
m_create->Inject<SimpleObject>();
AutoCurrentContext()->Inject<SimpleObject>();

// Verify that AutowiredFast can find this object
AutowiredFast<SimpleObject> sobj;
Expand Down
3 changes: 1 addition & 2 deletions src/autowiring/test/AutowiringTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
3 changes: 1 addition & 2 deletions src/autowiring/test/AutowiringUtilitiesTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
3 changes: 1 addition & 2 deletions src/autowiring/test/BasicThreadTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
11 changes: 7 additions & 4 deletions src/autowiring/test/BoltTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ class InjectsIntoEverything:
};

TEST_F(BoltTest, VerifySimpleInjection) {
AutoCurrentContext ctxt;
AutoEnable<InjectsIntoPipeline>();

auto created = m_create->Create<Pipeline>();
auto created = ctxt->Create<Pipeline>();

// Verify that the SimpleObject didn't accidentally get injected out here:
{
Expand Down Expand Up @@ -143,10 +144,11 @@ TEST_F(BoltTest, VerifyCreationBubbling) {
}

TEST_F(BoltTest, VerifyMultipleInjection) {
AutoCurrentContext ctxt;
AutoEnable<InjectsIntoBoth>();

auto created = m_create->Create<Pipeline>();
auto created2 = m_create->Create<OtherContext>();
auto created = ctxt->Create<Pipeline>();
auto created2 = ctxt->Create<OtherContext>();

// Verify that the SimpleObject didn't accidentally get injected out here:
{
Expand All @@ -168,6 +170,7 @@ TEST_F(BoltTest, VerifyMultipleInjection) {
}

TEST_F(BoltTest, EmptyBolt) {
AutoCurrentContext ctxt;
AutoEnable<InjectsIntoEverything>();
Autowired<CountObject> so;
EXPECT_FALSE(so.IsAutowired()) << "CountObject injected into outer context";
Expand All @@ -180,7 +183,7 @@ TEST_F(BoltTest, EmptyBolt) {
ASSERT_EQ(1, innerSo->count) << "ContextCreated() called incorrect number of times";
}

auto created2 = m_create->Create<Pipeline>();
auto created2 = ctxt->Create<Pipeline>();
{
CurrentContextPusher pshr(created2);
Autowired<CountObject> innerSo;
Expand Down
3 changes: 1 addition & 2 deletions src/autowiring/test/BoltTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
1 change: 1 addition & 0 deletions src/autowiring/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(AutowiringTest_SRCS
DtorCorrectnessTest.hpp
DtorCorrectnessTest.cpp
EnclosedContextTestBase.hpp
EnclosedContextTestBase.cpp
ExceptionFilterTest.hpp
ExceptionFilterTest.cpp
EventReceiverTest.hpp
Expand Down
19 changes: 11 additions & 8 deletions src/autowiring/test/ContextCleanupTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class ReceivesTeardownNotice:
};

TEST_F(ContextCleanupTest, VerifyGracefulThreadCleanup) {
m_create->Initiate();
AutoCurrentContext ctxt;
ctxt->Initiate();
AutoRequired<CoreThread> ct;

// Just create a CoreThread directly and have it pend some lambdas that will take awhile to run:
Expand All @@ -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<CoreThread> ct;

// Just create a CoreThread directly and have it pend some lambdas that will take awhile to run:
Expand All @@ -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";
}

Expand Down Expand Up @@ -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<TakesALongTimeToExit> 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";
}

3 changes: 1 addition & 2 deletions src/autowiring/test/ContextCleanupTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
3 changes: 1 addition & 2 deletions src/autowiring/test/ContextCreatorTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
2 changes: 1 addition & 1 deletion src/autowiring/test/ContextEnumeratorTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include "EnclosedContextTestBase.hpp"

class ContextEnumeratorTest:
public EnclosedContextTestBase
public testing::Test
{};
5 changes: 1 addition & 4 deletions src/autowiring/test/ContextMapTest.hpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>
#pragma once

class ContextMapTest:
public testing::Test
{
};

#endif
3 changes: 1 addition & 2 deletions src/autowiring/test/ContextMemberTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
14 changes: 9 additions & 5 deletions src/autowiring/test/CoreContextTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Bar{};
class Baz{};

TEST_F(CoreContextTest, TestEnumerateChildren) {
AutoCurrentContext ctxt;

// Create a few anonymous children:
AutoCreateContext child1;
AutoCreateContext child2;
Expand All @@ -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;
Expand All @@ -38,23 +40,25 @@ TEST_F(CoreContextTest, TestEnumerateChildren) {
AutoCreateContextT<Bar> barCtxt;
auto childFoo = barCtxt->Create<Foo>();

ContextEnumeratorT<Foo> enumerator1(m_create);
ContextEnumeratorT<Foo> enumerator1(ctxt);
std::vector<std::shared_ptr<CoreContext>> 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<Bar> enumerator2(m_create);
ContextEnumeratorT<Bar> enumerator2(ctxt);
std::vector<std::shared_ptr<CoreContext>> 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<Baz> enumerator3(m_create);
ContextEnumeratorT<Baz> enumerator3(ctxt);
std::vector<std::shared_ptr<CoreContext>> 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;
Expand All @@ -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";
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/autowiring/test/CoreContextTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
13 changes: 7 additions & 6 deletions src/autowiring/test/CoreJobTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@

TEST_F(CoreJobTest, VerifySimpleProperties) {
AutoRequired<CoreJob> 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) {
Expand Down
3 changes: 1 addition & 2 deletions src/autowiring/test/CoreJobTest.hpp
Original file line number Diff line number Diff line change
@@ -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
{};
Loading

0 comments on commit fb55296

Please sign in to comment.