Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gtest unexpected conversion

Tags:

c++

googletest

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?

like image 868
katang Avatar asked Dec 09 '15 04:12

katang


People also ask

How do I turn off test Gtest?

If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0 , as disabled tests are still compiled (and thus won't rot).

What is Mock_method?

You must always put a mock method definition ( MOCK_METHOD ) in a public: section of the mock class, regardless of the method being mocked being public , protected , or private in the base class.

What is a Gtest?

Google Test (also known as gtest) is a unit testing library for the C++ programming language, based on the xUnit architecture. The library is released under the BSD 3-clause license.

What is Expect_call Gtest?

EXPECT_CALL not only defines the behavior, but also sets an expectation that the method will be called with the given arguments, for the given number of times (and in the given order when you specify the order too).


1 Answers

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

like image 52
Claudio Avatar answered Sep 27 '22 18:09

Claudio