Enable and adress /W4 warnings in VS

This commit is contained in:
dcristoloveanu 2016-07-05 17:32:31 -07:00
Родитель 313550b1ca
Коммит dad6096abf
8 изменённых файлов: 59 добавлений и 47 удалений

Просмотреть файл

@ -20,6 +20,10 @@ endif()
include (CTest)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
include(ExternalProject)
#the following variables are project-wide and can be used with cmake-gui
@ -140,10 +144,10 @@ endif()
IF(WIN32)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# Make warning as error
add_definitions(/WX)
ELSE()
# Make warning as error
# Make warning as error
add_definitions(/WX)
ELSE()
# Make warning as error
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
ENDIF(WIN32)

@ -1 +1 @@
Subproject commit 5d9f0519117ab8fd6a43675767cf5cb4f2e1ccab
Subproject commit 7e2dcb9f24ad1a711ae640a274146d5076d8c3cf

Просмотреть файл

@ -56,7 +56,7 @@ typedef struct MQTT_CLIENT_OPTIONS_TAG
char* willMessage;
char* username;
char* password;
int keepAliveInterval;
uint16_t keepAliveInterval;
bool messageRetain;
bool useCleanSession;
QOS_VALUE qualityOfServiceValue;

Просмотреть файл

@ -95,6 +95,8 @@ static uint8_t byteutil_readByte(uint8_t** buffer)
static void sendComplete(void* context, IO_SEND_RESULT send_result)
{
MQTT_CLIENT* mqttData = (MQTT_CLIENT*)context;
/* Bug: we should not ignore the send_result */
(void)send_result;
if (mqttData != NULL && mqttData->fnOperationCallback != NULL)
{
if (mqttData->packetState == DISCONNECT_TYPE)
@ -583,6 +585,7 @@ int mqtt_client_connect(MQTT_CLIENT_HANDLE handle, XIO_HANDLE xioHandle, MQTT_CL
/*SRS_MQTT_CLIENT_07_006: [If any of the parameters handle, ioHandle, or mqttOptions are NULL then mqtt_client_connect shall return a non-zero value.]*/
if (handle == NULL || mqttOptions == NULL)
{
LOG(LOG_ERROR, LOG_LINE, "mqtt_client_connect: NULL argument (handle = %p, mqttOptions = %p)", handle, mqttOptions);
result = __LINE__;
}
else

Просмотреть файл

@ -269,7 +269,7 @@ static int constructSubscibeTypeVariableHeader(BUFFER_HANDLE ctrlPacket, uint16_
return result;
}
static BUFFER_HANDLE constructPublishReply(CONTROL_PACKET_TYPE type, int flags, uint16_t packetId)
static BUFFER_HANDLE constructPublishReply(CONTROL_PACKET_TYPE type, uint8_t flags, uint16_t packetId)
{
BUFFER_HANDLE result = BUFFER_new();
if (result != NULL)
@ -289,7 +289,7 @@ static BUFFER_HANDLE constructPublishReply(CONTROL_PACKET_TYPE type, int flags,
}
else
{
*iterator = type | flags;
*iterator = (uint8_t)type | flags;
iterator++;
*iterator = 0x2;
iterator++;
@ -339,7 +339,7 @@ static int constructFixedHeader(BUFFER_HANDLE ctrlPacket, CONTROL_PACKET_TYPE pa
else
{
uint8_t* iterator = BUFFER_u_char(fixedHeader);
*iterator = packetType | flags;
*iterator = (uint8_t)packetType | flags;
iterator++;
(void)memcpy(iterator, remainSize, index);
@ -915,7 +915,6 @@ int mqtt_codec_bytesReceived(MQTTCODEC_HANDLE handle, const unsigned char* buffe
}
else if (codec_Data->codecState == CODEC_STATE_VAR_HEADER)
{
size_t payloadLen = 0;
if (codec_Data->headerData == NULL)
{
codec_Data->codecState = CODEC_STATE_PAYLOAD;

Просмотреть файл

@ -58,7 +58,7 @@ static const TICK_COUNTER_HANDLE TEST_COUNTER_HANDLE = (TICK_COUNTER_HANDLE)0x12
static const MQTTCODEC_HANDLE TEST_MQTTCODEC_HANDLE = (MQTTCODEC_HANDLE)0x13;
static const MQTT_MESSAGE_HANDLE TEST_MESSAGE_HANDLE = (MQTT_MESSAGE_HANDLE)0x14;
static BUFFER_HANDLE TEST_BUFFER_HANDLE = (BUFFER_HANDLE)0x15;
static const uint64_t TEST_KEEP_ALIVE_INTERVAL = 20;
static const uint16_t TEST_KEEP_ALIVE_INTERVAL = 20;
static const uint16_t TEST_PACKET_ID = (uint16_t)0x1234;
static const unsigned char* TEST_BUFFER_U_CHAR = (const unsigned char*)0x19;
@ -85,12 +85,19 @@ extern "C" {
MQTTCODEC_HANDLE my_mqtt_codec_create(ON_PACKET_COMPLETE_CALLBACK packetComplete, void* callContext)
{
(void)callContext;
g_packetComplete = packetComplete;
return TEST_MQTTCODEC_HANDLE;
}
int my_xio_open(XIO_HANDLE handle, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context)
{
(void)handle;
/* Bug? : This is a bit wierd, why are we not using on_io_error and on_bytes_received? */
(void)on_bytes_received;
(void)on_bytes_received_context;
(void)on_io_error;
(void)on_io_error_context;
g_openComplete = on_io_open_complete;
g_onCompleteCtx = on_io_open_complete_context;
return 0;
@ -98,6 +105,7 @@ extern "C" {
int my_tickcounter_get_current_ms(TICK_COUNTER_HANDLE tick_counter, uint64_t* current_ms)
{
(void)tick_counter;
*current_ms = g_current_ms;
return 0;
}
@ -106,9 +114,13 @@ extern "C" {
}
#endif
void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
{
ASSERT_FAIL("umock_c reported error");
char temp_str[256];
(void)snprintf(temp_str, sizeof(temp_str), "umock_c reported error :%s", ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code));
ASSERT_FAIL(temp_str);
}
BEGIN_TEST_SUITE(mqtt_client_unittests)
@ -182,7 +194,7 @@ TEST_SUITE_CLEANUP(suite_cleanup)
TEST_FUNCTION_INITIALIZE(method_init)
{
if (TEST_MUTEX_ACQUIRE(test_serialize_mutex) != 0)
if (TEST_MUTEX_ACQUIRE(test_serialize_mutex))
{
ASSERT_FAIL("Could not acquire test serialization mutex.");
}
@ -211,6 +223,7 @@ static void TestRecvCallback(MQTT_MESSAGE_HANDLE msgHandle, void* context)
static void TestOpCallback(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_RESULT actionResult, const void* msgInfo, void* context)
{
(void)handle;
switch (actionResult)
{
case MQTT_CLIENT_ON_CONNACK:
@ -309,18 +322,20 @@ static void SetupMqttLibOptions(MQTT_CLIENT_OPTIONS* options, const char* client
const char* willTopic,
const char* username,
const char* password,
uint64_t keepAlive,
uint16_t keepAlive,
bool messageRetain,
bool cleanSession,
QOS_VALUE qos)
{
options->clientId = (char*)clientId;
options->willMessage = (char*)willMsg;
options->willTopic = (char*)willTopic;
options->username = (char*)username;
options->password = (char*)password;
options->keepAliveInterval = (int)keepAlive;
options->keepAliveInterval = keepAlive;
options->useCleanSession = cleanSession;
options->qualityOfServiceValue = qos;
options->messageRetain = messageRetain;
}
/* mqttclient_connect */
@ -1069,7 +1084,7 @@ TEST_FUNCTION(mqtt_client_dowork_ping_succeeds)
STRICT_EXPECTED_CALL(BUFFER_u_char(TEST_BUFFER_HANDLE)).SetReturn(CONNACK_RESP);
STRICT_EXPECTED_CALL(BUFFER_length(TEST_BUFFER_HANDLE)).SetReturn(length);
int result = mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
(void)mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
g_openComplete(g_onCompleteCtx, IO_OPEN_OK);
g_packetComplete(mqttHandle, CONNACK_TYPE, 0, connack_handle);
umock_c_reset_all_calls();
@ -1111,7 +1126,7 @@ TEST_FUNCTION(mqtt_client_dowork_ping_No_ping_response_succeeds)
STRICT_EXPECTED_CALL(BUFFER_u_char(TEST_BUFFER_HANDLE)).SetReturn(CONNACK_RESP);
STRICT_EXPECTED_CALL(BUFFER_length(TEST_BUFFER_HANDLE)).SetReturn(length);
int result = mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
(void)mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
g_openComplete(g_onCompleteCtx, IO_OPEN_OK);
g_packetComplete(mqttHandle, CONNACK_TYPE, 0, connack_handle);
@ -1153,7 +1168,7 @@ TEST_FUNCTION(mqtt_client_dowork_no_keepalive_no_ping_succeeds)
STRICT_EXPECTED_CALL(BUFFER_u_char(TEST_BUFFER_HANDLE)).SetReturn(CONNACK_RESP);
STRICT_EXPECTED_CALL(BUFFER_length(TEST_BUFFER_HANDLE)).SetReturn(length);
int result = mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
(void)mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
g_openComplete(g_onCompleteCtx, IO_OPEN_OK);
g_packetComplete(mqttHandle, CONNACK_TYPE, 0, connack_handle);
umock_c_reset_all_calls();
@ -1190,7 +1205,7 @@ TEST_FUNCTION(mqtt_client_dowork_no_ping_succeeds)
STRICT_EXPECTED_CALL(BUFFER_u_char(TEST_BUFFER_HANDLE)).SetReturn(CONNACK_RESP);
STRICT_EXPECTED_CALL(BUFFER_length(TEST_BUFFER_HANDLE)).SetReturn(length);
int result = mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
(void)mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
g_openComplete(g_onCompleteCtx, IO_OPEN_OK);
g_packetComplete(mqttHandle, CONNACK_TYPE, 0, connack_handle);
umock_c_reset_all_calls();
@ -1224,7 +1239,7 @@ TEST_FUNCTION(mqtt_client_dowork_tickcounter_fails_succeeds)
STRICT_EXPECTED_CALL(BUFFER_u_char(TEST_BUFFER_HANDLE)).SetReturn(CONNACK_RESP);
STRICT_EXPECTED_CALL(BUFFER_length(TEST_BUFFER_HANDLE)).SetReturn(length);
int result = mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
(void)mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
g_openComplete(g_onCompleteCtx, IO_OPEN_OK);
g_packetComplete(mqttHandle, CONNACK_TYPE, 0, connack_handle);
umock_c_reset_all_calls();
@ -1278,8 +1293,6 @@ TEST_FUNCTION(mqtt_client_recvCompleteCallback_context_NULL_fails)
TEST_FUNCTION(mqtt_client_recvCompleteCallback_BUFFER_HANDLE_NULL_fails)
{
// arrange
unsigned char CONNACK_RESP[] = { 0x1, 0x0 };
size_t length = sizeof(CONNACK_RESP) / sizeof(CONNACK_RESP[0]);
TEST_COMPLETE_DATA_INSTANCE testData;
CONNECT_ACK connack = { 0 };
@ -1635,7 +1648,6 @@ TEST_FUNCTION(mqtt_client_recvCompleteCallback_SUBACK_succeeds)
TEST_FUNCTION(mqtt_client_recvCompleteCallback_UNSUBACK_succeeds)
{
// arrange
const size_t PACKET_RETCODE_COUNT = 4;
unsigned char UNSUBSCRIBE_ACK_RESP[] = { 0xB0, 0x02, 0x12, 0x34 };
size_t length = sizeof(UNSUBSCRIBE_ACK_RESP) / sizeof(UNSUBSCRIBE_ACK_RESP[0]);
TEST_COMPLETE_DATA_INSTANCE testData;

Просмотреть файл

@ -76,7 +76,7 @@ static void SetupMqttLibOptions(MQTT_CLIENT_OPTIONS* options, const char* client
const char* willTopic,
const char* username,
const char* password,
int keepAlive,
uint16_t keepAlive,
bool messageRetain,
bool cleanSession,
QOS_VALUE qos)
@ -111,9 +111,13 @@ extern size_t real_BUFFER_length(BUFFER_HANDLE handle);
TEST_MUTEX_HANDLE test_serialize_mutex;
void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
{
ASSERT_FAIL("umock_c reported error");
char temp_str[256];
(void)snprintf(temp_str, sizeof(temp_str), "umock_c reported error :%s", ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code));
ASSERT_FAIL(temp_str);
}
BEGIN_TEST_SUITE(mqtt_codec_unittests)
@ -149,7 +153,7 @@ TEST_SUITE_CLEANUP(suite_cleanup)
TEST_FUNCTION_INITIALIZE(method_init)
{
if (TEST_MUTEX_ACQUIRE(test_serialize_mutex) != 0)
if (TEST_MUTEX_ACQUIRE(test_serialize_mutex))
{
ASSERT_FAIL("Could not acquire test serialization mutex.");
}
@ -173,6 +177,7 @@ static void PrintLogFunction(unsigned int options, char* format, ...)
static void TestOnCompleteCallback(void* context, CONTROL_PACKET_TYPE packet, int flags, BUFFER_HANDLE headerData)
{
TEST_COMPLETE_DATA_INSTANCE* testData = (TEST_COMPLETE_DATA_INSTANCE*)context;
(void)flags;
if (testData != NULL)
{
if (packet == PINGRESP_TYPE)
@ -432,8 +437,6 @@ TEST_FUNCTION(mqtt_codec_disconnect_succeed)
TEST_FUNCTION(mqtt_codec_disconnect_BUFFER_enlarge_fails)
{
// arrange
const unsigned char DISCONNECT_VALUE[] = { 0xE0, 0x00 };
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__LINE__);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
@ -450,8 +453,6 @@ TEST_FUNCTION(mqtt_codec_disconnect_BUFFER_enlarge_fails)
TEST_FUNCTION(mqtt_codec_ping_BUFFER_enlarge_fails)
{
// arrange
const unsigned char PING_VALUE[] = { 0xC0, 0x00 };
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__LINE__);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
@ -684,8 +685,6 @@ TEST_FUNCTION(mqtt_codec_publish_second_succeeds)
TEST_FUNCTION(mqtt_codec_publish_ack_pre_build_fail)
{
// arrange
unsigned char PUBLISH_ACK_VALUE[] = { 0x40, 0x02, 0x81, 0x58 };
EXPECTED_CALL(BUFFER_new());
STRICT_EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, 4))
.IgnoreArgument(1)
@ -996,7 +995,6 @@ TEST_FUNCTION(mqtt_codec_subscribe_succeeds)
TEST_FUNCTION(mqtt_codec_unsubscribe_subscribeList_NULL_fails)
{
// arrange
unsigned char UNSUBSCRIBE_VALUE[] = { 0x80, 0x0f, 0x81, 0x58, 0x00, 0x0a, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x00 };
// act
BUFFER_HANDLE handle = mqtt_codec_unsubscribe(TEST_PACKET_ID, NULL, 0);
@ -1010,8 +1008,6 @@ TEST_FUNCTION(mqtt_codec_unsubscribe_subscribeList_NULL_fails)
TEST_FUNCTION(mqtt_codec_unsubscribe_BUFFER_enlarge_fails)
{
// arrange
unsigned char UNSUBSCRIBE_VALUE[] = { 0x80, 0x0f, 0x81, 0x58, 0x00, 0x0a, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x00 };
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__LINE__);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
@ -1028,8 +1024,6 @@ TEST_FUNCTION(mqtt_codec_unsubscribe_BUFFER_enlarge_fails)
TEST_FUNCTION(mqtt_codec_unsubscribe_addListItemToUnsubscribePacket_BUFFER_enlarge_fails)
{
// arrange
unsigned char UNSUBSCRIBE_VALUE[] = { 0x80, 0x0f, 0x81, 0x58, 0x00, 0x0a, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x00 };
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG));
@ -1049,8 +1043,6 @@ TEST_FUNCTION(mqtt_codec_unsubscribe_addListItemToUnsubscribePacket_BUFFER_enlar
TEST_FUNCTION(mqtt_codec_unsubscribe_constructFixedHeader_fails)
{
// arrange
unsigned char UNSUBSCRIBE_VALUE[] = { 0xa0, 0x18, 0x81, 0x58, 0x00, 0x09, 0x73, 0x75, 0x62, 0x54, 0x6f, 0x70, 0x69, 0x63, 0x31, 0x00, 0x09, 0x73, 0x75, 0x62, 0x54, 0x6f, 0x70, 0x69, 0x63, 0x32 };
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG));
@ -1171,7 +1163,6 @@ TEST_FUNCTION(mqtt_codec_bytesReceived_connack_succeed)
{
// arrange
unsigned char CONNACK_RESP[] = { 0x20, 0x2, 0x1, 0x0 };
unsigned char TEST_CONNACK_VAR[] = { 0x1, 0x0 };
size_t length = sizeof(CONNACK_RESP) / sizeof(CONNACK_RESP[0]);
TEST_COMPLETE_DATA_INSTANCE testData = { 0 };
@ -1213,7 +1204,6 @@ TEST_FUNCTION(mqtt_codec_bytesReceived_puback_succeed)
{
// arrange
unsigned char PUBACK_RESP[] = { 0x40, 0x2, 0x12, 0x34 };
unsigned char TEST_PUBACK_VAR[] = { 0x12, 0x34 };
size_t length = sizeof(PUBACK_RESP) / sizeof(PUBACK_RESP[0]);
TEST_COMPLETE_DATA_INSTANCE testData = { 0 };

Просмотреть файл

@ -47,7 +47,7 @@ extern "C" {
static bool g_fail_alloc_calls;
static const char* TEST_SUBSCRIPTION_TOPIC = "subTopic";
static const uint8_t TEST_PACKET_ID = (uint8_t)0x1234;
static const uint8_t TEST_PACKET_ID = (uint8_t)0x12;
static const char* TEST_TOPIC_NAME = "topic Name";
static const uint8_t* TEST_MESSAGE = (const uint8_t*)"Message to send";
static const int TEST_MSG_LEN = sizeof(TEST_MESSAGE)/sizeof(TEST_MESSAGE[0]);
@ -63,9 +63,13 @@ IMPLEMENT_UMOCK_C_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES);
TEST_MUTEX_HANDLE test_serialize_mutex;
void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
{
ASSERT_FAIL("umock_c reported error");
char temp_str[256];
(void)snprintf(temp_str, sizeof(temp_str), "umock_c reported error :%s", ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code));
ASSERT_FAIL(temp_str);
}
BEGIN_TEST_SUITE(mqtt_message_unittests)
@ -91,7 +95,7 @@ TEST_SUITE_CLEANUP(suite_cleanup)
TEST_FUNCTION_INITIALIZE(method_init)
{
if (TEST_MUTEX_ACQUIRE(test_serialize_mutex) != 0)
if (TEST_MUTEX_ACQUIRE(test_serialize_mutex))
{
ASSERT_FAIL("Could not acquire test serialization mutex.");
}