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

时间:2015-03-19 16:23:53

标签: googletest gmock

我有以下匹配器

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)

请注意,在技术上描述传入的对象时,十六进制对并不是非常有用,并且会分散注意力,因为&#34;内联和交叉线的实际有用数据是(0,1)和#34 ; vs&#34;内联和交叉线匹配预期(1,0)&#34;

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

1 个答案:

答案 0 :(得分:2)

您需要为您的班级定义printer function。确保在定义类的同一名称空间中定义它。