katang katang - 3 months ago 20
C++ Question

gtest unexpected conversion

I am testing the correct operation of my function

bool Core::IsMeta(void)
{
return mProc->GetCode(mPC)->Meta;
}


using instructions


EXPECT_EQ(true,CC->IsMeta()); // The instruction pointed to is meta
EXPECT_EQ(false,CC1->IsMeta()); // The instruction pointed to is NOT meta



the tests run OK, but the two tests behave differently: the 'true' case compiles OK, the 'false' case presents with the warning


In file included from
/... ./build/gtest/src/gtest/include/gtest/gtest.h:1929:0,
from /... .cpp:1:
/... .cpp:
In member function ‘virtual void
... ::TestBody()’:
/... /build/gtest/src/gtest/include/gtest/internal/gtest-internal.h:133:55:
warning: converting ‘false’ to pointer type for argument 1 of ‘char
testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’
[-Wconversion-null]
(sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
^


Why gtest wants to convert 'false' to pointer? And why not 'true'?
Do I miss something?

Answer

For booleans you need to use EXPECT_TRUE() and EXPECT_FALSE() rather than EXPECT_EQ.