-
Notifications
You must be signed in to change notification settings - Fork 0
int sample_function()
CountrySideEngineer edited this page Nov 25, 2022
·
2 revisions
This page describes the stub code for function int sample_function()
, a method which has return.
The stub codes in source file is like below:
long sample_function_called_count;
int sample_function_return_value[STUB_BUFFER_SIZE_1];
void sample_function_init()
{
sample_function_called_count = 0;
for (int index = 0; index < STUB_BUFFER_SIZE_1; index++) {
sample_function_return_value[index] = 0;
}
}
int sample_function()
{
int return_latch = sample_function_return_value[sample_function_called_count];
sample_function_called_count++;
return return_latch;
}
The variable sample_function_return_value[STUB_BUFFER_SIZE_1]
is a buffer to store the values the stub method will return each time.
The naming rule for the variable to store the values to store the method should return is below:
(function data type) (function_name)_return_value[STUB_BUFFER_SIZE_1];
The variable is defined as an array to be called multiple calls.
The macro STUB_BUFFER_SIZE_1
to show the size of array is defined in its header file and the default size is 100.
The stub code in header file is like below.
extern long sample_function_called_count;
extern int sample_function_return_value[];
void sample_function_init();