int internal_init_with_lock_factory()

in src/umock_c.c [27:99]


int internal_init_with_lock_factory(ON_UMOCK_C_ERROR on_umock_c_error, UMOCK_C_LOCK_FACTORY_CREATE_LOCK_FUNC lock_factory_create_lock, void* lock_factory_create_lock_params)
{
    int result;

    if (umock_c_state != UMOCK_C_STATE_NOT_INITIALIZED)
    {
        /* Codes_SRS_UMOCK_C_01_007: [ umock_c_init when umock is already initialized shall fail and return a non-zero value. ]*/
        UMOCK_LOG("umock_c: umock_c already initialized.");
        result = __LINE__;
    }
    else
    {
        /* Codes_SRS_UMOCK_C_LIB_01_144: [ Out of the box umock_c shall support the following types through the header umocktypes_c.h: ]*/
        /* Codes_SRS_UMOCK_C_LIB_01_028: [**char**] */
        /* Codes_SRS_UMOCK_C_LIB_01_029 : [**unsigned char**] */
        /* Codes_SRS_UMOCK_C_LIB_01_030 : [**short**] */
        /* Codes_SRS_UMOCK_C_LIB_01_031 : [**unsigned short**] */
        /* Codes_SRS_UMOCK_C_LIB_01_032 : [**int**] */
        /* Codes_SRS_UMOCK_C_LIB_01_033 : [**unsigned int**] */
        /* Codes_SRS_UMOCK_C_LIB_01_034 : [**long**] */
        /* Codes_SRS_UMOCK_C_LIB_01_035 : [**unsigned long**] */
        /* Codes_SRS_UMOCK_C_LIB_01_036 : [**long long**] */
        /* Codes_SRS_UMOCK_C_LIB_01_037 : [**unsigned long long**] */
        /* Codes_SRS_UMOCK_C_LIB_01_038 : [**float**] */
        /* Codes_SRS_UMOCK_C_LIB_01_039 : [**double**] */
        /* Codes_SRS_UMOCK_C_LIB_01_040 : [**long double**] */
        /* Codes_SRS_UMOCK_C_LIB_01_041 : [**size_t**] */
        /* Codes_SRS_UMOCK_C_LIB_01_151: [ void\* ]*/
        /* Codes_SRS_UMOCK_C_LIB_01_152: [ const void\* ]*/
        /* Codes_SRS_UMOCK_C_01_023: [ umock_c_init shall initialize the umock types by calling umocktypes_init. ]*/
        if ((umocktypes_init() != 0) ||
            /* Codes_SRS_UMOCK_C_01_002: [ umock_c_init shall register the C native types by calling umocktypes_c_register_types. ]*/
            (umocktypes_c_register_types() != 0))
        {
            /* Codes_SRS_UMOCK_C_01_005: [ If any of the calls fails, umock_c_init shall fail and return a non-zero value. ]*/
            /* Codes_SRS_UMOCK_C_01_044: [ If any of the calls fails, umock_c_init_with_lock_factory shall fail and return a non-zero value. ]*/
            UMOCK_LOG("umock_c: Could not register standard C types with umock_c.");
            result = __LINE__;
        }
        else
        {
            /* Codes_SRS_UMOCK_C_01_003: [ umock_c_init shall create a call recorder by calling umockcallrecorder_create. ]*/
            umock_call_recorder = umockcallrecorder_create(lock_factory_create_lock, lock_factory_create_lock_params);
            if (umock_call_recorder == NULL)
            {
                /* Codes_SRS_UMOCK_C_01_005: [ If any of the calls fails, umock_c_init shall fail and return a non-zero value. ]*/
                /* Codes_SRS_UMOCK_C_01_044: [ If any of the calls fails, umock_c_init_with_lock_factory shall fail and return a non-zero value. ]*/
                UMOCK_LOG("umock_c: Could not create the call recorder.");
                result = __LINE__;
            }
            else
            {
                /* Codes_SRS_UMOCK_C_01_024: [ on_umock_c_error shall be optional. ]*/
                /* Codes_SRS_UMOCK_C_01_006: [ The on_umock_c_error callback shall be stored to be used for later error callbacks. ]*/
                on_umock_c_error_function = on_umock_c_error;

                /* Codes_SRS_UMOCK_C_01_001: [umock_c_init shall initialize the umock library.] */
                umock_c_state = UMOCK_C_STATE_INITIALIZED;

                /* Codes_SRS_UMOCK_C_01_004: [ On success, umock_c_init shall return 0. ]*/
                /* Codes_SRS_UMOCK_C_01_043: [ On success, umock_c_init_with_lock_factory shall return 0. ]*/
                result = 0;

                goto all_ok;
            }

            umocktypes_deinit();
        }
    }

all_ok:
    return result;
}