diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bdb2ecc..4c481eec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,6 +210,20 @@ add_library(liblibparodus STATIC SHARED IMPORTED) add_dependencies(liblibparodus libparodus) endif (FEATURE_SUPPORT_AKER) +if (BUILD_TESTING) +# cmocka external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(cmocka + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cmocka + GIT_REPOSITORY https://github.com/elventear/cmocka.git + GIT_TAG "b71a3060699bc1a5b00e958be353772f42545ac2" + CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} +) +add_library(libcmocka STATIC SHARED IMPORTED) +add_dependencies(libcmocka cmocka) + +endif (BUILD_TESTING) + endif () link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} ) diff --git a/src/webcfg_multipart.h b/src/webcfg_multipart.h index 061ec496..a89d17ce 100644 --- a/src/webcfg_multipart.h +++ b/src/webcfg_multipart.h @@ -75,6 +75,7 @@ int get_global_eventFlag(void); void set_global_eventFlag(); void set_global_ETAG(char *etag); char *get_global_ETAG(void); +WEBCFG_STATUS processMsgpackSubdoc(char *transaction_id); #ifdef WAN_FAILOVER_SUPPORTED void set_global_interface(char * value); char * get_global_interface(void); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c494000e..7168b8cb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -260,7 +260,7 @@ target_link_libraries (test_webcfgdb gcov -Wl,--no-as-needed ) #------------------------------------------------------------------------------- add_test(NAME test_multipart_unittest COMMAND ${MEMORY_CHECK} ./test_multipart_unittest) -set(SOURCES test_multipart_unittest.c ../src/webcfg_param.c ../src/webcfg_multipart.c ../src/webcfg_helpers.c ../src/webcfg.c ../src/webcfg_auth.c ../src/webcfg_notify.c ../src/webcfg_db.c ../src/webcfg_pack.c ../src/webcfg_blob.c ../src/webcfg_event.c ../src/webcfg_generic_pc.c ../src/webcfg_metadata.c) +set(SOURCES test_multipart_unittest.c ../src/webcfg_param.c ../src/webcfg_multipart.c ../src/webcfg_helpers.c ../src/webcfg.c ../src/webcfg_auth.c ../src/webcfg_notify.c ../src/webcfg_db.c ../src/webcfg_pack.c ../src/webcfg_blob.c ../src/webcfg_event.c ../src/webcfg_generic_pc.c ../src/webcfg_metadata.c ../src/webcfg_timer.c) if (WEBCONFIG_BIN_SUPPORT) set(SOURCES ${SOURCES} ../src/webcfg_rbus.c) @@ -343,6 +343,44 @@ endif (WEBCONFIG_BIN_SUPPORT) target_link_libraries (test_generic_pc gcov -Wl,--no-as-needed ) +#------------------------------------------------------------------------------- +# test_blob +#------------------------------------------------------------------------------- +add_test(NAME test_blob COMMAND ${MEMORY_CHECK} ./test_blob) +add_executable(test_blob test_blob.c ../src/webcfg_blob.c) +target_link_libraries (test_blob -lcunit -lmsgpackc -lcimplog -lcjson -ltrower-base64 ) + +target_link_libraries (test_blob gcov -Wl,--no-as-needed ) + +#------------------------------------------------------------------------------- +# test_cmoka_multipart.c +#------------------------------------------------------------------------------- +add_test(NAME test_cmocka_multipart COMMAND ${MEMORY_CHECK} ./test_cmocka_multipart) + +set(SOURCES test_cmocka_multipart.c ../src/webcfg_param.c ../src/webcfg_multipart.c ../src/webcfg_helpers.c ../src/webcfg.c ../src/webcfg_auth.c ../src/webcfg_notify.c ../src/webcfg_db.c ../src/webcfg_pack.c ../src/webcfg_blob.c ../src/webcfg_event.c ../src/webcfg_generic_pc.c ../src/webcfg_metadata.c ../src/webcfg_timer.c) + +if (WEBCONFIG_BIN_SUPPORT) +set(SOURCES ${SOURCES} ../src/webcfg_rbus.c) +endif (WEBCONFIG_BIN_SUPPORT) + +if (FEATURE_SUPPORT_AKER) +set(SOURCES ${SOURCES} ../src/webcfg_client.c ../src/webcfg_aker.c) +endif (FEATURE_SUPPORT_AKER) + +add_executable(test_cmocka_multipart ${SOURCES}) + +target_link_libraries (test_cmocka_multipart -lcmocka -lcunit -lmsgpackc -lpthread -lm -luuid -ltrower-base64 -lwdmp-c -lcimplog -lcjson -lwrp-c -lcurl ) + +if (WEBCONFIG_BIN_SUPPORT) +target_link_libraries (test_cmocka_multipart -lrbus) +endif (WEBCONFIG_BIN_SUPPORT) + +if (FEATURE_SUPPORT_AKER) +target_link_libraries (test_cmoka_multipart -llibparodus -lnanomsg) +endif (FEATURE_SUPPORT_AKER) + +target_link_libraries (test_cmocka_multipart gcov -Wl,--no-as-needed ) + # Code coverage add_custom_target(coverage @@ -375,8 +413,11 @@ ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_timer.dir/__/src --output-file test_ COMMAND lcov -q --capture --directory ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_notify.dir/__/src --output-file test_notify.info COMMAND lcov -q --capture --directory -${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_generic.dir/__/src --output-file test_generic_pc.info - +${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_generic_pc.dir/__/src --output-file test_generic_pc.info +COMMAND lcov -q --capture --directory +${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_blob.dir/__/src --output-file test_blob.info +COMMAND lcov -q --capture --directory +${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_cmocka_multipart.dir/__/src --output-file test_cmocka_multipart.info COMMAND lcov -a test_events_supp.info @@ -394,6 +435,8 @@ COMMAND lcov -a test_timer.info -a test_notify.info -a test_generic_pc.info +-a test_blob.info +-a test_cmocka_multipart.info --output-file coverage.info COMMAND genhtml coverage.info diff --git a/tests/test_cmocka_multipart.c b/tests/test_cmocka_multipart.c new file mode 100644 index 00000000..92a85b9c --- /dev/null +++ b/tests/test_cmocka_multipart.c @@ -0,0 +1,286 @@ +/** + * Copyright 2019 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include +#include +#include +#include +#include +#include + +#include "../src/webcfg_log.h" +#include "../src/webcfg_param.h" +#include "../src/webcfg.h" +#include "../src/webcfg_multipart.h" +#include "../src/webcfg_helpers.h" +#include "../src/webcfg_db.h" +#include "../src/webcfg_notify.h" +#include "../src/webcfg_metadata.h" +#include "../src/webcfg_generic.h" +#include "../src/webcfg_event.h" +#include "../src/webcfg_auth.h" +#include "../src/webcfg_blob.h" +#include "../src/webcfg_timer.h" + +#define UNUSED(x) (void )(x) +int numLoops; + +typedef void CURL; + +#undef curl_easy_setopt +#undef curl_easy_getinfo + +/*long long getRetryExpiryTimeout() +{ + return 0; +} + +int get_retry_timer() +{ + return 0; +} + +int updateRetryTimeDiff(long long expiry_time) +{ + UNUSED(expiry_time); + return 0; +} + +int checkRetryTimer( long long timestamp) +{ + return timestamp; +} + +char* printTime(long long time) +{ + UNUSED(time); + return NULL; +} + +int checkMaintenanceTimer() +{ + return 0; +} + +void initMaintenanceTimer() +{ + return; +} + +int getMaintenanceSyncSeconds(int maintenance_count) +{ + UNUSED(maintenance_count); + return 0; +} + +long get_global_retry_timestamp() +{ + return 0; +} + +int retrySyncSeconds() +{ + return 0; +} + +void set_retry_timer(int value) +{ + UNUSED(value); + return; +} + +void set_global_retry_timestamp(long value) +{ + UNUSED(value); + return; +} + +void set_global_maintenance_time(long value) +{ + UNUSED(value); + return; +} +*/ + +int Get_Webconfig_URL(char *pString) +{ + // Set a non-empty value for configURL + strcpy(pString, "http://example.com/config.xml"); + return 0; // or whatever the expected return value is +} + +CURL *curl_easy_init () +{ + function_called(); + return (CURL *) mock(); +} + +CURLcode curl_easy_perform(CURL *curl) +{ + UNUSED(curl); + int rtn; + + function_called(); + rtn = (int) mock(); + return rtn; +} + +CURLcode curl_easy_setopt(CURL *easy, CURLoption option, ...) +{ + UNUSED (easy); + UNUSED (option); + return CURLE_OK; +} + +CURLcode curl_easy_getinfo(CURL *easy, CURLINFO info, ... ) +{ + UNUSED (easy); + UNUSED (info); + //int rtn; + + va_list args; + va_start(args, info); + + CURLcode result = CURLE_OK; + + function_called(); + result = (int) mock(); + + if (info == CURLINFO_RESPONSE_CODE) { + long* response_code = va_arg(args, long*); + *response_code = 200; // Always return 200 as the response code + } else if (info == CURLINFO_CONTENT_TYPE) { + char** ct = va_arg(args, char**); + *ct = "multipart/mixed"; // Set the content type as "multipart/mixed" + } + return result; +} + +void curl_easy_cleanup(CURL *easy) +{ + (void) easy; +} + +void test_webcfg_http_request_curl_init_fail() +{ + char *config = NULL; // Initialize with your data + int r_count = 1; // Set the number of retries as needed + int status = 0; // Set the status as needed + long code = 0; // Response code + char *transaction_id = NULL; // Transaction ID + char contentType[64] = {0}; // Content type + size_t dataSize = 0; // Data size + char docname[64] = "value"; // Document name + + will_return (curl_easy_init, NULL); + expect_function_calls (curl_easy_init, 1); + + WEBCFG_STATUS result = webcfg_http_request(&config, r_count, status, &code, &transaction_id, contentType, &dataSize, docname); + + WebcfgInfo("The result is %d", result); + assert_int_equal (result, 1); + +} + +//get_global_supplementarySync() == 0 +void test_webcfg_http_request_curl_init_success() +{ + char *config = NULL; // Initialize with your data + int r_count = 1; // Set the number of retries as needed + int status = 0; // Set the status as needed + long code = 0; // Response code + char *transaction_id = NULL; // Transaction ID + char contentType[64] = {0}; // Content type + size_t dataSize = 0; // Data size + char docname[64] = {0}; // Document name + + set_global_supplementarySync(0); + + will_return (curl_easy_init, 1); + expect_function_calls (curl_easy_init, 1); + + will_return (curl_easy_perform, 0); + expect_function_calls (curl_easy_perform, 1); + + will_return (curl_easy_getinfo, 0); + expect_function_calls (curl_easy_getinfo, 1); + + will_return (curl_easy_getinfo, 0); + expect_function_calls (curl_easy_getinfo, 1); + + will_return (curl_easy_getinfo, 1); + expect_function_calls (curl_easy_getinfo, 1); + + WEBCFG_STATUS result = webcfg_http_request(&config, r_count, status, &code, &transaction_id, contentType, &dataSize, docname); + + WebcfgInfo("The result is %d", result); + + assert_int_equal (result, 0); +} + +int Get_Supplementary_URL(char *name, char *pString) { + // Set a non-empty value for configURL + strcpy(pString, "http://example.com/config.xml"); + return 0; // or whatever the expected return value is +} + +//get_global_supplementarySync() == 1 +void test_webcfg_http_request_supp_sync() +{ + char *config = NULL; // Initialize with your data + int r_count = 2; // Set the number of retries as needed + int status = 0; // Set the status as needed + long code = 0; // Response code + char *transaction_id = NULL; // Transaction ID + char contentType[64] = {0}; // Content type + size_t dataSize = 0; // Data size + char docname[64] = "value"; // Document name + + + set_global_supplementarySync(1); + will_return (curl_easy_init, 1); + expect_function_calls (curl_easy_init, 1); + + will_return (curl_easy_perform, 0); + expect_function_calls (curl_easy_perform, 1); + + will_return (curl_easy_getinfo, 0); + expect_function_calls (curl_easy_getinfo, 1); + + will_return (curl_easy_getinfo, 0); + expect_function_calls (curl_easy_getinfo, 1); + + will_return (curl_easy_getinfo, 0); + expect_function_calls (curl_easy_getinfo, 1); + + WEBCFG_STATUS result = webcfg_http_request(&config, r_count, status, &code, &transaction_id, contentType, &dataSize, docname); + + WebcfgInfo("The result is %d", result); + + assert_int_equal (result, 0); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_webcfg_http_request_curl_init_fail), + cmocka_unit_test(test_webcfg_http_request_curl_init_success), + cmocka_unit_test(test_webcfg_http_request_supp_sync) + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} + diff --git a/tests/test_multipart_unittest.c b/tests/test_multipart_unittest.c index 06925b17..160c1535 100644 --- a/tests/test_multipart_unittest.c +++ b/tests/test_multipart_unittest.c @@ -42,11 +42,17 @@ #include "../src/webcfg_event.h" #include "../src/webcfg_auth.h" #include "../src/webcfg_blob.h" +#include "../src/webcfg_rbus.h" + +rbusHandle_t handle; +extern rbusHandle_t rbus_handle; #ifdef FEATURE_SUPPORT_AKER #include "webcfg_aker.h" #endif +#define WEBCFG_BLOB_PARAM "Device.X_RDK_WebConfig.blobElement" + int numLoops; #define MAX_HEADER_LEN 4096 @@ -92,69 +98,6 @@ char * getModelName() char *mName = strdup("Model"); return mName; } -long long getRetryExpiryTimeout() -{ -return 0; -} -int get_retry_timer() -{ - return 0; -} - -void set_retry_timer(int value) -{ - UNUSED(value); - return; -} -char* printTime(long long time) -{ - UNUSED(time); - return NULL; -} - -long get_global_retry_timestamp() -{ - return 0; -} -void set_global_retry_timestamp(long value) -{ - UNUSED(value); - return; -} -int updateRetryTimeDiff(long long expiry_time) -{ - UNUSED(expiry_time); - return 0; -} -int checkRetryTimer( long long timestamp) -{ - UNUSED(timestamp); - return 0; -} -void initMaintenanceTimer() -{ - return; -} -int checkMaintenanceTimer() -{ - return 0; -} -int getMaintenanceSyncSeconds(int maintenance_count) -{ - UNUSED(maintenance_count); - return 0; -} -int retrySyncSeconds() -{ - return 0; -} -void set_global_maintenance_time(long value) -{ - UNUSED(value); - return; -} - - void test_generate_trans_uuid(){ @@ -163,7 +106,6 @@ void test_generate_trans_uuid(){ CU_ASSERT_FATAL( NULL != transaction_uuid); } - void test_replaceMac(){ char *configURL= "https://config/{sss}/com"; @@ -632,6 +574,284 @@ void test_get_multipartdoc_count(){ CU_ASSERT_FATAL( NULL == get_global_mp() ); } +int getEncodedBlob(char *data, char **encodedData); +static void packJsonString( cJSON *item, msgpack_packer *pk ); +static void packJsonNumber( cJSON *item, msgpack_packer *pk ); +static void packJsonArray( cJSON *item, msgpack_packer *pk, int isBlob ); +static void packJsonObject( cJSON *item, msgpack_packer *pk, int isBlob); +static void __msgpack_pack_string( msgpack_packer *pk, const void *string, size_t n ); +static int convertJsonToMsgPack(char *data, char **encodedData, int isBlob); + + + +static void packBlobData(cJSON *item, msgpack_packer *pk ) +{ + char *blobData = NULL, *encodedBlob = NULL; + int len = 0; + WebcfgDebug("------ %s ------\n",__FUNCTION__); + blobData = strdup(item->valuestring); + if(strlen(blobData) > 0) + { + WebcfgDebug("%s\n",blobData); + len = getEncodedBlob(blobData, &encodedBlob); + WebcfgDebug("%s\n",encodedBlob); + } + __msgpack_pack_string(pk, item->string, strlen(item->string)); + __msgpack_pack_string(pk, encodedBlob, len); + free(encodedBlob); + free(blobData); + WebcfgDebug("------ %s ------\n",__FUNCTION__); +} + +static int getItemsCount(cJSON *object) +{ + int count = 0; + while(object != NULL) + { + object = object->next; + count++; + } + return count; +} + +static void packJsonNumber( cJSON *item, msgpack_packer *pk ) +{ + WebcfgDebug("%s:%d\n",__FUNCTION__,item->valueint); + if(item->string != NULL) + { + __msgpack_pack_string(pk, item->string, strlen(item->string)); + } + msgpack_pack_int(pk, item->valueint); +} +static void packJsonArray(cJSON *item, msgpack_packer *pk, int isBlob) +{ + int arraySize = cJSON_GetArraySize(item); + WebcfgDebug("%s:%s\n",__FUNCTION__, item->string); + if(item->string != NULL) + { + //printf("packing %s\n",item->string); + __msgpack_pack_string(pk, item->string, strlen(item->string)); + } + msgpack_pack_array( pk, arraySize ); + int i=0; + for(i=0; itype) & 0XFF) + { + case cJSON_Object: + packJsonObject(arrItem, pk, isBlob); + break; + } + } +} + +static void packJsonString( cJSON *item, msgpack_packer *pk ) +{ + if(item->string != NULL) + { + __msgpack_pack_string(pk, item->string, strlen(item->string)); + } + __msgpack_pack_string(pk, item->valuestring, strlen(item->valuestring)); +} + +static void __msgpack_pack_string( msgpack_packer *pk, const void *string, size_t n ) +{ + WebcfgDebug("%s:%s\n",__FUNCTION__,(char *)string); + msgpack_pack_str( pk, n ); + msgpack_pack_str_body( pk, string, n ); +} + +static void packJsonObject( cJSON *item, msgpack_packer *pk, int isBlob ) +{ + WebcfgDebug("%s\n",__FUNCTION__); + cJSON *child = item->child; + msgpack_pack_map( pk, getItemsCount(child)); + while(child != NULL) + { + switch((child->type) & 0XFF) + { + case cJSON_String: + if(child->string != NULL && (strcmp(child->string, "value") == 0) && isBlob == 1) + { + packBlobData(child, pk); + } + else + { + packJsonString(child, pk); + } + break; + case cJSON_Number: + packJsonNumber(child, pk); + break; + case cJSON_Array: + packJsonArray(child, pk, isBlob); + break; + } + child = child->next; + } +} + +int getEncodedBlob(char *data, char **encodedData) +{ + cJSON *jsonData=NULL; + int encodedDataLen = 0; + WebcfgDebug("------- %s -------\n",__FUNCTION__); + jsonData=cJSON_Parse(data); + if(jsonData != NULL) + { + msgpack_sbuffer sbuf1; + msgpack_packer pk1; + msgpack_sbuffer_init( &sbuf1 ); + msgpack_packer_init( &pk1, &sbuf1, msgpack_sbuffer_write ); + packJsonObject(jsonData, &pk1, 1); + if( sbuf1.data ) + { + *encodedData = ( char * ) malloc( sizeof( char ) * sbuf1.size ); + if( NULL != *encodedData ) + { + memcpy( *encodedData, sbuf1.data, sbuf1.size ); + } + encodedDataLen = sbuf1.size; + } + msgpack_sbuffer_destroy(&sbuf1); + cJSON_Delete(jsonData); + } + WebcfgDebug("------- %s -------\n",__FUNCTION__); + return encodedDataLen; +} + +static int convertJsonToMsgPack(char *data, char **encodedData, int isBlob) +{ + cJSON *jsonData=NULL; + int encodedDataLen = 0; + jsonData=cJSON_Parse(data); + if(jsonData != NULL) + { + msgpack_sbuffer sbuf; + msgpack_packer pk; + msgpack_sbuffer_init( &sbuf ); + msgpack_packer_init( &pk, &sbuf, msgpack_sbuffer_write ); + packJsonObject(jsonData, &pk, isBlob); + if( sbuf.data ) + { + *encodedData = ( char * ) malloc( sizeof( char ) * sbuf.size ); + if( NULL != *encodedData ) + { + memcpy( *encodedData, sbuf.data, sbuf.size ); + } + encodedDataLen = sbuf.size; + } + msgpack_sbuffer_destroy(&sbuf); + cJSON_Delete(jsonData); + } + return encodedDataLen; +} + +rbusError_t webcfgBlobElementSetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusSetHandlerOptions_t* opts) { + + (void) handle; + (void) opts; + char const* paramName = rbusProperty_GetName(prop); + + WebcfgInfo("Parameter name is %s \n", paramName); + rbusValueType_t type_t; + rbusValue_t paramValue_t = rbusProperty_GetValue(prop); + if(paramValue_t) { + type_t = rbusValue_GetType(paramValue_t); + } else { + WebcfgError("Invalid input to set\n"); + return RBUS_ERROR_INVALID_INPUT; + } + + if(strncmp(paramName, WEBCFG_BLOB_PARAM, maxParamLen) == 0){ + if(type_t == RBUS_BYTES) { + int len; + uint8_t const* data = rbusValue_GetBytes(paramValue_t, &len); + CU_ASSERT_FATAL(NULL != data); + } + else { + WebcfgError("Unexpected value type for property %s\n", paramName); + return RBUS_ERROR_INVALID_INPUT; + } + } + else { + WebcfgError("Unexpected parameter = %s\n", paramName); + return RBUS_ERROR_ELEMENT_DOES_NOT_EXIST; + } + return RBUS_ERROR_SUCCESS; +} + + +void test_processMsgpackSubdoc() +{ + int status = webconfigRbusInit("consumerComponent"); + if(status) + { + WebcfgInfo("rbus init success\n"); + } + else{ + WebcfgError("rbus init failed"); + } + + int res = rbus_open(&rbus_handle, "providerComponent"); + if(res != RBUS_ERROR_SUCCESS) + { + CU_FAIL("rbus_open failed for providerComponent"); + } + + rbusDataElement_t webcfgBlobElement[1] = { + {WEBCFG_BLOB_PARAM, RBUS_ELEMENT_TYPE_PROPERTY, {NULL, webcfgBlobElementSetHandler, NULL, NULL, NULL, NULL}} + }; + rbusError_t ret = rbus_regDataElements(rbus_handle, 1, webcfgBlobElement); + CU_ASSERT_EQUAL(ret, RBUS_ERROR_SUCCESS); + + SubDocSupportMap_t *supportdocs = (SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(supportdocs) + { + strcpy(supportdocs->name,"value"); + strcpy(supportdocs->support,"true"); + strcpy(supportdocs->rbus_listener,"true"); + strcpy(supportdocs->dest,WEBCFG_BLOB_PARAM); + supportdocs->next=NULL; + } + set_global_sdInfoHead(supportdocs); + set_global_supplementarySync(0); + + + char *transaction_id = strdup("1234"); + char *Data = "{\"parameters\": [{\"name\":\"Device.DeviceInfo.Test\",\"value\":\"false\",\"dataType\":12},{\"name\":\"Device.DeviceInfo.Test1\",\"value\":\"true\",\"dataType\":12}]}"; + + char *encodedData = NULL; + int encodedLen = 0; + + encodedLen = convertJsonToMsgPack(Data, &encodedData, 1); + if(encodedLen) + { + multipartdocs_t *node = (multipartdocs_t *)malloc(sizeof(multipartdocs_t)); + if (node != NULL) + { + node->etag = 345431215; + node->name_space = strdup("value"); // Assuming strdup is available + node->data = (char *)malloc(encodedLen); + if (node->data != NULL) + { + memcpy(node->data, encodedData, encodedLen); + } + node->data_size = encodedLen; + node->isSupplementarySync = 0; + node->next = NULL; + WEBCFG_STATUS result; + set_global_mp(node); + result = processMsgpackSubdoc(transaction_id); + CU_ASSERT_EQUAL(result, WEBCFG_FAILURE); + } + + } + //rbus_close(rbus_handle); + //webpaRbus_Uninit(); +} + void add_suites( CU_pSuite *suite ) { *suite = CU_add_suite( "tests", NULL, NULL ); @@ -677,6 +897,7 @@ void add_suites( CU_pSuite *suite ) CU_add_test( *suite, "test addToMpList", test_addToMpList); CU_add_test( *suite, "test delete_mp_doc", test_delete_mp_doc); CU_add_test( *suite, "test get_multipartdoc_count", test_get_multipartdoc_count); + CU_add_test( *suite, "test processMsgpackSubdoc", test_processMsgpackSubdoc); } /*----------------------------------------------------------------------------*/