Skip to content

Commit

Permalink
Adding a unit test to provide justification for prior changes
Browse files Browse the repository at this point in the history
  • Loading branch information
codemercenary committed Aug 13, 2014
1 parent 5ec617a commit cf1f58e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/autowiring/test/AutoConstructTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,31 @@ TEST_F(AutoConstructTest, AutoConstructNoArgs) {
TEST_F(AutoConstructTest, AutoConstructWithArgs) {
AutoConstruct<HasDefaultCtorAndOthers> hdcao(495);
ASSERT_EQ(495, hdcao->v) << "Constructor call was not made as expected";
}

class CanOnlyAcceptMovedInput {
public:
CanOnlyAcceptMovedInput(std::unique_ptr<std::shared_ptr<int>>&& ptr) :
m_ptr(std::move(ptr))
{}

std::unique_ptr<std::shared_ptr<int>> m_ptr;
};

TEST_F(AutoConstructTest, CanConstructRvalueCtor) {
auto originalPtr = std::make_shared<int>(555);

// Make a unique pointer to a shared pointer, and pass it in:
{
AutoCreateContext ctxt;
CurrentContextPusher pshr(ctxt);

std::unique_ptr<std::shared_ptr<int>> forwarded(new std::shared_ptr<int>(originalPtr));
AutoConstruct<CanOnlyAcceptMovedInput> coami(std::move(forwarded));

// Should have the correct number of references, no more and no less
ASSERT_EQ(2UL, originalPtr.use_count()) << "Forwarding unique pointer did not correctly";
}

ASSERT_TRUE(originalPtr.unique()) << "Memory leak detected due to incorrect forwarding of a unique pointer";
}

0 comments on commit cf1f58e

Please sign in to comment.