Search code examples
googletestgooglemock

Is it possible to not output the raw object when dealing with GMock EXPECT_CALL?


I've got the following matcher

class HorizonFileFormatInlineCrosslineMatcher : public MatcherInterface < const HorizonFileFormat& >
{
public:
    HorizonFileFormatInlineCrosslineMatcher(int inline_col, int crossline_col) : inline_col_(inline_col), crossline_col_(crossline_col) 
    {}

    virtual bool MatchAndExplain(const HorizonFileFormat& hff, MatchResultListener* listener) const
    {
        *listener << "inline and crossline are (" << hff.inlineColumnIndex() << ", " << hff.xlineColumnIndex() << ")";

        return 
            hff.inlineColumnIndex() == inline_col_ && 
            hff.xlineColumnIndex() == crossline_col_;
    }

    virtual void DescribeTo(::std::ostream* os) const
    {
        *os << "inline and crossline match expected (" << inline_col_ << ", " << crossline_col_ << ")";
    }

    virtual void DescribeNegationTo(::std::ostream* os) const
    {
        *os << "inline and crossline do not match expected (" << inline_col_ << ", " << crossline_col_ << ")";
    }
private:
    int inline_col_;
    int crossline_col_;
};

inline Matcher<const HorizonFileFormat&> MatchInlineCrossline(int inline_col, int crossline_col)
{
    return testing::MakeMatcher(new HorizonFileFormatInlineCrosslineMatcher(inline_col, crossline_col));
}

When it fails, it successfully outputs

    [ RUN      ]
    DecisionSpaceHorizonImporterTests.when_the_survey_is_crossline_a_crossline_format_importer_is_used
    unknown file: error:
    Unexpected mock function call - taking default action specified at:
    decision_space_horizon_importer_tests.cpp(87):
        Function call: createPointSoupHorizonImporter(@000000000023EC40 88-byte object <20-A3 92-00 00-00 00-00 B0-16 1B-10 00-00 00-00 20-D3 18-10 00-00 00-00 CC-CC CC-CC CC-CC CC-CC 21-00 00-00 00-00 00-00 2F-00 00-00 00-00 00-00 CC-CC CC-CC CC-CC CC-CC 00-00 00-00 03-00 00-00 00-00 00-00 01-00 00-00 FF-FF FF-FF FF-FF FF-FF 02-00 00-00 01-00 00-00>, @000000000023EBD8 {})
              Returns: 000000000E850660
    Google Mock tried the following 1 expectation, but it didn't match:

    decision_space_horizon_importer_tests.cpp(137): EXPECT_CALL(*importer_factory, createPointSoupHorizonImporter(MatchInlineCrossline(1, 0), A<const HorizonImport::Attributes&>()))...
      Expected arg #0: inline and crossline match expected (1, 0)
               Actual: 88-byte object <20-A3 92-00 00-00 00-00 B0-16 1B-10 00-00 00-00 20-D3 18-10 00-00 00-00 CC-CC CC-CC CC-CC CC-CC 21-00 00-00 00-00 00-00 2F-00 00-00 00-00 00-00 CC-CC CC-CC CC-CC CC-CC 00-00 00-00 03-00 00-00 00-00 00-00 01-00 00-00 FF-FF FF-FF FF-FF FF-FF 02-00 00-00 01-00 00-00>, inline and crossline are (0, 1)
             Expected: to be called once
               Actual: never called - unsatisfied and active
    decision_space_horizon_importer_tests.cpp(137): error: Actual function call count doesn't match EXPECT_CALL(*importer_factory, createPointSoupHorizonImporter(MatchInlineCrossline(1, 0), A<const HorizonImport::Attributes&>()))...
             Expected: to be called once
             Actual: never called - unsatisfied and active
    [  FAILED  ]
    DecisionSpaceHorizonImporterTests.when_the_survey_is_crossline_a_crossline_format_importer_is_used (6 ms)

Note the hex pairs that, while technically describing the objects passed in, aren't exactly useful and distract the eye from the actual useful data of "inline and crossline are (0, 1)" vs "inline and crossline match expected (1, 0)"

What can I do to exclude these objects from the output?


Solution

  • You need to define a printer function for your class. Make sure you define it in the same namespace where your class is defined.