diff --git a/server/test/framework/Server_Tests.cpp b/server/test/framework/Server_Tests.cpp index 2125cd13..f1dab115 100644 --- a/server/test/framework/Server_Tests.cpp +++ b/server/test/framework/Server_Tests.cpp @@ -2103,6 +2103,44 @@ namespace { testUtils::checkStatuses(resultsMap, tests); } + TEST_F(Server_Test, Run_Tests_For_Multi_Dim_Pointers) { + fs::path multi_dim_pointers_c = getTestFilePath("multi_dim_pointers.c"); + auto request = testUtils::createFileRequest(projectName, suitePath, buildDirRelativePath, + srcPaths, multi_dim_pointers_c, + GrpcUtils::UTBOT_AUTO_TARGET_PATH, true, false); + auto testGen = FileTestGen(*request, writer.get(), TESTMODE); + Status status = Server::TestsGenServiceImpl::ProcessBaseTestRequest(testGen, writer.get()); + ASSERT_TRUE(status.ok()) << status.error_message(); + EXPECT_GE(testUtils::getNumberOfTests(testGen.tests), 2); + + fs::path testsDirPath = getTestFilePath("tests"); + + fs::path multi_dim_pointers_test_cpp = Paths::sourcePathToTestPath( + utbot::ProjectContext(projectName, suitePath, testsDirPath, buildDirRelativePath, clientProjectPath), + multi_dim_pointers_c); + auto testFilter = GrpcUtils::createTestFilterForFile(multi_dim_pointers_test_cpp); + auto runRequest = testUtils::createCoverageAndResultsRequest( + projectName, suitePath, testsDirPath, buildDirRelativePath, std::move(testFilter)); + + static auto coverageAndResultsWriter = + std::make_unique(nullptr); + CoverageAndResultsGenerator coverageGenerator{ runRequest.get(), + coverageAndResultsWriter.get() }; + utbot::SettingsContext settingsContext{ + true, false, 45, 0, false, false, ErrorMode::FAILING, false + }; + coverageGenerator.generate(false, settingsContext); + + EXPECT_FALSE(coverageGenerator.hasExceptions()); + ASSERT_TRUE(coverageGenerator.getCoverageMap().empty()); + + auto resultsMap = coverageGenerator.getTestResultMap(); + auto tests = coverageGenerator.getTestsToLaunch(); + + StatusCountMap expectedStatusCountMap{ { testsgen::TEST_PASSED, 2 } }; + testUtils::checkStatuses(resultsMap, tests); + } + TEST_F(Server_Test, Run_Tests_For_Struct_With_Union) { fs::path struct_with_union_c = getTestFilePath("struct_with_union.c"); auto request = testUtils::createFileRequest(projectName, suitePath, buildDirRelativePath, diff --git a/server/test/suites/server/CMakeLists.txt b/server/test/suites/server/CMakeLists.txt index 9195dc52..e2ed1c57 100644 --- a/server/test/suites/server/CMakeLists.txt +++ b/server/test/suites/server/CMakeLists.txt @@ -20,6 +20,7 @@ add_executable(server keywords.c linkage.c main.c + multi_dim_pointers.c pointer_parameters.c pointer_return.c simple_structs.c diff --git a/server/test/suites/server/multi_dim_pointers.c b/server/test/suites/server/multi_dim_pointers.c new file mode 100644 index 00000000..15146509 --- /dev/null +++ b/server/test/suites/server/multi_dim_pointers.c @@ -0,0 +1,23 @@ +#include "multi_dim_pointers.h" + +int func_with_multi_dim_pointer(struct MainStruct **str) { + if (!str) { + return 0; + } + str++; + struct MainStruct *ptr = *str; + int sz = 0; + if (ptr) { + struct ElementStruct *e = ptr->list.head; + struct ElementStruct *n; + for (int i = 0; i < 5; i++) { + if (e) { + n = e->next; + sz++; + } else { + break; + } + } + } + return sz; +} diff --git a/server/test/suites/server/multi_dim_pointers.h b/server/test/suites/server/multi_dim_pointers.h new file mode 100644 index 00000000..7dce8b47 --- /dev/null +++ b/server/test/suites/server/multi_dim_pointers.h @@ -0,0 +1,21 @@ +#ifndef UNITTESTBOT_MULTI_DIM_POINTERS_H +#define UNITTESTBOT_MULTI_DIM_POINTERS_H + +struct ElementStruct { + struct ElementStruct *prev; + struct ElementStruct *next; +}; + +struct ListStruct { + struct ElementStruct *head; + struct ElementStruct *tail; + unsigned size; +}; + +struct MainStruct { + struct ListStruct list; +}; + +int func_with_multi_dim_pointer(struct MainStruct **str); + +#endif // UNITTESTBOT_MULTI_DIM_POINTERS_H