-
Notifications
You must be signed in to change notification settings - Fork 0
void sample_function(int* input1)
This page describes the stub code for function void sample_function(int* input1)
, a method whose argument is pointer.
The argument with pointer can be input, output and both.
All patterns are described on this page.
The stub codes in source file is like below:
long sample_function_called_count;
int* sample_function_input[STUB_BUFFER_SIZE_1];
int sample_function_input_value[STUB_BUFFER_SIZE_1][STUB_BUFFER_SIZE_2];
long sample_function_input_value_size[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_input[index] = 0;
for (int index2 = 0; index2 < STUB_BUFFER_SIZE_2; index2++) {
sample_function_input_value[index][index2] = 0;
}
sample_function_input_value_size[index] = 0;
}
}
void sample_function(int* input1)
{
sample_function_input[sample_function_called_count] = input;
for (int index = 0;
index < sample_function_input_value_size[sample_function_called_count];
index++)
{
sample_function_input_value[sample_function_called_count][index] = *(input1 + index);
}
sample_function_called_count++;
}
The variable sample_function_input_value[STUB_BUFFER_SIZE_1][STUB_BUFFER_SIZE_2]
is a buffer to store the value the area specified by pointer argument, and in stub method, the values in the argument pointer area is copied to the buffer.
The buffer is defined as two-dimensional array to hold the value of the arguments for each execution.
The naming rule of the buffer is below:
(argument data type without pointer) (function name)_(argument name)_value[STUB_BUFFER_SIZE_1][STUB_BUFFER_SIZE_2];
The variable sample_function_input_value_size[STUB_BUFFER_SIZE_1]
holds the size to copy from the area specified by argument to the buffer sample_function_input_value
.
To change the number of data to copy to the buffer, edit the value in a size buffer.
The naming rule of the buffer is below:
long (function name)_(argument name)_value_size[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 files is like below:
extern long sample_function_called_count;
extern int sample_function_input_value[][STUB_BUFFER_SIZE_2];
extern long sample_function_input_value_size[];
void sample_function_init();
The stub codes in source file is like below:
long sample_function_called_count;
int* sample_function_input[STUB_BUFFER_SIZE_1];
int sample_function_input_return_value[STUB_BUFFER_SIZE_1][STUB_BUFFER_SIZE_2];
long sample_function_input_return_value_size[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_input[index] = 0;
for (int index2 = 0; index2 < STUB_BUFFER_SIZE_2; index2++) {
sample_function_input_return_value[index][index2] = 0;
}
sample_function_input_return_value_size[index] = 0;
}
}
void sample_function(int* input1)
{
sample_function_input[sample_function_called_count] = input1;
for (int index = 0;
index < sample_function_input_value_size[sample_function_called_count];
index++)
{
*(input1 + index) = sample_function_input_return_value[sample_function_called_count][index];
}
sample_function_called_count++;
}
The variable sample_function_input_return_value[STUB_BUFFER_SIZE_1][STUB_BUFFER_SIZE_2]
is a buffer to store value the stub method will return via the pointer argument.
The variable is declared as global variable and with "extern" in header file, and is be able to set the value before the stub method is called.
This is defines as two-dimension array to hold the value to return for each execution.
The naming rule of the buffer is below:
(argument data type without pointer) (function name)_(argument name)_return_value[STUB_BUFFER_SIZE_1][STUB_BUFFER_SIZE_2];
The variable sample_function_input_value_size[STUB_BUFFER_SIZE_1]
holds the size to copy to copy to argument.
To change the number of data to copy to area specified by argument pointer, edit the value in a size buffer before the stub method called, before calling a method which calls the stub method.
The naming rule of the buffer is below:
long (function name)_(argument name)_return_value_size[STUB_BUFFER_SIZE_1];
The value, buffer is defined as an array to be called multiple times. The macro STUB_BUFFER_SIZE_1
to show the size of array is defined in its header file and the default value is 100.
The stub code in header file is like below:
extern long sample_function_called_count;
extern int sample_function_input_return_value[][STUB_BUFFER_SIZE_2];
extern long sample_function_input_return_value_size[];
void sample_function_init();