Update references to renamed macros from macro_utils.h

This commit is contained in:
Jelani Brandon 2019-03-26 16:53:47 -07:00 коммит произвёл GitHub
Родитель ea9f6112d0
Коммит 0828b0e308
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 136 добавлений и 200 удалений

2
deps/c-utility поставляемый

@ -1 +1 @@
Subproject commit bc83cba1230e98988ae5cd2328f4dcf8c49d5866
Subproject commit 3fadc94f33148d0368742a0c8520f8190c78eef4

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

@ -20,7 +20,7 @@ typedef struct MQTT_CLIENT_DATA_INSTANCE_TAG* MQTT_CLIENT_HANDLE;
MQTT_CLIENT_ON_PING_RESPONSE, \
MQTT_CLIENT_ON_DISCONNECT
DEFINE_ENUM(MQTT_CLIENT_ACTION_RESULT, MQTT_CLIENT_ACTION_VALUES);
MU_DEFINE_ENUM(MQTT_CLIENT_ACTION_RESULT, MQTT_CLIENT_ACTION_VALUES);
#define MQTT_CLIENT_EVENT_ERROR_VALUES \
MQTT_CLIENT_CONNECTION_ERROR, \
@ -30,7 +30,7 @@ DEFINE_ENUM(MQTT_CLIENT_ACTION_RESULT, MQTT_CLIENT_ACTION_VALUES);
MQTT_CLIENT_NO_PING_RESPONSE, \
MQTT_CLIENT_UNKNOWN_ERROR
DEFINE_ENUM(MQTT_CLIENT_EVENT_ERROR, MQTT_CLIENT_EVENT_ERROR_VALUES);
MU_DEFINE_ENUM(MQTT_CLIENT_EVENT_ERROR, MQTT_CLIENT_EVENT_ERROR_VALUES);
typedef void(*ON_MQTT_OPERATION_CALLBACK)(MQTT_CLIENT_ACTION_RESULT actionResult, const void* msgInfo, void* callbackCtx);
typedef void(*ON_MQTT_ERROR_CALLBACK)(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_ERROR error, void* callbackCtx);

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

@ -31,7 +31,7 @@ typedef struct MQTT_CLIENT_TAG* MQTT_CLIENT_HANDLE;
MQTT_CLIENT_ON_PING_RESPONSE, \
MQTT_CLIENT_ON_DISCONNECT
DEFINE_ENUM(MQTT_CLIENT_EVENT_RESULT, MQTT_CLIENT_EVENT_VALUES);
MU_DEFINE_ENUM(MQTT_CLIENT_EVENT_RESULT, MQTT_CLIENT_EVENT_VALUES);
#define MQTT_CLIENT_EVENT_ERROR_VALUES \
MQTT_CLIENT_CONNECTION_ERROR, \
@ -41,7 +41,7 @@ DEFINE_ENUM(MQTT_CLIENT_EVENT_RESULT, MQTT_CLIENT_EVENT_VALUES);
MQTT_CLIENT_NO_PING_RESPONSE, \
MQTT_CLIENT_UNKNOWN_ERROR
DEFINE_ENUM(MQTT_CLIENT_EVENT_ERROR, MQTT_CLIENT_EVENT_ERROR_VALUES);
MU_DEFINE_ENUM(MQTT_CLIENT_EVENT_ERROR, MQTT_CLIENT_EVENT_ERROR_VALUES);
typedef void(*ON_MQTT_OPERATION_CALLBACK)(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_RESULT actionResult, const void* msgInfo, void* callbackCtx);
typedef void(*ON_MQTT_ERROR_CALLBACK)(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_ERROR error, void* callbackCtx);

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

