[IOT-2539] Clean sign-compare warnings 99/22199/3
authorGeorge Nash <george.nash@intel.com>
Mon, 31 Jul 2017 21:12:13 +0000 (14:12 -0700)
committerGeorge Nash <george.nash@intel.com>
Tue, 29 Aug 2017 15:39:22 +0000 (15:39 +0000)
It is common to do a compair with a const value in unit
tests. For example EXPECT_EQ(3, value).  If `value` is an
unsigned type this will produce the sign-compare compiler
warning. The compiler defaults to treating constant
numbers as a signed data type.  Adding a sufix u (i.e. 3u)
will tell the compiler to treat the constant as an
unsigned data type.

In other cases the type is cast to an unsigned or signed
value before the comparison.

In aclresourcetest.cpp the return type for GetNumberOfResource
function was updated to return size_t since in all the test
conditions it is compared with variable of size_t or a
constant number.

Bug: https://jira.iotivity.org/browse/IOT-2539
Change-Id: I7e47bfb9f027304abd975eb0d8e577cbd484545a
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21689
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
(cherry picked from commit 65cc1e5d3b263c13fd6d784303d8e3640c88ef56)

resource/csdk/connectivity/test/caprotocolmessagetest.cpp
resource/csdk/connectivity/test/ssladapter_test.cpp
resource/csdk/security/unittest/aclresourcetest.cpp
resource/csdk/security/unittest/base64tests.cpp
resource/csdk/stack/test/cbortests.cpp

index e05308b..5f63420 100644 (file)
@@ -208,7 +208,7 @@ TEST(CAProtocolMessage, CAGetTokenFromPDU)
     memset(&inData, 0, sizeof(CAInfo_t));
     inData.token = (CAToken_t)"token";
     tokenLength = strlen(inData.token);
-    ASSERT_LE(tokenLength, UINT8_MAX);
+    ASSERT_LE(tokenLength, static_cast<size_t>(UINT8_MAX));
     inData.tokenLength = (uint8_t)tokenLength;
     inData.type = CA_MSG_NONCONFIRM;
 
index e02a04d..ed1b0bb 100644 (file)
@@ -3024,7 +3024,7 @@ TEST(TLSAdapter, Test_ParseChain)
     size_t ret = ParseChain(&crt, certChain, certChainLen, &errNum);
     mbedtls_x509_crt_free(&crt);
 
-    EXPECT_EQ(7, ret);
+    EXPECT_EQ(7u, ret);
     EXPECT_EQ(0, errNum);
 }
 
index ce1b13d..ff2f13d 100644 (file)
@@ -96,9 +96,9 @@ exit:
     return false;
 }
 
-static int GetNumberOfResource(const OicSecAce_t* ace)
+static size_t GetNumberOfResource(const OicSecAce_t* ace)
 {
-    int ret = 0;
+    size_t ret = 0;
     OicSecRsrc_t* rsrc = NULL;
     LL_FOREACH(ace->resources, rsrc)
     {
@@ -237,7 +237,7 @@ TEST(ACLResourceTest, CBORACLConversion)
             numberOfCheckedAce++;
         }
     }
-    EXPECT_EQ(3, numberOfCheckedAce);
+    EXPECT_EQ(3u, numberOfCheckedAce);
 
     DeleteACLList(acl);
     DeleteACLList(secAcl);
@@ -542,7 +542,7 @@ TEST(ACLResourceTest, ACLDeleteWithMultiResourceTest)
     OicSecAce_t* savePtr = NULL;
     const OicSecAce_t* subjectAce1 = GetACLResourceData(&acl.aces->subjectuuid, &savePtr);
     ASSERT_TRUE(NULL != subjectAce1);
-    EXPECT_EQ(2, GetNumberOfResource(subjectAce1));
+    EXPECT_EQ(2u, GetNumberOfResource(subjectAce1));
 
     printf("\n\n");
     OicSecRsrc_t* rsrc = NULL;
@@ -565,7 +565,7 @@ TEST(ACLResourceTest, ACLDeleteWithMultiResourceTest)
     savePtr = NULL;
     const OicSecAce_t* subjectAce2 = GetACLResourceData(&acl.aces->subjectuuid, &savePtr);
     ASSERT_TRUE(NULL != subjectAce2);
-    EXPECT_EQ(1, GetNumberOfResource(subjectAce2));
+    EXPECT_EQ(1u, GetNumberOfResource(subjectAce2));
 
     // Perform cleanup
     OCPayloadDestroy((OCPayload *)securityPayload);
index ec15547..a7fd2be 100644 (file)
@@ -317,7 +317,7 @@ TEST(B64Test, RFC4648_EncodeTestVectors)
         b64Result = b64Encode((const uint8_t *)input[i], strlen(input[i]), buf, bufSize, &outputLength);
         EXPECT_EQ(B64_OK, b64Result)
                 << "Failed to Base64 encode \"" << input[i] << "\" to \"" << output[i] << "\"";
-        EXPECT_EQ(0, outputLength % 4)
+        EXPECT_EQ(0u, outputLength % 4)
                 << "The return size for all b64Encode operations should be a multiple of 4.";
         EXPECT_STREQ(output[i], buf)
                 << "Failed to Base64 encode \"" << input[i] << "\" to \"" << output[i] << "\"";
@@ -478,7 +478,7 @@ TEST(B64Test, EncodeThenDecode)
     char *b64Buf = (char *)OICCalloc(1, b64BufSize);
     ASSERT_NE(nullptr, b64Buf) << "memory allocation error.";
     EXPECT_EQ(B64_OK, b64Encode((const uint8_t *)input, sizeof(input), b64Buf, b64BufSize, &b64Size));
-    EXPECT_EQ(0, b64Size % 4) <<
+    EXPECT_EQ(0u, b64Size % 4) <<
                               "The return size for all b64Encode operations should be a multiple of 4.";
 
     size_t outSize;
index 4d78597..55e1a4c 100644 (file)
@@ -426,7 +426,7 @@ TEST(CborEmptyArrayTest, EmptyArrayArraySetGetTest)
 
     for(size_t i = 0; i < MAX_REP_ARRAY_DEPTH; i++)
     {
-        EXPECT_EQ(0, dimensions_out[i]);
+        EXPECT_EQ(0u, dimensions_out[i]);
     }
 
     // Cleanup