From 75aae52a128f3493546fbd08038f900cbddd19a6 Mon Sep 17 00:00:00 2001 From: suvi-123 Date: Thu, 14 Dec 2023 08:00:38 +0530 Subject: [PATCH] Fix test failure --- tests/CMakeLists.txt | 12 ++--- tests/test_webpa_notification.c | 90 +++++++++++++++++++++------------ 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ecf33bc0..b6348b84 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,12 +50,12 @@ target_link_libraries (test_libpd gcov -Wl,--no-as-needed ) # add_executable(test_webpa_set test_webpa_set.c mock_stack.c mock_cache.c ../source/app/libpd.c ${WEBPA_COMMON_SOURCES} ${WEBPA_TABLE_SOURCES}) # target_link_libraries (test_webpa_set -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS} -llibparodus) -# #------------------------------------------------------------------------------- -# # test_webpa_notification -# #------------------------------------------------------------------------------- -# add_test(NAME test_webpa_notification COMMAND ${MEMORY_CHECK} ./test_webpa_notification) -# add_executable(test_webpa_notification test_webpa_notification.c mock_stack.c mock_cache.c ../source/app/libpd.c ${WEBPA_COMMON_SOURCES} ${WEBPA_TABLE_SOURCES}) -# target_link_libraries (test_webpa_notification -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS} -llibparodus) + #------------------------------------------------------------------------------- + # test_webpa_notification + #------------------------------------------------------------------------------- + add_test(NAME test_webpa_notification COMMAND ${MEMORY_CHECK} ./test_webpa_notification) + add_executable(test_webpa_notification test_webpa_notification.c mock_stack.c mock_cache.c ../source/app/libpd.c ${WEBPA_COMMON_SOURCES} ${WEBPA_TABLE_SOURCES}) + target_link_libraries (test_webpa_notification -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS} -llibparodus) # #------------------------------------------------------------------------------- # # test_webpa_get_attributes diff --git a/tests/test_webpa_notification.c b/tests/test_webpa_notification.c index 58e9428f..673681a2 100644 --- a/tests/test_webpa_notification.c +++ b/tests/test_webpa_notification.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "../source/include/webpa_adapter.h" #include "../source/broadband/include/webpa_internal.h" @@ -60,6 +61,20 @@ extern char* cloud_status; /*----------------------------------------------------------------------------*/ /* Mocks */ /*----------------------------------------------------------------------------*/ +void clearTraceContext() +{ +} + +rbusError_t getTraceContext(char* traceContext[]) +{ + UNUSED(traceContext); +} + +rbusError_t setTraceContext(char* traceContext[]) +{ + UNUSED(traceContext); +} + int libparodus_send (libpd_instance_t instance, wrp_msg_t *msg) { UNUSED(instance); @@ -185,6 +200,12 @@ void test_factory_reset_notification() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_values, cmcList1); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_components, getDeviceInfoCompDetails()); will_return(get_global_component_size, 1); expect_function_call(CcspBaseIf_discComponentSupportingNamespace); @@ -197,12 +218,6 @@ void test_factory_reset_notification() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(get_global_values, cmcList1); - will_return(get_global_parameters_count, 1); - expect_function_call(CcspBaseIf_getParameterValues); - will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); - expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(get_global_values, cmcList2); will_return(get_global_parameters_count, 1); expect_function_call(CcspBaseIf_getParameterValues); @@ -290,6 +305,17 @@ void test_firmware_upgrade_notification() sendNotificationForFirmwareUpgrade(); } +void processFactoryResetNotification() +{ + NotifyData *notifyData = (NotifyData *) malloc(sizeof(NotifyData)); + notifyData->type= TRANS_STATUS; + notifyData->u.status= (TransData *)malloc(sizeof(TransData)); + notifyData->u.status->transId = strndup("qwkgfg75sgqwdgfhasfg", MAX_PARAMETER_LEN); + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + processNotification(notifyData); +} + void test_transaction_status_notification() { NotifyData *notifyData = (NotifyData *) malloc(sizeof(NotifyData)); @@ -363,6 +389,12 @@ void test_FR_cloud_sync_notification() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_values, cmcList); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_components, getDeviceInfoCompDetails()); will_return(get_global_component_size, 1); expect_function_call(CcspBaseIf_discComponentSupportingNamespace); @@ -375,12 +407,6 @@ void test_FR_cloud_sync_notification() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(get_global_values, cmcList); - will_return(get_global_parameters_count, 1); - expect_function_call(CcspBaseIf_getParameterValues); - will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); - expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(get_global_values, cmcList2); will_return(get_global_parameters_count, 1); expect_function_call(CcspBaseIf_getParameterValues); @@ -454,6 +480,12 @@ void test_FR_cloud_sync_notification_retry() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_values, oldCmcList); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_components, getDeviceInfoCompDetails()); will_return(get_global_component_size, 1); expect_function_call(CcspBaseIf_discComponentSupportingNamespace); @@ -466,12 +498,6 @@ void test_FR_cloud_sync_notification_retry() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(get_global_values, oldCmcList); - will_return(get_global_parameters_count, 1); - expect_function_call(CcspBaseIf_getParameterValues); - will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); - expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(libparodus_send, (intptr_t)0); expect_function_call(libparodus_send); @@ -553,6 +579,12 @@ void test_FR_notify_cloud_status_retry() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_values, cmcList); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_components, getDeviceInfoCompDetails()); will_return(get_global_component_size, 1); expect_function_call(CcspBaseIf_discComponentSupportingNamespace); @@ -565,12 +597,6 @@ void test_FR_notify_cloud_status_retry() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(get_global_values, cmcList); - will_return(get_global_parameters_count, 1); - expect_function_call(CcspBaseIf_getParameterValues); - will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); - expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(get_global_values, cmcList2); will_return(get_global_parameters_count, 1); expect_function_call(CcspBaseIf_getParameterValues); @@ -670,18 +696,18 @@ void test_factory_reset_notification_with_cmc_512() will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); - will_return(get_global_components, getDeviceInfoCompDetails()); - will_return(get_global_component_size, 1); - expect_function_call(CcspBaseIf_discComponentSupportingNamespace); - will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); - expect_function_call(free_componentStruct_t); - will_return(get_global_values, rebootReasonList); will_return(get_global_parameters_count, 1); expect_function_call(CcspBaseIf_getParameterValues); will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + will_return(get_global_values, cmcList1); will_return(get_global_parameters_count, 1); expect_function_call(CcspBaseIf_getParameterValues); @@ -749,14 +775,14 @@ int main(void) cmocka_unit_test(test_factory_reset_notification), cmocka_unit_test(test_FR_cloud_sync_notification), cmocka_unit_test(test_firmware_upgrade_notification), - cmocka_unit_test(err_loadCfgFile), + cmocka_unit_test(err_loadCfgFile), cmocka_unit_test(test_transaction_status_notification), cmocka_unit_test(test_FR_cloud_sync_notification_retry), cmocka_unit_test(test_FR_notify_cloud_status_retry), cmocka_unit_test(test_FR_notify_cloud_status_empty_mac), cmocka_unit_test(test_manageable_notification), cmocka_unit_test(err_manageable_notification), - cmocka_unit_test(test_factory_reset_notification_with_cmc_512), + cmocka_unit_test(test_factory_reset_notification_with_cmc_512), cmocka_unit_test(test_processNotification), };