Commit 0b6958b9 authored by George Nash's avatar George Nash

[IOT-2539] Clean sign-compare warnings

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's avatarGeorge Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21689Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarDan Mihai <Daniel.Mihai@microsoft.com>
(cherry picked from commit 65cc1e5d)
parent 9fa87391
......@@ -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;
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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;
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment