forked from dascandy/hippomocks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue/Feature Description] Mocking of unique_ptr is currently not supported in HippoMocks. [Resolution] Cherry-pick changes from dascandy#82 which add support for unique_ptr.
- Loading branch information
Showing
3 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include <string> | ||
|
||
#include "gtest/gtest.h" | ||
#include "hippomocks.h" | ||
|
||
class IU { | ||
public: | ||
virtual ~IU() {} | ||
virtual void f() = 0; | ||
virtual void g() {} | ||
virtual int h() { return 0; } | ||
virtual void i(std::string) {} | ||
virtual void j(std::string) = 0; | ||
}; | ||
|
||
TEST(TestUniquePtr, checkUniquePtrDestruction) { | ||
MockRepository mocks; | ||
auto iu = mocks.UniqueMock<IU>(); | ||
} | ||
|
||
TEST(TestUniquePtr, checkCallsWorksOnUniquePtr) { | ||
MockRepository mocks; | ||
std::unique_ptr<IU> iu = mocks.UniqueMock<IU>(); | ||
mocks.ExpectCall(iu.get(), IU::f); | ||
iu->f(); | ||
} | ||
|
||
TEST(TestUniquePtr, checkMissingExpectationsWorksOnUniquePtr) { | ||
MockRepository mocks; | ||
bool exceptionCaught = false; | ||
std::unique_ptr<IU> iu = mocks.UniqueMock<IU>(); | ||
try { | ||
iu->f(); | ||
} catch (HippoMocks::NotImplementedException const &) { | ||
exceptionCaught = true; | ||
} | ||
EXPECT_TRUE(exceptionCaught); | ||
} | ||
|
||
TEST(TestUniquePtr, checkNeverCallWorksOnUniquePtr) { | ||
bool exceptionCaught = false; | ||
MockRepository mocks; | ||
auto iu = mocks.UniqueMock<IU>(); | ||
Call &callF = mocks.ExpectCall(iu.get(), IU::f); | ||
mocks.OnCall(iu.get(), IU::g); | ||
mocks.NeverCall(iu.get(), IU::g).After(callF); | ||
iu->g(); | ||
iu->g(); | ||
iu->f(); | ||
try { | ||
iu->g(); | ||
} catch (HippoMocks::ExpectationException &) { | ||
exceptionCaught = true; | ||
} | ||
EXPECT_TRUE(exceptionCaught); | ||
} | ||
|
||
TEST(TestUniquePtr, checkClassArgumentsAcceptedWithUniquePtr) { | ||
MockRepository mocks; | ||
auto iamock = mocks.UniqueMock<IU>(); | ||
mocks.OnCall(iamock.get(), IU::i).With("hi"); | ||
mocks.OnCall(iamock.get(), IU::j).With("bye"); | ||
iamock->i("hi"); | ||
iamock->j("bye"); | ||
} | ||
|
||
TEST(TestUniquePtr, checkClassArgumentsCheckedWithUniquePtr) { | ||
MockRepository mocks; | ||
auto iamock = mocks.UniqueMock<IU>(); | ||
mocks.OnCall(iamock.get(), IU::i).With("hi"); | ||
mocks.OnCall(iamock.get(), IU::j).With("bye"); | ||
bool exceptionCaught = false; | ||
try { | ||
iamock->i("bye"); | ||
} catch (HippoMocks::ExpectationException) { | ||
exceptionCaught = true; | ||
} | ||
EXPECT_TRUE(exceptionCaught); | ||
mocks.reset(); | ||
} | ||
|
||
TEST(TestUniquePtr, checkClassArgumentsIgnoredWithUniquePtr) { | ||
MockRepository mocks; | ||
auto iamock = mocks.UniqueMock<IU>(); | ||
mocks.OnCall(iamock.get(), IU::i); | ||
iamock->i("bye"); | ||
} |