Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Deferred(DispatchQueue*) #817

Merged
merged 4 commits into from
Nov 3, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions autowiring/Deferred.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#pragma once

class CoreThread;
class DispatchQueue;

/// <summary>
/// Marker return type for deferred calls
Expand All @@ -12,5 +12,5 @@ class CoreThread;
/// </remarks>
class Deferred {
public:
Deferred(CoreThread* pThread) {}
Deferred(DispatchQueue* pQueue) {}
};
30 changes: 30 additions & 0 deletions src/autowiring/test/AutoFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,36 @@ TEST_F(AutoFilterTest, DeferredDecorateOnly) {
ASSERT_EQ(105, dec->i) << "Deferred decorate-only AutoFilter did not properly attach before context termination";
}

class DQueueSharedPointer:
public DispatchQueue
{
public:
size_t callCount = 0;

Deferred AutoFilter(std::shared_ptr<const int>) {
callCount++;
return Deferred(this);
}
};

TEST_F(AutoFilterTest, DQueueAutoFilterTest) {
AutoRequired<AutoPacketFactory> factory;
auto ptr = std::make_shared<int>(1012);

AutoRequired<DQueueSharedPointer> dQueueSharedPtr;

// Generate a bunch of packets, all with the same shared pointer decoration:
for(size_t i = 0; i < 100; i++) {
// Decorate the packet, forget about it:
auto packet = factory->NewPacket();
packet->Decorate(ptr);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to add ASSERT_EQ(0UL, dQueueSharedPtr->callCount) at this point, so we can be assured that the filter is not called prematurely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the last thing, then I'll merge.

dQueueSharedPtr->DispatchAllEvents();

// Ensure nothing got cached unexpectedly, and that the call count is precisely what we want
ASSERT_EQ(100UL, dQueueSharedPtr->callCount) << "The expected number of calls to AutoFilter were not made";
}

class MyInheritingAutoFilter:
public FilterGen<std::vector<int>>
{};
Expand Down