In C you have these options for stubbing:
Linker
Function pointer
Preprocessor
In C++ you have all those, plus
Subclassing and overriding virtual functions
To build the stubs, there is Mock support built into CppUTestExt
thanks, James
--------------------------------------------------------------------------------------------
James Grenning Author of TDD for Embedded C
www.renaissancesoftware.net http://pragprog.com/titles/jgade/
www.renaissancesoftware.net/blog
www.twitter.com/jwgrenning
What exactly do you have in mind with objcopy support? I'm not quite clear about it :)
Thanks!
Bas
Thanks for keeping an eye on my question.
I'm a newbie in unit test. And try to seek a objcopy way to do ut. We have
some legacy code, as well as the fresh code. The function pointer way is a
good one(easy to use and comprehensive), but we have to add some extra code
inside the legacy souce file. Which violate our rule no to touch the current
code...
Objcopy can fulfill our requirement, it's not quite convenient to use
through.
As we have decided to use CppUTest as our ut framework, I was wondering, if
it also support objcopy, we can use objcopy very easily..
That's where the question originating from.
I'm still learning the cppumock, hope it can help us. there's not so much
example on your website about this, seems a little difficult for me.
Best wishes,
Pan.
-----邮件原件-----
发件人: cppu...@googlegroups.com [mailto:cppu...@googlegroups.com] 代表
Bas Vodde
发送时间: 2012年2月10日 12:48
收件人: cppu...@googlegroups.com
主题: Re: about stub support
> Thanks for keeping an eye on my question.
> I'm a newbie in unit test. And try to seek a objcopy way to do ut.
Could you explain more how you would want to use objcopy?
I've not had much interest in providing such mocking methods as they feel like hacking and they aren't very cross-platform :(
> We have some legacy code, as well as the fresh code. The function pointer way is a
> good one(easy to use and comprehensive), but we have to add some extra code
> inside the legacy souce file. Which violate our rule no to touch the current
> code...
Yah, the "function to function-pointer" refactoring is a fairly safe one though. In my own work with legacy, I usually use that, but then for larger "modules" use linker stubbing. In all products I've worked, this worked well as the linker stubbing allowed us to not make any changes to code, but because we only use it on larger components, therefore it doesn't lead to too much binaries.
> Objcopy can fulfill our requirement, it's not quite convenient to use
> through.
Please tell me more how you want to use it :)
> As we have decided to use CppUTest as our ut framework, I was wondering, if
> it also support objcopy, we can use objcopy very easily..
> That's where the question originating from.
Ok. Well at the moment, there is no direct objcopy support.
> I'm still learning the cppumock, hope it can help us. there's not so much
> example on your website about this, seems a little difficult for me.
Oh, I'm sorry to hear that. I'll try to find time to make more and better examples in the future.
For the CppUMock, it is probably best to read the TestMockSupport.cpp file which contains all the tests for the mocking.
Thanks!
Bas