@ -5,6 +5,7 @@
#define MQTTCONST_H
#include "azure_c_shared_utility/crt_abstractions.h"
#include "azure_c_shared_utility/macro_utils.h"
#ifdef __cplusplus
#include <cstddef>
@ -33,7 +34,7 @@ extern "C" {
PACKET_TYPE_ERROR, \
UNKNOWN_TYPE
DEFINE_ENUM(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES)
MU_DEFINE_ENUM(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES)
#define QOS_VALUE_VALUES \
DELIVER_AT_MOST_ONCE = 0x00, \
@ -41,7 +42,7 @@ DEFINE_ENUM(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES)
DELIVER_EXACTLY_ONCE = 0x02, \
DELIVER_FAILURE = 0x80
DEFINE_ENUM(QOS_VALUE, QOS_VALUE_VALUES)
MU_DEFINE_ENUM(QOS_VALUE, QOS_VALUE_VALUES)
typedef struct APP_PAYLOAD_TAG
{

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

@ -7,11 +7,13 @@
#include "azure_c_shared_utility/crt_abstractions.h"
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/optimize_size.h"
#include "azure_c_shared_utility/macro_utils.h"
#include "azure_c_shared_utility/platform.h"
#include "azure_c_shared_utility/strings.h"
#include "azure_c_shared_utility/threadapi.h"
#include "azure_c_shared_utility/tickcounter.h"
#include "azure_c_shared_utility/xlogging.h"
#include "azure_c_shared_utility/macro_utils.h"
#include "azure_umqtt_c/mqtt_client.h"
#include "azure_umqtt_c/mqtt_codec.h"
@ -30,7 +32,7 @@
static const char* const TRUE_CONST = "true";
static const char* const FALSE_CONST = "false";
DEFINE_ENUM_STRINGS(QOS_VALUE, QOS_VALUE_VALUES);
MU_DEFINE_ENUM_STRINGS(QOS_VALUE, QOS_VALUE_VALUES);
typedef struct MQTT_CLIENT_TAG
{
@ -363,7 +365,7 @@ static int sendPacketItem(MQTT_CLIENT* mqtt_client, const unsigned char* data, s
if (tickcounter_get_current_ms(mqtt_client->packetTickCntr, &mqtt_client->packetSendTimeMs) != 0)
{
LogError("Failure getting current ms tickcounter");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -371,7 +373,7 @@ static int sendPacketItem(MQTT_CLIENT* mqtt_client, const unsigned char* data, s
if (result != 0)
{
LogError("%d: Failure sending control packet data", result);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -508,7 +510,7 @@ static int cloneMqttOptions(MQTT_CLIENT* mqtt_client, const MQTT_CLIENT_OPTIONS*
{
if (mallocAndStrcpy_s(&temp_option, mqttOptions->clientId) != 0)
{
result = __FAILURE__;
result = MU_FAILURE;
LogError("mallocAndStrcpy_s clientId");
}
else
@ -525,7 +527,7 @@ static int cloneMqttOptions(MQTT_CLIENT* mqtt_client, const MQTT_CLIENT_OPTIONS*
temp_option = NULL;
if (mallocAndStrcpy_s(&temp_option, mqttOptions->willTopic) != 0)
{
result = __FAILURE__;
result = MU_FAILURE;
LogError("mallocAndStrcpy_s willTopic");
}
else
@ -543,7 +545,7 @@ static int cloneMqttOptions(MQTT_CLIENT* mqtt_client, const MQTT_CLIENT_OPTIONS*
if (mallocAndStrcpy_s(&temp_option, mqttOptions->willMessage) != 0)
{
LogError("mallocAndStrcpy_s willMessage");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -560,7 +562,7 @@ static int cloneMqttOptions(MQTT_CLIENT* mqtt_client, const MQTT_CLIENT_OPTIONS*
if (mallocAndStrcpy_s(&temp_option, mqttOptions->username) != 0)
{
LogError("mallocAndStrcpy_s username");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -577,7 +579,7 @@ static int cloneMqttOptions(MQTT_CLIENT* mqtt_client, const MQTT_CLIENT_OPTIONS*
if (mallocAndStrcpy_s(&temp_option, mqttOptions->password) != 0)
{
LogError("mallocAndStrcpy_s password");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -625,7 +627,7 @@ static void ProcessPublishMessage(MQTT_CLIENT* mqtt_client, uint8_t* initialPos,
if (mqtt_client->logTrace)
{
trace_log = STRING_construct_sprintf("PUBLISH | IS_DUP: %s | RETAIN: %d | QOS: %s | TOPIC_NAME: %s", isDuplicateMsg ? TRUE_CONST : FALSE_CONST,
isRetainMsg ? 1 : 0, ENUM_TO_STRING(QOS_VALUE, qosValue), topicName);
isRetainMsg ? 1 : 0, MU_ENUM_TO_STRING(QOS_VALUE, qosValue), topicName);
}
#endif
uint16_t packetId = 0;
@ -981,7 +983,7 @@ int mqtt_client_connect(MQTT_CLIENT_HANDLE handle, XIO_HANDLE xioHandle, MQTT_CL
if (handle == NULL || mqttOptions == NULL || xioHandle == NULL)
{
LogError("mqtt_client_connect: NULL argument (handle = %p, mqttOptions = %p, xioHandle: %p)", handle, mqttOptions, xioHandle);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -994,14 +996,14 @@ int mqtt_client_connect(MQTT_CLIENT_HANDLE handle, XIO_HANDLE xioHandle, MQTT_CL
if (cloneMqttOptions(mqtt_client, mqttOptions) != 0)
{
LogError("Error: Clone Mqtt Options failed");
result = __FAILURE__;
result = MU_FAILURE;
}
/*Codes_SRS_MQTT_CLIENT_07_008: [mqtt_client_connect shall open the XIO_HANDLE by calling into the xio_open interface.]*/
else if (xio_open(xioHandle, onOpenComplete, mqtt_client, onBytesReceived, mqtt_client, onIoError, mqtt_client) != 0)
{
/*Codes_SRS_MQTT_CLIENT_07_007: [If any failure is encountered then mqtt_client_connect shall return a non-zero value.]*/
LogError("Error: io_open failed");
result = __FAILURE__;
result = MU_FAILURE;
mqtt_client->xioHandle = NULL;
// Remove cloned options
clear_mqtt_options(mqtt_client);
@ -1022,7 +1024,7 @@ int mqtt_client_publish(MQTT_CLIENT_HANDLE handle, MQTT_MESSAGE_HANDLE msgHandle
{
/*Codes_SRS_MQTT_CLIENT_07_019: [If one of the parameters handle or msgHandle is NULL then mqtt_client_publish shall return a non-zero value.]*/
LogError("Invalid parameter specified mqtt_client: %p, msgHandle: %p", mqtt_client, msgHandle);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1032,7 +1034,7 @@ int mqtt_client_publish(MQTT_CLIENT_HANDLE handle, MQTT_MESSAGE_HANDLE msgHandle
{
/*Codes_SRS_MQTT_CLIENT_07_020: [If any failure is encountered then mqtt_client_unsubscribe shall return a non-zero value.]*/
LogError("Error: mqttmessage_getApplicationMsg failed");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1048,7 +1050,7 @@ int mqtt_client_publish(MQTT_CLIENT_HANDLE handle, MQTT_MESSAGE_HANDLE msgHandle
{
/*Codes_SRS_MQTT_CLIENT_07_020: [If any failure is encountered then mqtt_client_unsubscribe shall return a non-zero value.]*/
LogError("Error: mqtt_codec_publish failed");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1060,7 +1062,7 @@ int mqtt_client_publish(MQTT_CLIENT_HANDLE handle, MQTT_MESSAGE_HANDLE msgHandle
{
/*Codes_SRS_MQTT_CLIENT_07_020: [If any failure is encountered then mqtt_client_unsubscribe shall return a non-zero value.]*/
LogError("Error: mqtt_client_publish send failed");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1086,7 +1088,7 @@ int mqtt_client_subscribe(MQTT_CLIENT_HANDLE handle, uint16_t packetId, SUBSCRIB
{
/*Codes_SRS_MQTT_CLIENT_07_013: [If any of the parameters handle, subscribeList is NULL or count is 0 then mqtt_client_subscribe shall return a non-zero value.]*/
LogError("Invalid parameter specified mqtt_client: %p, subscribeList: %p, count: %lu, packetId: %d", mqtt_client, subscribeList, (unsigned long)count, packetId);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1097,7 +1099,7 @@ int mqtt_client_subscribe(MQTT_CLIENT_HANDLE handle, uint16_t packetId, SUBSCRIB
{
/*Codes_SRS_MQTT_CLIENT_07_014: [If any failure is encountered then mqtt_client_subscribe shall return a non-zero value.]*/
LogError("Error: mqtt_codec_subscribe failed");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1109,7 +1111,7 @@ int mqtt_client_subscribe(MQTT_CLIENT_HANDLE handle, uint16_t packetId, SUBSCRIB
{
/*Codes_SRS_MQTT_CLIENT_07_014: [If any failure is encountered then mqtt_client_subscribe shall return a non-zero value.]*/
LogError("Error: mqtt_client_subscribe send failed");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1134,7 +1136,7 @@ int mqtt_client_unsubscribe(MQTT_CLIENT_HANDLE handle, uint16_t packetId, const
{
/*Codes_SRS_MQTT_CLIENT_07_016: [If any of the parameters handle, unsubscribeList is NULL or count is 0 then mqtt_client_unsubscribe shall return a non-zero value.]*/
LogError("Invalid parameter specified mqtt_client: %p, unsubscribeList: %p, count: %lu, packetId: %d", mqtt_client, unsubscribeList, (unsigned long)count, packetId);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1145,7 +1147,7 @@ int mqtt_client_unsubscribe(MQTT_CLIENT_HANDLE handle, uint16_t packetId, const
{
/*Codes_SRS_MQTT_CLIENT_07_017: [If any failure is encountered then mqtt_client_unsubscribe shall return a non-zero value.]*/
LogError("Error: mqtt_codec_unsubscribe failed");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1157,7 +1159,7 @@ int mqtt_client_unsubscribe(MQTT_CLIENT_HANDLE handle, uint16_t packetId, const
{
/*Codes_SRS_MQTT_CLIENT_07_017: [If any failure is encountered then mqtt_client_unsubscribe shall return a non-zero value.].]*/
LogError("Error: mqtt_client_unsubscribe send failed");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1181,7 +1183,7 @@ int mqtt_client_disconnect(MQTT_CLIENT_HANDLE handle, ON_MQTT_DISCONNECTED_CALLB
if (mqtt_client == NULL)
{
/*Codes_SRS_MQTT_CLIENT_07_010: [If the parameters handle is NULL then mqtt_client_disconnect shall return a non-zero value.]*/
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1193,7 +1195,7 @@ int mqtt_client_disconnect(MQTT_CLIENT_HANDLE handle, ON_MQTT_DISCONNECTED_CALLB
/*Codes_SRS_MQTT_CLIENT_07_011: [If any failure is encountered then mqtt_client_disconnect shall return a non-zero value.]*/
LogError("Error: mqtt_client_disconnect failed");
mqtt_client->packetState = PACKET_TYPE_ERROR;
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1208,7 +1210,7 @@ int mqtt_client_disconnect(MQTT_CLIENT_HANDLE handle, ON_MQTT_DISCONNECTED_CALLB
{
/*Codes_SRS_MQTT_CLIENT_07_011: [If any failure is encountered then mqtt_client_disconnect shall return a non-zero value.]*/
LogError("Error: mqtt_client_disconnect send failed");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{

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

@ -47,7 +47,7 @@
static const char* const TRUE_CONST = "true";
static const char* const FALSE_CONST = "false";
DEFINE_ENUM(CODEC_STATE_RESULT, CODEC_STATE_VALUES);
MU_DEFINE_ENUM(CODEC_STATE_RESULT, CODEC_STATE_VALUES);
typedef struct MQTTCODEC_INSTANCE_TAG
{
@ -130,7 +130,7 @@ static int addListItemsToUnsubscribePacket(BUFFER_HANDLE ctrlPacket, const char*
int result = 0;
if (payloadList == NULL || ctrlPacket == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -142,11 +142,11 @@ static int addListItemsToUnsubscribePacket(BUFFER_HANDLE ctrlPacket, const char*
size_t topicLen = strlen(payloadList[index]);
if (topicLen > USHRT_MAX)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else if (BUFFER_enlarge(ctrlPacket, topicLen + 2) != 0)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -168,7 +168,7 @@ static int addListItemsToSubscribePacket(BUFFER_HANDLE ctrlPacket, SUBSCRIBE_PAY
int result = 0;
if (payloadList == NULL || ctrlPacket == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -180,11 +180,11 @@ static int addListItemsToSubscribePacket(BUFFER_HANDLE ctrlPacket, SUBSCRIBE_PAY
size_t topicLen = strlen(payloadList[index].subscribeTopic);
if (topicLen > USHRT_MAX)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else if (BUFFER_enlarge(ctrlPacket, topicLen + 2 + 1) != 0)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -208,14 +208,14 @@ static int constructConnectVariableHeader(BUFFER_HANDLE ctrlPacket, const MQTT_C
int result = 0;
if (BUFFER_enlarge(ctrlPacket, CONNECT_VARIABLE_HEADER_SIZE) != 0)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
uint8_t* iterator = BUFFER_u_char(ctrlPacket);
if (iterator == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -253,18 +253,18 @@ static int constructPublishVariableHeader(BUFFER_HANDLE ctrlPacket, const PUBLIS
if (topicLen > USHRT_MAX)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else if (BUFFER_enlarge(ctrlPacket, topicLen + idLen + spaceLen) != 0)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
uint8_t* iterator = BUFFER_u_char(ctrlPacket);
if (iterator == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -294,14 +294,14 @@ static int constructSubscibeTypeVariableHeader(BUFFER_HANDLE ctrlPacket, uint16_
int result = 0;
if (BUFFER_enlarge(ctrlPacket, 2) != 0)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
uint8_t* iterator = BUFFER_u_char(ctrlPacket);
if (iterator == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -348,7 +348,7 @@ static int constructFixedHeader(BUFFER_HANDLE ctrlPacket, CONTROL_PACKET_TYPE pa
int result;
if (ctrlPacket == NULL)
{
return __FAILURE__;
return MU_FAILURE;
}
else
{
@ -372,12 +372,12 @@ static int constructFixedHeader(BUFFER_HANDLE ctrlPacket, CONTROL_PACKET_TYPE pa
BUFFER_HANDLE fixedHeader = BUFFER_new();
if (fixedHeader == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else if (BUFFER_pre_build(fixedHeader, index + 1) != 0)
{
BUFFER_delete(fixedHeader);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -398,7 +398,7 @@ static int constructConnPayload(BUFFER_HANDLE ctrlPacket, const MQTT_CLIENT_OPTI
int result = 0;
if (mqttOptions == NULL || ctrlPacket == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -441,19 +441,19 @@ static int constructConnPayload(BUFFER_HANDLE ctrlPacket, const MQTT_CLIENT_OPTI
// Validate the Username & Password
if (clientLen > USHRT_MAX)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else if (usernameLen == 0 && passwordLen > 0)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else if ((willMessageLen > 0 && willTopicLen == 0) || (willTopicLen > 0 && willMessageLen == 0))
{
result = __FAILURE__;
result = MU_FAILURE;
}
else if (BUFFER_enlarge(ctrlPacket, totalLen) != 0)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -466,7 +466,7 @@ static int constructConnPayload(BUFFER_HANDLE ctrlPacket, const MQTT_CLIENT_OPTI
// TODO: Read on the Will Topic
if (willMessageLen > USHRT_MAX || willTopicLen > USHRT_MAX || usernameLen > USHRT_MAX || passwordLen > USHRT_MAX)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -535,7 +535,7 @@ static int prepareheaderDataInfo(MQTTCODEC_INSTANCE* codecData, uint8_t remainLe
int result;
if (codecData == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -555,7 +555,7 @@ static int prepareheaderDataInfo(MQTTCODEC_INSTANCE* codecData, uint8_t remainLe
if (multiplier > 128 * 128 * 128)
{
result = __FAILURE__;
result = MU_FAILURE;
break;
}
} while ((encodeByte & NEXT_128_CHUNK) != 0);
@ -574,7 +574,7 @@ static int prepareheaderDataInfo(MQTTCODEC_INSTANCE* codecData, uint8_t remainLe
{
/* Codes_SRS_MQTT_CODEC_07_035: [ If any error is encountered then the packet state will be marked as error and mqtt_codec_bytesReceived shall return a non-zero value. ] */
LogError("Failed BUFFER_new");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -582,7 +582,7 @@ static int prepareheaderDataInfo(MQTTCODEC_INSTANCE* codecData, uint8_t remainLe
{
/* Codes_SRS_MQTT_CODEC_07_035: [ If any error is encountered then the packet state will be marked as error and mqtt_codec_bytesReceived shall return a non-zero value. ] */
LogError("Failed BUFFER_pre_build");
result = __FAILURE__;
result = MU_FAILURE;
}
}
@ -1054,14 +1054,14 @@ int mqtt_codec_bytesReceived(MQTTCODEC_HANDLE handle, const unsigned char* buffe
/* Codes_SRS_MQTT_CODEC_07_031: [If the parameters handle or buffer is NULL then mqtt_codec_bytesReceived shall return a non-zero value.] */
if (codec_Data == NULL)
{
result = __FAILURE__;
result = MU_FAILURE;
}
/* Codes_SRS_MQTT_CODEC_07_031: [If the parameters handle or buffer is NULL then mqtt_codec_bytesReceived shall return a non-zero value.] */
/* Codes_SRS_MQTT_CODEC_07_032: [If the parameters size is zero then mqtt_codec_bytesReceived shall return a non-zero value.] */
else if (buffer == NULL || size == 0)
{
codec_Data->currPacket = PACKET_TYPE_ERROR;
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1083,7 +1083,7 @@ int mqtt_codec_bytesReceived(MQTTCODEC_HANDLE handle, const unsigned char* buffe
{
/* Codes_SRS_MQTT_CODEC_07_035: [If any error is encountered then the packet state will be marked as error and mqtt_codec_bytesReceived shall return a non-zero value.] */
codec_Data->currPacket = PACKET_TYPE_ERROR;
result = __FAILURE__;
result = MU_FAILURE;
}
if (codec_Data->currPacket == PINGRESP_TYPE)
{
@ -1105,7 +1105,7 @@ int mqtt_codec_bytesReceived(MQTTCODEC_HANDLE handle, const unsigned char* buffe
{
/* Codes_SRS_MQTT_CODEC_07_035: [If any error is encountered then the packet state will be marked as error and mqtt_codec_bytesReceived shall return a non-zero value.] */
codec_Data->currPacket = PACKET_TYPE_ERROR;
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -1126,7 +1126,7 @@ int mqtt_codec_bytesReceived(MQTTCODEC_HANDLE handle, const unsigned char* buffe
{
/* Codes_SRS_MQTT_CODEC_07_035: [If any error is encountered then the packet state will be marked as error and mqtt_codec_bytesReceived shall return a non-zero value.] */
codec_Data->currPacket = PACKET_TYPE_ERROR;
result = __FAILURE__;
result = MU_FAILURE;
}
}
}

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

@ -7,6 +7,7 @@
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/xlogging.h"
#include "azure_c_shared_utility/string_token.h"
#include "azure_c_shared_utility/macro_utils.h"
typedef struct MQTT_MESSAGE_TAG
{
@ -221,7 +222,7 @@ int mqttmessage_getTopicLevels(MQTT_MESSAGE_HANDLE handle, char*** levels, size_
if (handle == NULL || levels == NULL || count == NULL)
{
LogError("Invalid Parameter handle: %p, levels: %p, count: %p", handle, levels, count);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -232,7 +233,7 @@ int mqttmessage_getTopicLevels(MQTT_MESSAGE_HANDLE handle, char*** levels, size_
if (topic_name == NULL)
{
LogError("Topic name is NULL");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -246,7 +247,7 @@ int mqttmessage_getTopicLevels(MQTT_MESSAGE_HANDLE handle, char*** levels, size_
{
// Codes_SRS_MQTTMESSAGE_09_003: [ If splitting fails the function shall return a non-zero value. ]
LogError("Failed splitting topic levels");
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -317,7 +318,7 @@ int mqttmessage_setIsDuplicateMsg(MQTT_MESSAGE_HANDLE handle, bool duplicateMsg)
if (handle == NULL)
{
LogError("Invalid Parameter handle: %p.", handle);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{
@ -335,7 +336,7 @@ int mqttmessage_setIsRetained(MQTT_MESSAGE_HANDLE handle, bool retainMsg)
if (handle == NULL)
{
LogError("Invalid Parameter handle: %p.", handle);
result = __FAILURE__;
result = MU_FAILURE;
}
else
{

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

@ -248,18 +248,15 @@ extern "C" {
return 0;
}
#ifdef __cplusplus
}
#endif
DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
{
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);
ASSERT_FAIL("umock_c reported error :%s", MU_ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code));
}
BEGIN_TEST_SUITE(mqtt_client_ut)
@ -309,12 +306,12 @@ TEST_SUITE_INITIALIZE(suite_init)
REGISTER_GLOBAL_MOCK_RETURN(mqtt_codec_create, NULL);
REGISTER_GLOBAL_MOCK_HOOK(xio_open, my_xio_open);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(xio_open, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(xio_open, MU_FAILURE);
REGISTER_GLOBAL_MOCK_HOOK(xio_send, my_xio_send);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(xio_send, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(xio_send, MU_FAILURE);
REGISTER_GLOBAL_MOCK_HOOK(tickcounter_get_current_ms, my_tickcounter_get_current_ms);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(tickcounter_get_current_ms, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(tickcounter_get_current_ms, MU_FAILURE);
REGISTER_GLOBAL_MOCK_HOOK(mqtt_codec_publishRelease, my_mqtt_codec_publishRelease);
REGISTER_GLOBAL_MOCK_HOOK(mqtt_codec_publishComplete, my_mqtt_codec_publishComplete);
@ -337,12 +334,12 @@ TEST_SUITE_INITIALIZE(suite_init)
REGISTER_GLOBAL_MOCK_RETURN(mqtt_codec_publishReceived, TEST_BUFFER_HANDLE);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mqtt_codec_publishReceived, NULL);
REGISTER_GLOBAL_MOCK_RETURN(mqtt_codec_bytesReceived, 0);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mqtt_codec_bytesReceived, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mqtt_codec_bytesReceived, MU_FAILURE);
REGISTER_GLOBAL_MOCK_RETURN(xio_close, 0);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(xio_close, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(xio_close, MU_FAILURE);
REGISTER_GLOBAL_MOCK_RETURN(platform_init, 0);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(platform_init, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(platform_init, MU_FAILURE);
REGISTER_GLOBAL_MOCK_RETURN(tickcounter_create, TEST_COUNTER_HANDLE);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(tickcounter_create, NULL);
@ -362,14 +359,14 @@ TEST_SUITE_INITIALIZE(suite_init)
REGISTER_GLOBAL_MOCK_RETURN(mqttmessage_getIsDuplicateMsg, true);
REGISTER_GLOBAL_MOCK_RETURN(mqttmessage_getIsRetained, true);
REGISTER_GLOBAL_MOCK_RETURN(mqttmessage_setIsDuplicateMsg, 0);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mqttmessage_setIsDuplicateMsg, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mqttmessage_setIsDuplicateMsg, MU_FAILURE);
REGISTER_GLOBAL_MOCK_RETURN(mqttmessage_setIsRetained, 0);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mqttmessage_setIsRetained, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mqttmessage_setIsRetained, MU_FAILURE);
REGISTER_GLOBAL_MOCK_RETURN(mqttmessage_getApplicationMsg, &TEST_APP_PAYLOAD);
REGISTER_GLOBAL_MOCK_HOOK(mqttmessage_destroy, my_mqttmessage_destroy);
REGISTER_GLOBAL_MOCK_RETURN(mallocAndStrcpy_s, 0);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mallocAndStrcpy_s, __FAILURE__);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mallocAndStrcpy_s, MU_FAILURE);
}
TEST_SUITE_CLEANUP(suite_cleanup)
@ -414,7 +411,7 @@ static int should_skip_index(size_t current_index, const size_t skip_array[], si
{
if (current_index == skip_array[index])
{
result = __FAILURE__;
result = MU_FAILURE;
break;
}
}
@ -516,58 +513,31 @@ static void setup_mqtt_client_connect_mocks(MQTT_CLIENT_OPTIONS* mqttOptions)
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, mqttOptions->password));
}
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreArgument(2)
.IgnoreArgument(3)
.IgnoreArgument_on_bytes_received_context()
.IgnoreArgument_on_io_error_context()
.IgnoreArgument(4)
.IgnoreArgument(6);
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
EXPECTED_CALL(mqtt_codec_connect(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
STRICT_EXPECTED_CALL(BUFFER_length(TEST_BUFFER_HANDLE));
STRICT_EXPECTED_CALL(BUFFER_u_char(TEST_BUFFER_HANDLE));
STRICT_EXPECTED_CALL(tickcounter_get_current_ms(TEST_COUNTER_HANDLE, IGNORED_PTR_ARG))
.IgnoreArgument_current_ms();
STRICT_EXPECTED_CALL(tickcounter_get_current_ms(TEST_COUNTER_HANDLE, IGNORED_PTR_ARG));
EXPECTED_CALL(xio_send(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
STRICT_EXPECTED_CALL(BUFFER_delete(TEST_BUFFER_HANDLE));
}
static void setup_mqtt_client_connect_retry_mocks(MQTT_CLIENT_OPTIONS* mqttOptions)
{
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_CLIENT_ID))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_WILL_MSG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_USERNAME))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_PASSWORD))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_CLIENT_ID));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_WILL_MSG));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_USERNAME));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_PASSWORD));
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreArgument(2)
.IgnoreArgument(3)
.IgnoreArgument_on_bytes_received_context()
.IgnoreArgument_on_io_error_context()
.IgnoreArgument(4)
.IgnoreArgument(6)
.SetReturn(__FAILURE__);
.SetReturn(MU_FAILURE);
setup_mqtt_clear_options_mocks(mqttOptions);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_CLIENT_ID))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_WILL_MSG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_USERNAME))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_PASSWORD))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreArgument(2)
.IgnoreArgument(3)
.IgnoreArgument_on_bytes_received_context()
.IgnoreArgument_on_io_error_context()
.IgnoreArgument(4)
.IgnoreArgument(6);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_CLIENT_ID));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_WILL_MSG));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_USERNAME));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_PASSWORD));
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
}
static void TestRecvCallback(MQTT_MESSAGE_HANDLE msgHandle, void* context)
@ -764,14 +734,11 @@ TEST_FUNCTION(mqtt_client_init_fail)
umock_c_negative_tests_reset();
umock_c_negative_tests_fail_call(index);
char tmp_msg[128];
sprintf(tmp_msg, "IoTHubClient_LL_SendReportedState failure in test %zu/%zu", index, count);
// act
MQTT_CLIENT_HANDLE result = mqtt_client_init(TestRecvCallback, TestOpCallback, NULL, TestErrorCallback, NULL);
// assert
ASSERT_IS_NULL(result);
ASSERT_IS_NULL(result, "IoTHubClient_LL_SendReportedState failure in test %zu/%zu", index, count);
}
// cleanup
@ -894,23 +861,12 @@ TEST_FUNCTION(mqtt_client_connect_fails)
SetupMqttLibOptions(&mqttOptions, TEST_CLIENT_ID, TEST_WILL_MSG, TEST_WILL_TOPIC, TEST_USERNAME, TEST_PASSWORD, TEST_KEEP_ALIVE_INTERVAL, false, true, DELIVER_AT_MOST_ONCE);
umock_c_reset_all_calls();
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_CLIENT_ID))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_WILL_TOPIC))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_WILL_MSG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_USERNAME))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_PASSWORD))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreArgument(2)
.IgnoreArgument(3)
.IgnoreArgument_on_bytes_received_context()
.IgnoreArgument_on_io_error_context()
.IgnoreArgument(4)
.IgnoreArgument(6);
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_CLIENT_ID));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_WILL_TOPIC));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_WILL_MSG));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_USERNAME));
STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_PASSWORD));
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
umock_c_negative_tests_snapshot();
@ -921,9 +877,6 @@ TEST_FUNCTION(mqtt_client_connect_fails)
umock_c_negative_tests_reset();
umock_c_negative_tests_fail_call(index);
char tmp_msg[64];
sprintf(tmp_msg, "mqtt_client_connect failure in test %zu/%zu", index, count);
int result = mqtt_client_connect(mqttHandle, TEST_IO_HANDLE, &mqttOptions);
if (result == 0)
{
@ -931,7 +884,7 @@ TEST_FUNCTION(mqtt_client_connect_fails)
}
// assert
ASSERT_ARE_NOT_EQUAL(int, 0, result, tmp_msg);
ASSERT_ARE_NOT_EQUAL(int, 0, result, "mqtt_client_connect failure in test %zu/%zu", index, count);
}
// cleanup
@ -1059,7 +1012,7 @@ TEST_FUNCTION(mqtt_client_on_bytes_received_bytesReceived_fail_succeeds)
umock_c_reset_all_calls();
EXPECTED_CALL(mqtt_codec_bytesReceived(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG))
.SetReturn(__FAILURE__);
.SetReturn(MU_FAILURE);
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
for (size_t index = 0; index < MAX_CLOSE_RETRIES; index++)
@ -1089,9 +1042,7 @@ TEST_FUNCTION(mqtt_client_connect_multiple_completes_one_connect_succeeds)
SetupMqttLibOptions(&mqttOptions, TEST_CLIENT_ID, TEST_WILL_MSG, NULL, TEST_USERNAME, TEST_PASSWORD, TEST_KEEP_ALIVE_INTERVAL, false, true, DELIVER_AT_MOST_ONCE);
setup_mqtt_client_connect_mocks(&mqttOptions);
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreArgument_on_io_close_complete()
.IgnoreArgument_callback_context();
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
STRICT_EXPECTED_CALL(xio_dowork(IGNORED_PTR_ARG));
STRICT_EXPECTED_CALL(ThreadAPI_Sleep(CLOSE_SLEEP_VALUE));
@ -1303,13 +1254,10 @@ TEST_FUNCTION(mqtt_client_subscribe_fails)
umock_c_negative_tests_reset();
umock_c_negative_tests_fail_call(index);
char tmp_msg[64];
sprintf(tmp_msg, "mqtt_client_subscribe failure in test %zu/%zu", index, count);
int result = mqtt_client_subscribe(mqttHandle, TEST_PACKET_ID, TEST_SUBSCRIBE_PAYLOAD, 2);
// assert
ASSERT_ARE_NOT_EQUAL(int, 0, result, tmp_msg);
ASSERT_ARE_NOT_EQUAL(int, 0, result, "mqtt_client_subscribe failure in test %zu/%zu", index, count);
}
// cleanup
@ -1442,13 +1390,10 @@ TEST_FUNCTION(mqtt_client_unsubscribe_fail)
umock_c_negative_tests_reset();
umock_c_negative_tests_fail_call(index);
char tmp_msg[64];
sprintf(tmp_msg, "mqtt_client_unsubscribe failure in test %zu/%zu", index, count);
int result = mqtt_client_unsubscribe(mqttHandle, TEST_PACKET_ID, TEST_UNSUBSCRIPTION_TOPIC, 2);
// assert
ASSERT_ARE_NOT_EQUAL(int, 0, result, tmp_msg);
ASSERT_ARE_NOT_EQUAL(int, 0, result, "mqtt_client_unsubscribe failure in test %zu/%zu", index, count);
}
// cleanup
@ -1551,7 +1496,7 @@ TEST_FUNCTION(mqtt_client_publish_xio_send_fails)
STRICT_EXPECTED_CALL(BUFFER_length(TEST_BUFFER_HANDLE));
STRICT_EXPECTED_CALL(BUFFER_u_char(TEST_BUFFER_HANDLE));
STRICT_EXPECTED_CALL(tickcounter_get_current_ms(TEST_COUNTER_HANDLE, IGNORED_PTR_ARG)).IgnoreArgument(2);
EXPECTED_CALL(xio_send(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(xio_send(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)).SetReturn(MU_FAILURE);
STRICT_EXPECTED_CALL(BUFFER_delete(TEST_BUFFER_HANDLE));
// act
@ -1578,7 +1523,6 @@ TEST_FUNCTION(mqtt_client_publish_succeeds)
STRICT_EXPECTED_CALL(mqttmessage_getPacketId(TEST_MESSAGE_HANDLE));
STRICT_EXPECTED_CALL(mqttmessage_getTopicName(TEST_MESSAGE_HANDLE));
EXPECTED_CALL(mqtt_codec_publish(DELIVER_AT_MOST_ONCE, true, true, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG));
STRICT_EXPECTED_CALL(BUFFER_length(TEST_BUFFER_HANDLE));
STRICT_EXPECTED_CALL(BUFFER_u_char(TEST_BUFFER_HANDLE));
@ -1639,13 +1583,10 @@ TEST_FUNCTION(mqtt_client_disconnect_fail)
umock_c_negative_tests_reset();
umock_c_negative_tests_fail_call(index);
char tmp_msg[64];
sprintf(tmp_msg, "mqtt_client_disconnect failure in test %zu/%zu", index, count);
int result = mqtt_client_disconnect(mqttHandle, NULL, NULL);
// assert
ASSERT_ARE_NOT_EQUAL(int, 0, result, tmp_msg);
ASSERT_ARE_NOT_EQUAL(int, 0, result, "mqtt_client_disconnect failure in test %zu/%zu", index, count);
}
// cleanup
@ -1941,7 +1882,7 @@ TEST_FUNCTION(mqtt_client_dowork_tickcounter_fails_succeeds)
umock_c_reset_all_calls();
EXPECTED_CALL(xio_dowork(IGNORED_PTR_ARG));
STRICT_EXPECTED_CALL(tickcounter_get_current_ms(TEST_COUNTER_HANDLE, IGNORED_PTR_ARG)).IgnoreArgument(2).SetReturn(__FAILURE__);
STRICT_EXPECTED_CALL(tickcounter_get_current_ms(TEST_COUNTER_HANDLE, IGNORED_PTR_ARG)).IgnoreArgument(2).SetReturn(MU_FAILURE);
// act
mqtt_client_dowork(mqttHandle);
@ -2230,12 +2171,10 @@ TEST_FUNCTION(mqtt_client_recvCompleteCallback_PUBLISH_EXACTLY_ONCE_fail)
umock_c_negative_tests_reset();
umock_c_negative_tests_fail_call(index);
char tmp_msg[64];
sprintf(tmp_msg, "IoTHubClient_LL_Create failure in test %zu/%zu", index, count);
g_packetComplete(mqttHandle, PUBLISH_TYPE, flag, publish_handle);
if (index == 2 || index == 3 || index == 4 || index == 5 || index == 6)
ASSERT_IS_TRUE(g_errorCallbackInvoked);
ASSERT_IS_TRUE(g_errorCallbackInvoked, "IoTHubClient_LL_Create failure in test %zu/%zu", index, count);
}
// cleanup

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

@ -164,13 +164,11 @@ extern size_t real_BUFFER_length(BUFFER_HANDLE handle);
TEST_MUTEX_HANDLE test_serialize_mutex;
DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
{
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);
ASSERT_FAIL("umock_c reported error :%s", MU_ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code));
}
BEGIN_TEST_SUITE(mqtt_codec_ut)
@ -319,7 +317,7 @@ TEST_FUNCTION(mqtt_codec_connect_BUFFER_enlarge_fail)
SetupMqttLibOptions(&mqttOptions, TEST_CLIENT_ID, NULL, NULL, "testuser", "testpassword", 20, false, true, DELIVER_AT_MOST_ONCE);
STRICT_EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -336,7 +334,7 @@ TEST_FUNCTION(mqtt_codec_connect_WillMsg_zero_WillTopic_nonzero_fail)
SetupMqttLibOptions(&mqttOptions, TEST_CLIENT_ID, TEST_WILL_MSG, NULL, "testuser", "testpassword", 20, false, true, DELIVER_AT_MOST_ONCE);
STRICT_EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -538,7 +536,7 @@ TEST_FUNCTION(mqtt_codec_disconnect_BUFFER_enlarge_fails)
{
// arrange
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -554,7 +552,7 @@ TEST_FUNCTION(mqtt_codec_ping_BUFFER_enlarge_fails)
{
// arrange
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -609,7 +607,7 @@ TEST_FUNCTION(mqtt_codec_publish_construct_BUFFER_enlarge_fail)
// arrange
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_length(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -629,7 +627,7 @@ TEST_FUNCTION(mqtt_codec_publish_BUFFER_enlarge_fails)
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_length(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -655,7 +653,7 @@ TEST_FUNCTION(mqtt_codec_publish_constructFixedHeader_fails)
EXPECTED_CALL(BUFFER_length(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
@ -828,7 +826,7 @@ TEST_FUNCTION(mqtt_codec_publish_ack_pre_build_fail)
EXPECTED_CALL(BUFFER_new());
STRICT_EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, 4))
.IgnoreArgument(1)
.SetReturn(__FAILURE__);
.SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -889,7 +887,7 @@ TEST_FUNCTION(mqtt_codec_publish_received_pre_build_fail)
STRICT_EXPECTED_CALL(BUFFER_new());
STRICT_EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, 4))
.IgnoreArgument(1)
.SetReturn(__FAILURE__);
.SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -934,7 +932,7 @@ TEST_FUNCTION(mqtt_codec_publish_release_pre_build_fail)
EXPECTED_CALL(BUFFER_new());
STRICT_EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, 4))
.IgnoreArgument(1)
.SetReturn(__FAILURE__);
.SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -979,7 +977,7 @@ TEST_FUNCTION(mqtt_codec_publish_complete_pre_build_fail)
EXPECTED_CALL(BUFFER_new());
STRICT_EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, 4))
.IgnoreArgument(1)
.SetReturn(__FAILURE__);
.SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -1035,7 +1033,7 @@ TEST_FUNCTION(mqtt_codec_subscribe_BUFFER_enlarge_fails)
{
// arrange
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -1051,7 +1049,7 @@ TEST_FUNCTION(mqtt_codec_subscribe_addListItemsToSubscribePacket_fails)
{
// arrange
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -1078,7 +1076,7 @@ TEST_FUNCTION(mqtt_codec_subscribe_constructFixedHeader_fails)
EXPECTED_CALL(BUFFER_length(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
@ -1191,7 +1189,7 @@ TEST_FUNCTION(mqtt_codec_unsubscribe_BUFFER_enlarge_fails)
{
// arrange
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -1210,7 +1208,7 @@ TEST_FUNCTION(mqtt_codec_unsubscribe_addListItemToUnsubscribePacket_BUFFER_enlar
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_length(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_enlarge(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
// act
@ -1237,7 +1235,7 @@ TEST_FUNCTION(mqtt_codec_unsubscribe_constructFixedHeader_fails)
EXPECTED_CALL(BUFFER_length(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(__FAILURE__);
EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, IGNORED_NUM_ARG)).SetReturn(MU_FAILURE);
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG));
@ -1398,7 +1396,7 @@ TEST_FUNCTION(mqtt_codec_bytesReceived_buffer_BUFFER_pre_build_fails)
umock_c_reset_all_calls();
EXPECTED_CALL(BUFFER_new());
EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, IGNORED_NUM_ARG).SetReturn(__FAILURE__));
EXPECTED_CALL(BUFFER_pre_build(IGNORED_PTR_ARG, IGNORED_NUM_ARG).SetReturn(MU_FAILURE));
// act
result = mqtt_codec_bytesReceived(handle, UNSUBACK_RESP, length);

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

@ -91,13 +91,11 @@ IMPLEMENT_UMOCK_C_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES);
TEST_MUTEX_HANDLE test_serialize_mutex;
DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
{
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);
ASSERT_FAIL("umock_c reported error :%s", MU_ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code));
}
BEGIN_TEST_SUITE(mqtt_message_ut)
@ -133,7 +131,6 @@ TEST_SUITE_INITIALIZE(suite_init)
REGISTER_GLOBAL_MOCK_FAIL_RETURN(StringToken_Split, 1);
REGISTER_GLOBAL_MOCK_RETURN(mallocAndStrcpy_s, 0);
REGISTER_GLOBAL_MOCK_FAIL_RETURN(mallocAndStrcpy_s, 1);
}
TEST_SUITE_CLEANUP(suite_cleanup)
@ -664,7 +661,6 @@ TEST_FUNCTION(mqttmessage_getTopicLevels_negative_tests)
for (i = 0; i < umock_c_negative_tests_call_count(); i++)
{
// arrange
char error_msg[64];
int result;
umock_c_negative_tests_reset();
@ -674,8 +670,7 @@ TEST_FUNCTION(mqttmessage_getTopicLevels_negative_tests)
result = mqttmessage_getTopicLevels(handle, &levels, &count);
// assert
sprintf(error_msg, "On failed call %zu", i);
ASSERT_ARE_NOT_EQUAL(int, 0, result, error_msg);
ASSERT_ARE_NOT_EQUAL(int, 0, result, "On failed call %zu", i);
}
// cleanup