googletest打印COleDateTime值
我已将 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>
注意 实际 值!
I have integrated googletest into our MFC application. However while writing tests involving COleDateTime objects I came across the following warning:
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 *)'
The test was the following:
TEST(FunctionTest, SumDays)
{
COleDateTime res = SumDays(COleDateTime(2010,10,31,0,0,0), 1);
EXPECT_EQ(COleDateTime(2010,11,01,0,0,0), res);
}
The problem is I cannot add a << operator or a PrintTo method as the documentation announces.
Allot more tests are going to involve date values so I want to avoid the inline solution the documentation refers to.
Is there a good solution to control the print string for COleDateTime values?
The current output comes out like:
<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>
Notice the Actual value!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题并发现,与 Caerbanogs 声明相反 - 实施PrintTo 函数确实有帮助。一件重要的事情是确保该类“扩展”googletest 的行为与
PrintTo
-Function 具有完全相同的命名空间。在本例中,这就是命名空间
ATL
!这导致了以下针对
COleDateTime
和COleDateTimeSpan
的解决方案:只需将其放入一个位置,您可以将其包含在所有 googletest-Projects 中(如果您有多个项目) 。
最后它对我有用:-)
I had the same porblem and figured out, that - in contrast to Caerbanogs statement - implementing the
PrintTo
-Function(s) helps indeed. One important thing is to make sure that the Class for that one "extends" a behaviour for googletest has exactly the same namespace as thePrintTo
-Function.In this case that is the namespace
ATL
!This leads to the following solution for
COleDateTime
andCOleDateTimeSpan
:Just put that into a place, which you can include from all your googletest-Projects (if you have more than one).
At last it works for me :-)