int umockcallrecorder_add_expected_call()

in src/umockcallrecorder.c [200:241]


int umockcallrecorder_add_expected_call(UMOCKCALLRECORDER_HANDLE umock_call_recorder, UMOCKCALL_HANDLE mock_call)
{
    int result;

    if ((umock_call_recorder == NULL) ||
        (mock_call == NULL))
    {
        /* Codes_SRS_UMOCKCALLRECORDER_01_012: [ If any of the arguments is NULL, umockcallrecorder_add_expected_call shall fail and return a non-zero value. ]*/
        UMOCK_LOG("umockcallrecorder: Bad arguments in add expected call: umock_call_recorder = %p, mock_call = %p.",
            umock_call_recorder, mock_call);
        result = MU_FAILURE;
    }
    else
    {
        /* Codes_SRS_UMOCKCALLRECORDER_01_068: [ If a lock was created for the call recorder, umockcallrecorder_add_expected_call acquire the lock in exclusive mode. ]*/
        internal_lock_acquire_exclusive_if_needed(umock_call_recorder);
        {
            UMOCK_EXPECTED_CALL* new_expected_calls = umockalloc_realloc(umock_call_recorder->expected_calls, sizeof(UMOCK_EXPECTED_CALL) * (umock_call_recorder->expected_call_count + 1));
            if (new_expected_calls == NULL)
            {
                /* Codes_SRS_UMOCKCALLRECORDER_01_013: [ If any error occurs, umockcallrecorder_add_expected_call shall fail and return a non-zero value. ]*/
                UMOCK_LOG("umockcallrecorder: Cannot allocate memory in add expected call.");
                result = MU_FAILURE;
            }
            else
            {
                /* Codes_SRS_UMOCKCALLRECORDER_01_008: [ umockcallrecorder_add_expected_call shall add the mock_call call to the expected call list maintained by the call recorder identified by umock_call_recorder. ]*/
                umock_call_recorder->expected_calls = new_expected_calls;
                umock_call_recorder->expected_calls[umock_call_recorder->expected_call_count].umockcall = mock_call;
                umock_call_recorder->expected_calls[umock_call_recorder->expected_call_count++].is_matched = 0;

                /* Codes_SRS_UMOCKCALLRECORDER_01_009: [ On success umockcallrecorder_add_expected_call shall return 0. ]*/
                result = 0;
            }

            /* Codes_SRS_UMOCKCALLRECORDER_01_069: [ If a lock was created for the call recorder, umockcallrecorder_add_expected_call shall release the exclusive lock. ]*/
            internal_lock_release_exclusive_if_needed(umock_call_recorder);
        }
    }

    return result;
}