Last active
January 31, 2022 19:24
-
-
Save Munken/df6828e275e128a8174c6e5851776a4d to your computer and use it in GitHub Desktop.
ioctl varadic mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Mocks source file | |
Generated with Narmock v0.2.15 (https://github.com/vberlier/narmock) | |
Do not edit manually | |
*/ | |
#include <errno.h> | |
#include <stddef.h> | |
#include "__mocks__.h" | |
void narmock_reset_all_mocks(void) | |
{ | |
MOCK(ioctl)->reset(); | |
} | |
// NARMOCK_IMPLEMENTATION ioctl | |
int __real_ioctl(int arg1, unsigned long int arg2, ...); | |
typedef struct _narmock_private_state_type_for_ioctl _narmock_private_state_type_for_ioctl; | |
struct _narmock_private_state_type_for_ioctl | |
{ | |
_narmock_state_type_for_ioctl public; | |
int mode; | |
int return_value; | |
int (*implementation)(int arg1, unsigned long int arg2, ...); | |
int errno_value; | |
_narmock_params_type_for_ioctl last_call; | |
}; | |
static const _narmock_state_type_for_ioctl *_narmock_mock_return_function_for_ioctl(int return_value); | |
static const _narmock_state_type_for_ioctl *_narmock_mock_implementation_function_for_ioctl(int (*implementation)(int arg1, unsigned long int arg2, ...)); | |
static const _narmock_state_type_for_ioctl *_narmock_mock_errno_function_for_ioctl(int errno_value); | |
static const _narmock_state_type_for_ioctl *_narmock_disable_mock_function_for_ioctl(void); | |
static const _narmock_state_type_for_ioctl *_narmock_reset_function_for_ioctl(void); | |
static _narmock_private_state_type_for_ioctl _narmock_state_for_ioctl = | |
{ | |
.public = { | |
.mock_return = _narmock_mock_return_function_for_ioctl, | |
.mock_implementation = _narmock_mock_implementation_function_for_ioctl, | |
.mock_errno = _narmock_mock_errno_function_for_ioctl, | |
.disable_mock = _narmock_disable_mock_function_for_ioctl, | |
.reset = _narmock_reset_function_for_ioctl, | |
.call_count = 0, | |
.last_call = NULL | |
}, | |
.mode = 0, | |
.errno_value = 0 | |
}; | |
int __wrap_ioctl_call_impl(int arg1, unsigned long int arg2, ...) { | |
void *args = __builtin_apply_args(); | |
void *ret = NULL; | |
(void) arg1; | |
(void) arg2; | |
switch (_narmock_state_for_ioctl.mode) | |
{ | |
case 1: | |
return _narmock_state_for_ioctl.return_value; | |
break; | |
case 2: | |
ret = __builtin_apply((void (*)())_narmock_state_for_ioctl.implementation, args, 1000); | |
__builtin_return(ret); | |
default: | |
ret = __builtin_apply((void (*)())__real_ioctl, args, 1000); | |
__builtin_return(ret); | |
} | |
} | |
int __wrap_ioctl(int arg1, unsigned long int arg2, ...) | |
{ | |
int return_value; | |
void *ret = NULL; | |
void *args = __builtin_apply_args(); | |
(void) arg1; | |
(void) arg2; | |
ret = __builtin_apply((void (*)())_narmock_state_for_ioctl.implementation, args, 1000); | |
return_value = *((int*) ret); | |
if (_narmock_state_for_ioctl.errno_value != 0) | |
{ | |
errno = _narmock_state_for_ioctl.errno_value; | |
} | |
_narmock_state_for_ioctl.public.call_count++; | |
_narmock_params_type_for_ioctl last_call = { arg1, arg2, return_value, errno }; | |
_narmock_state_for_ioctl.last_call = last_call; | |
_narmock_state_for_ioctl.public.last_call = &_narmock_state_for_ioctl.last_call; | |
return return_value; | |
} | |
static const _narmock_state_type_for_ioctl *_narmock_mock_return_function_for_ioctl(int return_value) | |
{ | |
_narmock_state_for_ioctl.mode = 1; | |
_narmock_state_for_ioctl.return_value = return_value; | |
return &_narmock_state_for_ioctl.public; | |
} | |
static const _narmock_state_type_for_ioctl *_narmock_mock_implementation_function_for_ioctl(int (*implementation)(int arg1, unsigned long int arg2, ...)) | |
{ | |
_narmock_state_for_ioctl.mode = 2; | |
_narmock_state_for_ioctl.implementation = implementation; | |
return &_narmock_state_for_ioctl.public; | |
} | |
static const _narmock_state_type_for_ioctl *_narmock_mock_errno_function_for_ioctl(int errno_value) | |
{ | |
_narmock_state_for_ioctl.errno_value = errno_value; | |
return &_narmock_state_for_ioctl.public; | |
} | |
static const _narmock_state_type_for_ioctl *_narmock_disable_mock_function_for_ioctl(void) | |
{ | |
_narmock_state_for_ioctl.mode = 0; | |
_narmock_state_for_ioctl.errno_value = 0; | |
return &_narmock_state_for_ioctl.public; | |
} | |
static const _narmock_state_type_for_ioctl *_narmock_reset_function_for_ioctl(void) | |
{ | |
_narmock_state_for_ioctl.mode = 0; | |
_narmock_state_for_ioctl.errno_value = 0; | |
_narmock_state_for_ioctl.public.call_count = 0; | |
_narmock_state_for_ioctl.public.last_call = NULL; | |
return &_narmock_state_for_ioctl.public; | |
} | |
const _narmock_state_type_for_ioctl *_narmock_get_mock_for_ioctl(const void *function) | |
{ | |
(void)function; | |
return &_narmock_state_for_ioctl.public; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Mocks header file | |
Generated with Narmock v0.2.15 (https://github.com/vberlier/narmock) | |
Do not edit manually | |
*/ | |
#ifndef MOCKS_H | |
#define MOCKS_H | |
#include <x86_64-linux-gnu/sys/ioctl.h> | |
#ifndef MOCK | |
#define MOCK(function) (_narmock_get_mock_for_##function((void *)&function)) | |
#endif | |
#ifndef _NARMOCK_RESET_ALL_MOCKS | |
#define _NARMOCK_RESET_ALL_MOCKS 1 | |
void narmock_reset_all_mocks(void); | |
#endif | |
// NARMOCK_DECLARATION ioctl | |
// NARMOCK_LINKER_FLAGS -Wl,--wrap=ioctl | |
typedef struct _narmock_state_type_for_ioctl _narmock_state_type_for_ioctl; | |
typedef struct _narmock_params_type_for_ioctl _narmock_params_type_for_ioctl; | |
struct _narmock_state_type_for_ioctl | |
{ | |
const _narmock_state_type_for_ioctl *(*mock_return)(int return_value); | |
const _narmock_state_type_for_ioctl *(*mock_implementation)(int (*implementation)(int arg1, unsigned long int arg2, ...)); | |
const _narmock_state_type_for_ioctl *(*mock_errno)(int errno_value); | |
const _narmock_state_type_for_ioctl *(*disable_mock)(void); | |
const _narmock_state_type_for_ioctl *(*reset)(void); | |
int call_count; | |
const _narmock_params_type_for_ioctl *last_call; | |
}; | |
struct _narmock_params_type_for_ioctl | |
{ | |
int arg1; | |
unsigned long int arg2; | |
int return_value; | |
int errsv; | |
}; | |
const _narmock_state_type_for_ioctl *_narmock_get_mock_for_ioctl(const void *function); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment