ASSERT_EQ and ASSERT_NE rationale

6,519 views
Skip to first unread message

Gregory Pakosz

unread,
Dec 16, 2009, 4:06:53 AM12/16/09
to Google C++ Testing Framework
Hello,

What's the rational behind having ASSERT_EQ allowing tests like
ASSERT_EQ(NULL, somePointer); though disallowing ASSERT_NE(NULL,
somePointer); ?

From what I see, the implementation of ASSERT_EQ relies
on ::testing::internal::EqHelper<GTEST_IS_NULL_LITERAL_(expected)
>::Compare but ASSERT_NE uses ::testing::internal::CmpHelperNE.

With MSVC2005, ASSERT_NE(NULL, somePointer); fails to compile when
trying to instantiate CmpHelperNE<int, void*> with a C2040 error:
http://msdn.microsoft.com/en-us/library/kb3dky0e.aspx

Thank you,
Gregory

Tor Didriksen

unread,
Dec 16, 2009, 4:53:11 AM12/16/09
to Gregory Pakosz, Google C++ Testing Framework

Gregory Pakosz

unread,
Dec 16, 2009, 5:01:19 AM12/16/09
to Google C++ Testing Framework
>
> please see
>
> http://code.google.com/p/googletest/wiki/GoogleTestFAQ#Why_does_Googl...
>
> -- didrik

Hello didrik,

Thank you for that quick answer.

To my defense, I did opened the FAQ but searched for "ASSERT_NE" in
the page which gave not found (yeah it was only the 4th item in the
toc though).

May I suggest to change the title of the item to:

"Why does Google Test support EXPECT_EQ(NULL, ptr) and ASSERT_EQ(NULL,
ptr) but not EXPECT_NE(NULL, ptr) and ASSERT_NE(NULL, ptr)?"

Regards,
Gregory

Zhanyong Wan (λx.x x)

unread,
Dec 16, 2009, 12:15:43 PM12/16/09
to Gregory Pakosz, Google C++ Testing Framework
Thanks for the suggestion. Done.
--
Zhanyong
Reply all
Reply to author
Forward
0 new messages