Skip to content

Commit

Permalink
Add tests for this case
Browse files Browse the repository at this point in the history
  • Loading branch information
IDKWNTCMF committed Jul 28, 2023
1 parent df038ef commit a683b70
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
38 changes: 38 additions & 0 deletions server/test/framework/Server_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerCoverageAndResultsWriter>(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,
Expand Down
1 change: 1 addition & 0 deletions server/test/suites/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions server/test/suites/server/multi_dim_pointers.c
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions server/test/suites/server/multi_dim_pointers.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a683b70

Please sign in to comment.