我已经将googletest集成到我们的MFC应用程序中。然而,在编写涉及COleDateTime对象的测试时,我遇到了以下警告:
1>gtest/gtest-printers.h(169) : warning C4244: 'initializing' : conversion from 'DATE' to 'const testing::internal::BiggestInt', possible loss of data
1>gtest/gtest-printers.h(168) : while compiling class template member function 'void testing::internal2::TypeWithoutFormatter<T,kTypeKind>::PrintValue(const T &,std::ostream *)'试验结果如下:
TEST(FunctionTest, SumDays)
{
COleDateTime res = SumDays(COleDateTime(2010,10,31,0,0,0), 1);
EXPECT_EQ(COleDateTime(2010,11,01,0,0,0), res);
}问题是,我不能添加<<运算符或PrintTo方法,正如文档所宣布的那样。分配更多的测试将涉及日期值,因此我希望避免文档所指的内联解决方案。
有一个很好的解决方案来控制COleDateTime值的打印字符串吗?
当前输出的结果如下:
<failure message="Value of: res
 Actual: 40512
Expected: COleDateTime(2010,10,30,0,0,0)
Which is: 40481" type=""><![CDATA[.\Code.cpp:6837
Value of: res
Actual: 40512
Expected: COleDateTime(2010,10,30,0,0,0)
Which is: 40481]]></failure>注意实际的值!
发布于 2014-06-02 12:58:22
我有同样的问题,并指出,与Caerbanogs语句不同的是,实现PrintTo-Function确实有帮助。重要的一件事是确保该类的类“扩展”了googletest的行为,使与PrintTo-Function完全相同。
在本例中,这是名称空间ATL!
这将为COleDateTime和COleDateTimeSpan提供以下解决方案
namespace ATL {
void PrintTo(const COleDateTime& dtDatum, ::std::ostream* os)
{
// I want an additional Format, so I append a human readable notion
*os << dtDatum.m_dt << " (" << (LPCSTR)dtDatum.Format(_T("%d.%m.%Y %H:%M:%S")) << ")";
}
void PrintTo(const COleDateTimeSpan& dsSpanne, ::std::ostream* os)
{
*os << dsSpanne.m_span;
}
}只要把它放到一个地方,你就可以把它包含在你所有的谷歌项目中(如果你有一个以上的话)。
最后,它对我有用:-)
https://stackoverflow.com/questions/6623063
复制相似问题