in src/umockcall.c [210:270]
UMOCKCALL_HANDLE umockcall_clone(UMOCKCALL_HANDLE umockcall)
{
UMOCKCALL_HANDLE result;
if (umockcall == NULL)
{
/* Codes_SRS_UMOCKCALL_01_032: [ If umockcall is NULL, umockcall_clone shall return NULL. ]*/
UMOCK_LOG("umockcall_clone: NULL umockcall in getting call data.");
result = NULL;
}
else
{
result = (UMOCKCALL*)umockalloc_malloc(sizeof(UMOCKCALL));
if (result == NULL)
{
/* Codes_SRS_UMOCKCALL_01_043: [ If allocating memory for the new umock call fails, umockcall_clone shall return NULL. ]*/
UMOCK_LOG("umockcall_clone: Failed allocating memory for new copied call.");
}
else
{
size_t function_name_length = strlen(umockcall->function_name);
result->function_name = (char*)umockalloc_malloc(function_name_length + 1);
if (result->function_name == NULL)
{
/* Codes_SRS_UMOCKCALL_01_036: [ If allocating memory for the function name fails, umockcall_clone shall return NULL. ]*/
UMOCK_LOG("umockcall_clone: Failed allocating memory for new copied call function name.");
umockalloc_free(result);
result = NULL;
}
else
{
/* Codes_SRS_UMOCKCALL_01_035: [ umockcall_clone shall copy also the function name. ]*/
(void)memcpy(result->function_name, umockcall->function_name, function_name_length + 1);
/* Codes_SRS_UMOCKCALL_01_033: [ The call data shall be cloned by calling the umockcall_data_copy function passed in umockcall_create and passing as argument the umockcall_data value passed in umockcall_create. ]*/
result->umockcall_data = umockcall->umockcall_data_copy(umockcall->umockcall_data);
if (result->umockcall_data == NULL)
{
/* Codes_SRS_UMOCKCALL_01_034: [ If umockcall_data_copy fails then umockcall_clone shall return NULL. ]*/
UMOCK_LOG("umockcall_clone: Failed copying call data.");
umockalloc_free(result->function_name);
umockalloc_free(result);
result = NULL;
}
else
{
/* Codes_SRS_UMOCKCALL_01_037: [ umockcall_clone shall also copy all the functions passed to umockcall_create (umockcall_data_copy, umockcall_data_free, umockcall_data_are_equal, umockcall_data_stringify). ]*/
result->umockcall_data_are_equal = umockcall->umockcall_data_are_equal;
result->umockcall_data_copy = umockcall->umockcall_data_copy;
result->umockcall_data_free = umockcall->umockcall_data_free;
result->umockcall_data_stringify = umockcall->umockcall_data_stringify;
result->ignore_all_calls = umockcall->ignore_all_calls;
result->call_can_fail = umockcall->call_can_fail;
result->fail_call = umockcall->fail_call;
}
}
}
}
return result;
}