Menu

#10 Overload operator<< for interface class

v1.0 (example)
open
nobody
None
5
2022-06-17
2022-06-14
alex100
No

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!

Related

Support Requests: #10

Discussion

  • Ewald Arnold

    Ewald Arnold - 2022-06-15

    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)));
    }

    }

    Alexandra Gehring alex100@users.sourceforge.net hat am 14.06.2022 14:01 CEST geschrieben:


    [support-requests:#10] (https://sourceforge.net/p/mockpp/support-requests/10/) Overload operator<< for interface class
    Status: open
    Group: v1.0 (example)
    Created: Tue Jun 14, 2022 12:01 PM UTC by Alexandra Gehring
    Last Updated: Tue Jun 14, 2022 12:01 PM UTC
    Owner: nobody
    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!


    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/mockpp/support-requests/10/
    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

    --
    Ewald Arnold
    mailto:ewald (http://sonne.home/horde5/imp/dynamic.php?page=mailbox) at ewald-arnold dot de

     

    Related

    Support Requests: #10

  • alex100

    alex100 - 2022-06-17

    Thank you so much! It is working now.

     
    • Ewald Arnold

      Ewald Arnold - 2022-06-17

      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:

      Thank you so much! It is working now.


      [support-requests:#10] Overload operator<< for interface class

      Status: open
      Group: v1.0 (example)
      Created: Tue Jun 14, 2022 12:01 PM UTC by alex100
      Last Updated: Tue Jun 14, 2022 12:01 PM UTC
      Owner: nobody

      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!


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/mockpp/support-requests/10/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Support Requests: #10


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.