处理GMock时是否可以不输出原始对象EXPECT_CALL?

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

我有以下匹配器

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

失败时,成功输出

    [ 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)

请注意十六进制对,虽然在技术上描述了传入的对象,但并不完全有用,并且会分散人们对 "inline and crossline are (0, 1)" 与 "inline and crossline match expected (1, 0)"

实际有用数据的注意力

如何从输出中排除这些对象?

您需要为 class 定义一个 printer function。确保在定义 class 的同一个命名空间中定义它。