UTBotCpp
UTBotCpp copied to clipboard
[BUG] Array parameter initialized with simple type
Description In case function accept array as parameter but simply pass it to another function and does not access its element, UTBot initialize such parameter without array.
To Reproduce
int return_first_element(int array[]) {
int pivot = array[0];
return (pivot);
}
int foo(int array[]) {
return return_first_element(array);
}
- Use code above to reproduce.
- Generate tests for
foomethod. It results in following test:
TEST(regression, foo_test_1)
{
int array = 0;
int actual = foo(&array);
EXPECT_EQ(0, actual);
int expected_array = 0;
EXPECT_EQ(expected_array, array);
}
Note that array declared and initialized with simple int instead of array.
Expected that UTBot would generate test similar to what is generated for return_first_element method at least in part of declaration and initialization of array
// test generated for 'return_first_element'
TEST(regression, return_first_element_test_1)
{
int array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int actual = return_first_element(array);
EXPECT_EQ(0, actual);
int expected_array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for (int it_3_0 = 0; it_3_0 < 10; it_3_0 ++) {
EXPECT_EQ(expected_array[it_3_0], array[it_3_0]);
}
}
Seems it is the limitation of array type resolver
void ArraySubscriptFetcherMatchCallback::run(const MatchFinder::MatchResult &Result)
The parameter is recognized in case of usage [] addressing in the function body.
int return_first_element(int array[]) {
int pivot = *(array + 1); // <- array is a pointer
//int pivot = array[1]; // <- array is an array
return (pivot);
}