From 6d958ba51b37be10a0340b92e6387d592a9e9ad8 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 29 Aug 2016 11:41:59 -0700 Subject: [PATCH] Fix compiler warnings in unit tests. (#488) --- tests/unit/test_hmac_sha256.cpp | 4 ++-- tests/unit/test_lowpan.cpp | 8 ++++---- tests/unit/test_message.cpp | 4 ++-- tests/unit/test_ncp_buffer.cpp | 2 +- tests/unit/test_util.cpp | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unit/test_hmac_sha256.cpp b/tests/unit/test_hmac_sha256.cpp index b6f8e6dd8..b0f5458c6 100644 --- a/tests/unit/test_hmac_sha256.cpp +++ b/tests/unit/test_hmac_sha256.cpp @@ -67,8 +67,8 @@ void TestHmacSha256(void) for (int i = 0; tests[i].key != NULL; i++) { - otCryptoHmacSha256Start(tests[i].key, strlen(tests[i].key)); - otCryptoHmacSha256Update(tests[i].data, strlen(tests[i].data)); + otCryptoHmacSha256Start(tests[i].key, static_cast(strlen(tests[i].key))); + otCryptoHmacSha256Update(tests[i].data, static_cast(strlen(tests[i].data))); otCryptoHmacSha256Finish(hash); VerifyOrQuit(memcmp(hash, tests[i].hash, sizeof(tests[i].hash)) == 0, diff --git a/tests/unit/test_lowpan.cpp b/tests/unit/test_lowpan.cpp index f2b392983..fe906d1e1 100644 --- a/tests/unit/test_lowpan.cpp +++ b/tests/unit/test_lowpan.cpp @@ -83,7 +83,7 @@ void TestLowpanIphc(void) Message *message = NULL; uint8_t result[1500]; - unsigned resultLength = 0; + uint16_t resultLength = 0; Mac::Address macSource; Mac::Address macDest; @@ -112,7 +112,7 @@ void TestLowpanIphc(void) Mac::Frame frame; frame.mPsdu = iphcVector.data(); - frame.mLength = iphcVector.size(); + frame.mLength = static_cast(iphcVector.size()); frame.GetSrcAddr(macSource); frame.GetDstAddr(macDest); @@ -126,7 +126,7 @@ void TestLowpanIphc(void) frame.GetPayloadLength(), 0); uint16_t ip6PayloadLength = frame.GetPayloadLength() - - decompressedBytes; + static_cast(decompressedBytes); SuccessOrQuit(message->Append(frame.GetPayload() + decompressedBytes, ip6PayloadLength), "6lo: Message::Append failed"); @@ -150,7 +150,7 @@ void TestLowpanIphc(void) printf("Compressed OpenThread:\n"); otTestPrintHex(result, compressBytes); - VerifyOrQuit(memcmp(frame.GetPayload(), result, compressBytes) == 0, + VerifyOrQuit(memcmp(frame.GetPayload(), result, static_cast(compressBytes)) == 0, "6lo: Lowpan::Compress failed"); SuccessOrQuit(Message::Free(*message), "6lo: Message:Free failed"); diff --git a/tests/unit/test_message.cpp b/tests/unit/test_message.cpp index 09c1f1549..921822e8e 100644 --- a/tests/unit/test_message.cpp +++ b/tests/unit/test_message.cpp @@ -36,7 +36,7 @@ extern"C" void otSignalTaskletPending(void) { } -extern "C" void otPlatDiagAlarmFired() +extern "C" void otPlatDiagAlarmFired(void) { } @@ -50,7 +50,7 @@ void TestMessage(void) for (unsigned i = 0; i < sizeof(writeBuffer); i++) { - writeBuffer[i] = random(); + writeBuffer[i] = static_cast(random()); } VerifyOrQuit((message = Thread::Message::New(Thread::Message::kTypeIp6, 0)) != NULL, diff --git a/tests/unit/test_ncp_buffer.cpp b/tests/unit/test_ncp_buffer.cpp index b7db16527..ef09246dd 100644 --- a/tests/unit/test_ncp_buffer.cpp +++ b/tests/unit/test_ncp_buffer.cpp @@ -110,7 +110,7 @@ void DumpBuffer(const char *aTextMessage, uint8_t *aBuffer, uint16_t aBufferLeng { byte = *aBuffer++; printf("%02X ", byte); - charBuff[counter] = isprint(byte) ? byte : '.'; + charBuff[counter] = isprint(byte) ? static_cast(byte) : '.'; counter++; if (counter == kBytesPerLine) diff --git a/tests/unit/test_util.cpp b/tests/unit/test_util.cpp index 7f53cd060..cd0dbefbe 100644 --- a/tests/unit/test_util.cpp +++ b/tests/unit/test_util.cpp @@ -40,7 +40,7 @@ void otTestHexToVector(std::string &aHex, std::vector &aOutBytes) while (ss >> word) { - uint8_t n = strtol(word.data(), NULL, 16); + uint8_t n = static_cast(strtol(word.data(), NULL, 16)); aOutBytes.push_back(n); } } @@ -63,12 +63,12 @@ void otTestPrintHex(uint8_t *aBuffer, int aLength) void otTestPrintHex(std::string &aString) { - otTestPrintHex((uint8_t *)aString.data(), aString.size()); + otTestPrintHex((uint8_t *)aString.data(), static_cast(aString.size())); } void otTestPrintHex(std::vector &aBytes) { - otTestPrintHex((uint8_t *)&aBytes[0], aBytes.size()); + otTestPrintHex((uint8_t *)&aBytes[0], static_cast(aBytes.size())); }