-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
Hi,
I working latest device updates sdk code and developed some own unit test for own customized part of code.
Unit test is acting for function which send message to cloud , so it has dependencies to another which is from azure-c-sdk.
To avoid error , i am using umock functionality and mocking dependencies using STRICT_CALL.
But getting error of umock.
Please help me out.
code :
#include "umock_c/umock_c.h"
#include <catch2/catch.hpp>
using Catch::Matchers::Equals;
#include <sstream>
#include <string>
#include "aduc/c_utils.h"
#include "aduc/logging.h"
#define ENABLE_MOCKS
#include "azureiot/iothub_message.h"
#undef ENABLE_MOCKS
TEST_CASE("Test_Case-4: IotClient_SendMessageAsyn Test"){
ADUC_Logging_Init(ADUC_LOG_DEBUG, "du-agent");
// umock_c_reset_all_calls();
REGISTER_UMOCK_ALIAS_TYPE(IOTHUB_MESSAGE_HANDLE, void*);
SECTION("Validate Client-handle as null ,Fail")
{
bool result = IotClient_SendMessageAsyn((char *)"Hi", NULL, (char *)"test");
CHECK (result == 0);
}
SECTION("Input are Valid and communication fail,Fail")
{
bool result = IotClient_SendMessageAsyn((char *)"{\"test\":\"Hi\"}", (IOTHUB_DEVICE_CLIENT_LL_HANDLE)1234, (char *)"test");
CHECK (result == 0);
}
SECTION("Payload Json Invalid ,Fail")
{
bool result = IotClient_SendMessageAsyn(NULL, (IOTHUB_DEVICE_CLIENT_LL_HANDLE)1234,(char *)"test");
CHECK (result == 0);
}
SECTION("Payload fail to convert utf-8,Fail")
{
STRICT_EXPECTED_CALL(IoTHubMessage_SetContentEncodingSystemProperty(0,0))
.SetReturn(IOTHUB_MESSAGE_INVALID_ARG)
.IgnoreAllArguments();
bool result = IotClient_SendMessageAsyn((char *)"!@#$", (IOTHUB_DEVICE_CLIENT_LL_HANDLE)123, (char *)"test");
CHECK (result == 0);
}
}
Error while building
-- target architecture: x86_64
-- target architecture: x86_64
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vetscan/accenture/dev_gc/test/adu-service/out
[1/2] Building CXX object src/agent/custom_iot_service/tests/CMakeFiles/custom_iot_service_unit_tests.dir/common_iotclient_communincation_ut.cpp.o
FAILED: src/agent/custom_iot_service/tests/CMakeFiles/custom_iot_service_unit_tests.dir/common_iotclient_communincation_ut.cpp.o
/usr/bin/c++ -DADUC_DOWNLOADS_FOLDER=\"/var/lib/adu/downloads\" -DADUC_INSTALLEDCRITERIA_FILE_PATH=\"/tmp/adu-test-installedcriteria\" -DADUC_LOG_FOLDER=\"/var/log/adu\" -DADUC_USE_ZLOGGING=1 -DADUC_VERSION=\"0.8.1\" -DARCHITECTURE_x86_64=1 -DAUTH_TYPE_0x509 -DAUTH_TYPE_SYM -DAUTH_TYPE_TPM -DFILE_UPLOAD_ENABLE=\"true\" -DTELEMETRY_ENABLE=\"true\" -I/usr/local/inc -I/usr/local/pal/linux -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I../src/agent/custom_iot_service/tests/inc -I../src/agent/custom_iot_service/tests/../../inc -I../src/agent/custom_iot_service/tests/../inc -I../src/agent/hsm_interface/inc -I../src/utils/c_utils/inc -I../src/logging/inc -I../src/logging/zlog/inc -I../src/agent/pnp_helper/inc -I../src/agent/adu_core_interface/inc -I../src/inc -I../src/adu_types/inc -I../src/adu_workflow/inc -I../src/communication_abstraction/inc -I../src/extensions/extension_manager/inc -I../src/extensions/inc -I../src/utils/extension_utils/inc -I../src/utils/hash_utils/inc -I../src/utils/parser_utils/inc -I../src/utils/parson_json_utils/inc -I../src/utils/system_utils/inc -I../src/utils/workflow_utils/inc -I../src/utils/crypto_utils/inc -isystem /usr/local/include/azureiot -Werror -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wformat -Werror=format-security -fno-rtti -Wall -Wextra -Wno-missing-braces -Wno-missing-field-initializers -Wno-unused-function -Wno-unused-parameter -Wno-ignored-qualifiers -g -std=gnu++11 -MD -MT src/agent/custom_iot_service/tests/CMakeFiles/custom_iot_service_unit_tests.dir/common_iotclient_communincation_ut.cpp.o -MF src/agent/custom_iot_service/tests/CMakeFiles/custom_iot_service_unit_tests.dir/common_iotclient_communincation_ut.cpp.o.d -o src/agent/custom_iot_service/tests/CMakeFiles/custom_iot_service_unit_tests.dir/common_iotclient_communincation_ut.cpp.o -c ../src/agent/custom_iot_service/tests/common_iotclient_communincation_ut.cpp
../src/agent/custom_iot_service/tests/common_iotclient_communincation_ut.cpp:21: error: "__cplusplus" redefined [-Werror]
21 | #define __cplusplus
|
<built-in>: note: this is the location of the previous definition
In file included from /usr/local/include/umock_c/umock_c.h:13,
from ../src/agent/custom_iot_service/tests/common_iotclient_communincation_ut.cpp:1:
../src/agent/custom_iot_service/tests/common_iotclient_communincation_ut.cpp: In function ‘void ____C_A_T_C_H____T_E_S_T____0()’:
../src/agent/custom_iot_service/tests/common_iotclient_communincation_ut.cpp:154:9: error: ‘get_auto_ignore_args_function_IoTHubMessage_SetContentEncodingSystemProperty’ was not declared in this scope
154 | STRICT_EXPECTED_CALL(IoTHubMessage_SetContentEncodingSystemProperty(0,0))
| ^~~~~~~~~~~~~~~~~~~~
../src/agent/custom_iot_service/tests/common_iotclient_communincation_ut.cpp:154:9: error: ‘umock_c_strict_expected_IoTHubMessage_SetContentEncodingSystemProperty’ was not declared in this scope; did you mean ‘IoTHubMessage_SetContentEncodingSystemProperty’?
154 | STRICT_EXPECTED_CALL(IoTHubMessage_SetContentEncodingSystemProperty(0,0))
| ^~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
ninja: build stopped: subcommand failed.
Metadata
Metadata
Assignees
Labels
No labels