Skip to content

Commit

Permalink
Adding unit test demonstrating failure of PostConstruction NotifyWhen…
Browse files Browse the repository at this point in the history
…Autowired for Context.
  • Loading branch information
Gabriel Hare committed Aug 22, 2014
1 parent 7e0bd3c commit 97f0e62
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/autowiring/test/PostConstructTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,9 @@ TEST_F(PostConstructTest, ContextNotifyWhenAutowired) {

// Now we'd like to be notified when SimpleObject gets added:
ctxt->NotifyWhenAutowired<SimpleObject>(
[called] {
[called] {
*called = true;
}
);
});

// Should only be two uses, at this point, of the capture of the above lambda:
EXPECT_EQ(2L, called.use_count()) << "Unexpected number of references held in a capture lambda";
Expand All @@ -283,3 +282,23 @@ TEST_F(PostConstructTest, ContextNotifyWhenAutowired) {
ASSERT_TRUE(called.unique()) << "Autowiring notification lambda was not properly cleaned up";
}

TEST_F(PostConstructTest, ContextNotifyWhenAutowiredPostConstruct) {
auto called = std::make_shared<bool>(false);
AutoCurrentContext ctxt;

// Create an object that will satisfy subsequent notification call:
AutoRequired<SimpleObject> sobj;

// Notification should be immediate:
ctxt->NotifyWhenAutowired<SimpleObject>(
[called] {
*called = true;
});

// Insert the SimpleObject, see if the lambda got hit:
ASSERT_TRUE(*called) << "Context-wide autowiring notification was not hit as expected when a matching type was injected into a context";

// Our shared pointer should be unique by this point, because the lambda should have been destroyed
ASSERT_TRUE(called.unique()) << "Autowiring notification lambda was not properly cleaned up";
}

0 comments on commit 97f0e62

Please sign in to comment.