From ed1c9d53f80e2c58b1a524d4e586044424cf7e7e Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Wed, 29 Apr 2015 17:43:13 +0200 Subject: [PATCH] tests: fix test errors found with current gmock/gtest Some tests fail to build using up to date gmock and gtest (newer than in Tizen). Fixes are simple: - properly cast numeric constants when they are compared against unsigned types - use EXPECT_TRUE/EXPECT_FALSE instead of EXPECT_EQ with bool literal. EXPECT_EQ(false, ...) is known to fail (e.g. https://code.google.com/p/chromium/issues/detail?id=139326) Change-Id: I75d0cd4adb2d68af67d06a0630980ad5cb2cbdfc Signed-off-by: Rafal Krypa --- test/common/exceptions/bucketrecordcorrupted.cpp | 10 ++++---- test/common/protocols/RequestTestHelper.h | 4 ++-- test/common/protocols/ResponseTestHelper.h | 4 ++-- test/credsCommons/parser/Parser.cpp | 28 +++++++++++----------- test/service/main/cmdlineparser.cpp | 10 ++++---- test/storage/inmemorystoragebackend/buckets.cpp | 2 +- .../inmemorystoragebackendfixture.h | 4 ++-- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/test/common/exceptions/bucketrecordcorrupted.cpp b/test/common/exceptions/bucketrecordcorrupted.cpp index 3d00faa..8bc69a7 100644 --- a/test/common/exceptions/bucketrecordcorrupted.cpp +++ b/test/common/exceptions/bucketrecordcorrupted.cpp @@ -37,7 +37,7 @@ TEST(BucketRecordCorruptedException, line) { ASSERT_THAT(ex.what(), StartsWith(expected)); ASSERT_EQ("line", ex.line()); ASSERT_EQ("", ex.filename()); - ASSERT_EQ(0, ex.lineNumber()); + ASSERT_EQ(static_cast(0), ex.lineNumber()); } TEST(BucketRecordCorruptedException, line_lineno) { @@ -49,7 +49,7 @@ TEST(BucketRecordCorruptedException, line_lineno) { ASSERT_THAT(ex.what(), StartsWith(expected)); ASSERT_EQ("line", ex.line()); ASSERT_EQ("", ex.filename()); - ASSERT_EQ(10, ex.lineNumber()); + ASSERT_EQ(static_cast(10), ex.lineNumber()); } TEST(BucketRecordCorruptedException, line_lineno_filename) { @@ -61,7 +61,7 @@ TEST(BucketRecordCorruptedException, line_lineno_filename) { ASSERT_THAT(ex.what(), StartsWith(expected)); ASSERT_EQ("line", ex.line()); ASSERT_EQ("bucket.bkt", ex.filename()); - ASSERT_EQ(10, ex.lineNumber()); + ASSERT_EQ(static_cast(10), ex.lineNumber()); } TEST(BucketRecordCorruptedException, line_filename) { @@ -73,7 +73,7 @@ TEST(BucketRecordCorruptedException, line_filename) { ASSERT_THAT(ex.what(), StartsWith(expected)); ASSERT_EQ("line", ex.line()); ASSERT_EQ("bucket.bkt", ex.filename()); - ASSERT_EQ(0, ex.lineNumber()); + ASSERT_EQ(static_cast(0), ex.lineNumber()); } TEST(BucketRecordCorruptedException, line_sliced) { @@ -88,5 +88,5 @@ TEST(BucketRecordCorruptedException, line_sliced) { ASSERT_THAT(ex.what(), StartsWith(expected)); ASSERT_EQ(line, ex.line()); ASSERT_EQ("", ex.filename()); - ASSERT_EQ(0, ex.lineNumber()); + ASSERT_EQ(static_cast(0), ex.lineNumber()); } diff --git a/test/common/protocols/RequestTestHelper.h b/test/common/protocols/RequestTestHelper.h index 894ddd0..f64eb54 100644 --- a/test/common/protocols/RequestTestHelper.h +++ b/test/common/protocols/RequestTestHelper.h @@ -48,7 +48,7 @@ void testRequest(std::shared_ptr request, Cynara::ProtocolPtr protocol) { auto extractedRequest = protocol->extractRequestFromBuffer(queue); ASSERT_TRUE(bool(extractedRequest)); - ASSERT_EQ(queue->size(), 0); + ASSERT_EQ(queue->size(), static_cast(0)); compare(*request, dynamic_cast(*extractedRequest)); } @@ -63,7 +63,7 @@ void binaryTestRequest(Cynara::RequestPtr request, Cynara::ProtocolPtr protocol) auto extractedRequest = protocol->extractRequestFromBuffer(queue); ASSERT_TRUE(bool(extractedRequest)); - ASSERT_EQ(queue->size(), 0); + ASSERT_EQ(queue->size(), static_cast(0)); extractedRequest->execute(*protocol, context); Cynara::RawBuffer data2(queue->size()); diff --git a/test/common/protocols/ResponseTestHelper.h b/test/common/protocols/ResponseTestHelper.h index 66d1a5b..85cbc29 100644 --- a/test/common/protocols/ResponseTestHelper.h +++ b/test/common/protocols/ResponseTestHelper.h @@ -48,7 +48,7 @@ void testResponse(std::shared_ptr response, Cynara::ProtocolPtr protocol) { auto extractedResponse = protocol->extractResponseFromBuffer(queue); ASSERT_TRUE(bool(extractedResponse)); - ASSERT_EQ(queue->size(), 0); + ASSERT_EQ(queue->size(), static_cast(0)); compare(*response, dynamic_cast(*extractedResponse)); } @@ -63,7 +63,7 @@ void binaryTestResponse(Cynara::ResponsePtr response, Cynara::ProtocolPtr protoc auto extractedResponse = protocol->extractResponseFromBuffer(queue); ASSERT_TRUE(bool(extractedResponse)); - ASSERT_EQ(queue->size(), 0); + ASSERT_EQ(queue->size(), static_cast(0)); extractedResponse->execute(*protocol, context); Cynara::RawBuffer data2(queue->size()); diff --git a/test/credsCommons/parser/Parser.cpp b/test/credsCommons/parser/Parser.cpp index 9a92205..f2a86c3 100644 --- a/test/credsCommons/parser/Parser.cpp +++ b/test/credsCommons/parser/Parser.cpp @@ -139,8 +139,8 @@ TEST(parser, interpretValue_OK) { {"pid", CLIENT_METHOD_PID}}; int method = NOT_A_METHOD_CODE; bool occurred = false; - EXPECT_EQ(true, credsBackend.interpretValue(clientCredsMap, method, "smack", occurred)); - EXPECT_EQ(true, occurred); + EXPECT_TRUE(credsBackend.interpretValue(clientCredsMap, method, "smack", occurred)); + EXPECT_TRUE(occurred); EXPECT_EQ(CLIENT_METHOD_SMACK, method); } @@ -149,9 +149,9 @@ TEST(parser, interpretValueKeyNotInMap1) { {"pid", CLIENT_METHOD_PID}}; int method = NOT_A_METHOD_CODE; bool occurred = false; - EXPECT_EQ(false, + EXPECT_FALSE( credsBackend.interpretValue(clientCredsMap, method, "NeitherSmackNorPid", occurred)); - EXPECT_EQ(true, occurred); + EXPECT_TRUE(occurred); EXPECT_EQ(NOT_A_METHOD_CODE, method); } @@ -160,9 +160,9 @@ TEST(parser, interpretValueKeyNotInMap2) { {"pid", CLIENT_METHOD_PID}}; int method = NOT_A_METHOD_CODE; bool occurred = true; - EXPECT_EQ(false, + EXPECT_FALSE( credsBackend.interpretValue(clientCredsMap, method, "NeitherSmackNorPid", occurred)); - EXPECT_EQ(true, occurred); + EXPECT_TRUE(occurred); EXPECT_EQ(NOT_A_METHOD_CODE, method); } @@ -171,9 +171,9 @@ TEST(parser, interpretValueKeyAppearsAgain) { {"pid", CLIENT_METHOD_PID}}; int method = NOT_A_METHOD_CODE; bool occurred = true; - EXPECT_EQ(false, + EXPECT_FALSE( credsBackend.interpretValue(clientCredsMap, method, "smack", occurred)); - EXPECT_EQ(true, occurred); + EXPECT_TRUE(occurred); EXPECT_EQ(NOT_A_METHOD_CODE, method); } @@ -182,9 +182,9 @@ TEST(parser, interpretValueKeyEmptyKey) { {"pid", CLIENT_METHOD_PID}}; int method = NOT_A_METHOD_CODE; bool occurred = true; - EXPECT_EQ(false, + EXPECT_FALSE( credsBackend.interpretValue(clientCredsMap, method, "", occurred)); - EXPECT_EQ(true, occurred); + EXPECT_TRUE(occurred); EXPECT_EQ(NOT_A_METHOD_CODE, method); } @@ -192,9 +192,9 @@ TEST(parser, interpretValueEmptyMap1) { static const CredentialsMap clientCredsMap{}; int method = NOT_A_METHOD_CODE; bool occurred = false; - EXPECT_EQ(false, + EXPECT_FALSE( credsBackend.interpretValue(clientCredsMap, method, "Anything", occurred)); - EXPECT_EQ(true, occurred); + EXPECT_TRUE(occurred); EXPECT_EQ(NOT_A_METHOD_CODE, method); } @@ -202,9 +202,9 @@ TEST(parser, interpretValueEmptyMap2) { static const CredentialsMap clientCredsMap{}; int method = NOT_A_METHOD_CODE; bool occurred = true; - EXPECT_EQ(false, + EXPECT_FALSE( credsBackend.interpretValue(clientCredsMap, method, "Anything", occurred)); - EXPECT_EQ(true, occurred); + EXPECT_TRUE(occurred); EXPECT_EQ(NOT_A_METHOD_CODE, method); } diff --git a/test/service/main/cmdlineparser.cpp b/test/service/main/cmdlineparser.cpp index 1869a68..5558379 100644 --- a/test/service/main/cmdlineparser.cpp +++ b/test/service/main/cmdlineparser.cpp @@ -219,7 +219,7 @@ TEST_F(CynaraCommandlineTest, maskOption) { ASSERT_FALSE(options.m_error); ASSERT_FALSE(options.m_exit); ASSERT_FALSE(options.m_daemon); - ASSERT_EQ(options.m_mask, 0666); + ASSERT_EQ(options.m_mask, static_cast(0666)); ASSERT_EQ(options.m_uid, static_cast(-1)); ASSERT_EQ(options.m_gid, static_cast(-1)); ASSERT_TRUE(out.empty()); @@ -314,7 +314,7 @@ TEST_F(CynaraCommandlineTest, userOptionName) { ASSERT_FALSE(options.m_exit); ASSERT_FALSE(options.m_daemon); ASSERT_EQ(options.m_mask, static_cast(-1)); - ASSERT_EQ(options.m_uid, 0); + ASSERT_EQ(options.m_uid, static_cast(0)); ASSERT_EQ(options.m_gid, static_cast(-1)); ASSERT_TRUE(out.empty()); ASSERT_TRUE(err.empty()); @@ -346,7 +346,7 @@ TEST_F(CynaraCommandlineTest, userOptionUid) { ASSERT_FALSE(options.m_exit); ASSERT_FALSE(options.m_daemon); ASSERT_EQ(options.m_mask, static_cast(-1)); - ASSERT_EQ(options.m_uid, 1234); + ASSERT_EQ(options.m_uid, static_cast(1234)); ASSERT_EQ(options.m_gid, static_cast(-1)); ASSERT_TRUE(out.empty()); ASSERT_TRUE(err.empty()); @@ -441,7 +441,7 @@ TEST_F(CynaraCommandlineTest, groupOptionName) { ASSERT_FALSE(options.m_daemon); ASSERT_EQ(options.m_mask, static_cast(-1)); ASSERT_EQ(options.m_uid, static_cast(-1)); - ASSERT_EQ(options.m_gid, 0); + ASSERT_EQ(options.m_gid, static_cast(0)); ASSERT_TRUE(out.empty()); ASSERT_TRUE(err.empty()); } @@ -473,7 +473,7 @@ TEST_F(CynaraCommandlineTest, groupOptionGid) { ASSERT_FALSE(options.m_daemon); ASSERT_EQ(options.m_mask, static_cast(-1)); ASSERT_EQ(options.m_uid, static_cast(-1)); - ASSERT_EQ(options.m_gid, 1234); + ASSERT_EQ(options.m_gid, static_cast(1234)); ASSERT_TRUE(out.empty()); ASSERT_TRUE(err.empty()); } diff --git a/test/storage/inmemorystoragebackend/buckets.cpp b/test/storage/inmemorystoragebackend/buckets.cpp index 4fdd03f..58eecd5 100644 --- a/test/storage/inmemorystoragebackend/buckets.cpp +++ b/test/storage/inmemorystoragebackend/buckets.cpp @@ -44,7 +44,7 @@ TEST_F(InMemoryStorageBackendFixture, createBucket) { PolicyBucketId bucketId = "new-bucket"; backend.createBucket(bucketId, defaultPolicy); - ASSERT_EQ(1, m_buckets.size()); + ASSERT_EQ(static_cast(1), m_buckets.size()); ASSERT_NE(m_buckets.end(), m_buckets.find(bucketId)); ASSERT_EQ(defaultPolicy, m_buckets.at(bucketId).defaultPolicy()); ASSERT_THAT(m_buckets.at(bucketId), IsEmpty()); diff --git a/test/storage/inmemorystoragebackend/inmemorystoragebackendfixture.h b/test/storage/inmemorystoragebackend/inmemorystoragebackendfixture.h index 7d3c7bc..76616fc 100644 --- a/test/storage/inmemorystoragebackend/inmemorystoragebackendfixture.h +++ b/test/storage/inmemorystoragebackend/inmemorystoragebackendfixture.h @@ -82,7 +82,7 @@ protected: static void ASSERT_DB_VIRGIN(Cynara::Buckets &buckets) { using ::testing::IsEmpty; - ASSERT_EQ(1, buckets.size()); + ASSERT_EQ(static_cast(1), buckets.size()); auto defaultBucketIter = buckets.find(Cynara::defaultPolicyBucketId); ASSERT_NE(buckets.end(), defaultBucketIter); auto &defaultBucket = defaultBucketIter->second; @@ -92,7 +92,7 @@ protected: static void ASSERT_DB_EMPTY(Cynara::Buckets &buckets) { using ::testing::IsEmpty; - ASSERT_EQ(0, buckets.size()); + ASSERT_EQ(static_cast(0), buckets.size()); ASSERT_THAT(buckets, IsEmpty()); } -- 2.7.4