Hi there,
I use mockpp 1.16.6 together with CppUnit.
I would like to mock a pretty large class MyProxy. MyProxy contains a method that looks like this:
void Initialize(IMyInterface& myinterface);
I generated the mock for MyProxy using the autogeneration tools with mockpp2xml and xml2mockpp, but when I try to build the code, I get this error:
..\mockpp-1.16.6\mockpp/constraint/ConstraintList.h(274) : error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'mockpp::String' (or there is no acceptable conversion) while trying to match the argument list '(mockpp::String, const IMyInterface)'.
As I do not want to mock IMyInterface using Mockpp (I only need IMyInterface for this one function argument in the Initialize method) I just created a simple class with the same name IMyInterface and used this dummy class as argument type for the Initialize method.
I know from the Mockpp documentation, that I need to overload the << operator for IMyInterface, but I don't know where to do that. I already tried to add the overload to the dummy class of IMyInterface and I also tried to add the macro MOCKPP_ENABLE_DEFAULT_FORMATTER to the Mockpp mock of MyProxy before the include of mockpp.h. In the first case the namespace MOCKPP_NS was not found (of course, as I did not use Mockpp to create the dummy class) and in the second case the error is this:
mockpp-1.16.6\mockpp/mockpp.h(443) : error C2143: syntax error : missing ';' before 'namespace'
If you need more information, please let me know.
Thanks a lot for your help!
Hello Alexandra,
I am sure you found the solution yourself already. mockpp needs a little help from you, to output meaningful debugging information. The mechanism is similar to std::ostream and extends in the same user-defined way.
At work I have a collection of such helpers in a h/cpp-file. All you need to do is implement something for your IMyInterface. The example below just outputs the adress in hex as this class is mostly virtual and my outputter here is simply a catch-all-derived. You probably want something more elaborate :-)
But take care to keep namespaces clean and explicit if you use your own namespace like in the example.
Hope this helps :-)
-- h-file
ifndef MOCKPP_SUPP_KERNEL_H
define MOCKPP_SUPP_KERNEL_H
define MOCKPP_ENABLE_DEFAULT_FORMATTER
include <mockpp compat="" formatter.h=""></mockpp>
namespace myns {
mockpp::String & operator << (mockpp::String &formatter, UInterface *);
}
endif
-- cpp-file
namespace myns {
mockpp::String& operator << (mockpp::String &formatter, UInterface intf)
{
return mockpp::replaceFormatterString(formatter, UString::number((void)(intf)));
}
}
--
Ewald Arnold
mailto:ewald (http://sonne.home/horde5/imp/dynamic.php?page=mailbox) at ewald-arnold dot de
Related
Support Requests: #10
Thank you so much! It is working now.
Great😀 and as I said, you found it yourself, just that tiny last bit was missing.
Am 17. Juni 2022 11:46:24 MESZ schrieb alex100 alex100@users.sourceforge.net:
Related
Support Requests: #10