Comments (8)
Ok, It works! You can mock the dtor now!
The following code will work:
Mock<SomeInterface> mock;
Fake(Dtor(mock)); // Stub the dtor to do nothing!!
SomeInterface * i = &mock.get();
std::unique_ptr<SomeInterface> ptr(i);
You can do much more than that:
void mock_virtual_dtor_with_when() {
int a = 0;
Mock<SomeInterface> mock;
When(Dtor(mock)).Do([&](){a++; });
SomeInterface * i = &(mock.get());
delete i; // a++
delete i; // a++
ASSERT_EQUAL(2, a);
}
Enjoy!
from fakeit.
Hi,
I made some changes trying to make Fakeit support your request, though i had to revert them all back since for some reason it does not work on gcc.
Things get tricky since the instance held by the mock is not a real instance (since the mocked class is abstract). It is a faked instance managed by the mock object. Letting the test/user delete the instance fails because the FakeObject's virtual table does not have a destructor.
I will make another effort in the next few days to make it work (by putting a fake destructor in the correct position of the virtual table) I hope I will be able to make it work.
from fakeit.
Thanks for your effort! I will certainly try this out next week.
from fakeit.
Hi, it works fine now. I have just a small remark:
At this line GCC 4.8 gives the warning ISO C++ forbids casting between pointer-to-function and pointer-to-object
. Is there something we could do to avoid that warning?
from fakeit.
Sure, I'll fix it this weekend.
On Feb 5, 2015 9:37 AM, "Stijn Van Nieuwenhuyse" [email protected]
wrote:
Hi, it works fine now. I have just a small remark:
At this
https://github.com/eranpeer/FakeIt/blob/master/include/mockutils/gcc/VirtualTable.hpp#L80
line GCC 4.8 gives the warning ISO C++ forbids casting between
pointer-to-function and pointer-to-object. Is there something we could do
to avoid that warning?—
Reply to this email directly or view it on GitHub
#10 (comment).
from fakeit.
Done! I fixed the gcc warning.
from fakeit.
I have a similar crash here with Qt's QSharedPointer. Used current master branch!
#0 0x685d62 in fakeit::MethodProxyCreator<void>::methodProxy(unsigned int) [..]/external/fakeit.hpp:5815:20
#1 0x685459 in void fakeit::MethodProxyCreator<void>::methodProxyX<0>() [..]/external/fakeit.hpp:5820:20
#2 0x689a89 in fakeit::VirtualTable<ActivationContext>::dtor(int) [..]/external/fakeit.hpp:5615:13
#3 0x7fc23f73049f in QScopedPointerDeleter<ActivationContext>::cleanup(ActivationContext*) [..]/QtCore/qscopedpointer.h:54:9
#4 0x7fc23f730028 in QScopedPointer<ActivationContext, QScopedPointerDeleter<ActivationContext> >::~QScopedPointer() [..]/QtCore/qscopedpointer.h:101:9
The code:
Mock<ActivationContext> context;
When(Dtor(context));
QSharedPointer<AuthModel> model(new AuthModel(&context.get()));
from fakeit.
What happens when both the mock and the unique_ptr (that points to the mocked instance) are deleted?
{
Mock<SomeType> mock;
Fake(Dtor(mock));
std::unique_ptr<SomeType> ptr {&mock.get()};
} // <- both are deleted
I'm having some issues and I suspect it has to do with this..
from fakeit.
Related Issues (20)
- Overloaded function in derived class hides base class function HOT 5
- compiled error with c++17 in VS2019 HOT 4
- SIGSEGV when when mock with shared_ptr HOT 16
- complied error when mock with unique_ptr HOT 3
- exception with unique_ptr HOT 13
- Can't mock override with ref-qualifiers? HOT 5
- Colliding MockingContext ids when used in multiple translation units because of __COUNTER__ HOT 7
- Can't stub method with vector of unique_ptr parameter HOT 5
- Clang 14.0.6 compile error HOT 7
- Undefined sanitizer issue HOT 4
- Seems latest version 2.3.1 is not available on conan yet HOT 3
- fakeit from conan center doesn't get header with integration (e.g. header with gtest integration) HOT 5
- Quickstart spy example does not work as expected HOT 2
- Cannot verify 0 times invocations using RepeatedSequence HOT 4
- There are deprecated warnings on OSX with C++20 and C++23 HOT 3
- FakeIt and CppUTest HOT 3
- Verify Using QString gives bad_alloc HOT 2
- Missing .CoReturn method HOT 1
- Not working with local classes? HOT 1
- Stubbing method returning the vector of unique_ptr's generates the compile error. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fakeit.