Skip to content

Commit

Permalink
update filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ladisgin committed May 3, 2023
1 parent 9ebcb17 commit 07b7f2e
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fun Path.assertTestFilesExist(sourceFileNames: List<String>) {
this.visitAllFiles { testFile ->
val name = testFile.nameWithoutExtension
if (!name.endsWith("_stub") &&
!name.endsWith(MAKE_WRAPPER_SUFFIX) &&
!name.endsWith("_wrapper") &&
testFile.extension != "mk"
) {
val sourceFileName = testFile.name.removeTestSuffixes()
Expand Down
80 changes: 32 additions & 48 deletions server/src/FeaturesFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ static void updateIfNotCompleteType(types::TypeSupport &typeSupport,
}
}

bool has_private_array(const types::Type &type, const types::TypesHandler &typesHandler) {
bool hasPrivateArray(const types::Type &type, const types::TypesHandler &typesHandler) {
switch (typesHandler.getTypeKind(type)) {
case types::TypeKind::STRUCT_LIKE:
for (const auto &field: typesHandler.getStructInfo(type).fields) {
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
return true;
}
return has_private_array(field.type, typesHandler);
return hasPrivateArray(field.type, typesHandler);
}
break;
case types::TypeKind::OBJECT_POINTER:
return has_private_array(type.baseTypeObj(), typesHandler);
case types::TypeKind::ARRAY:
return has_private_array(type.baseTypeObj(), typesHandler);
case types::TypeKind::PRIMITIVE:
case types::TypeKind::ENUM:
case types::TypeKind::UNKNOWN:
Expand Down Expand Up @@ -105,7 +103,7 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
}

if (method.isClassMethod() &&
!typesHandler.getStructInfo(method.classObj->type).canBeConstruct) {
!typesHandler.getStructInfo(method.classObj->type).hasDefaultPublicConstructor) {
std::stringstream message;
message
<< "Method '" << method.name
Expand All @@ -116,54 +114,40 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
return true;
}

for (const auto &param: method.params) {
if (typesHandler.isStructLike(param.type)) {
for (const auto &field: typesHandler.getStructInfo(param.type).fields) {
if (field.type.isArray() &&
field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
std::stringstream message;
message
<< "Method '" << method.name
<< "' was skipped, as class '" << param.type.typeName()
<< "' has private array member '" << field.name << "'";
LOG_S(DEBUG) << message.str();
tests.commentBlocks.push_back(message.str());
return true;
}
}
}
if (method.isClassMethod() &&
hasPrivateArray(method.classObj->type, typesHandler)) {
std::stringstream message;
message
<< "Method '" << method.name
<< "' was skipped, as class '" << method.classObj->type.typeName()
<< "' has private field";
LOG_S(DEBUG) << message.str();
tests.commentBlocks.push_back(message.str());
return true;
}

if (typesHandler.isStructLike(method.returnType)) {
for (const auto &field: typesHandler.getStructInfo(method.returnType).fields) {
if (field.type.isArray() &&
field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
std::stringstream message;
message
<< "Method '" << method.name
<< "' was skipped, as class '" << method.returnType.typeName()
<< "' has private array member '" << field.name << "'";
LOG_S(DEBUG) << message.str();
tests.commentBlocks.push_back(message.str());
return true;
}
for (const auto &param: method.params) {
if (typesHandler.isStructLike(param.type) && hasPrivateArray(param.type, typesHandler)) {
std::stringstream message;
message
<< "Method '" << method.name
<< "' was skipped, as parameter '" << param.type.typeName()
<< "' has private field";
LOG_S(DEBUG) << message.str();
tests.commentBlocks.push_back(message.str());
return true;
}
}

if (method.isClassMethod()) {
for (const auto &field: typesHandler.getStructInfo(method.classObj->type).fields) {
if (field.type.isArray() &&
field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
std::stringstream message;
message
<< "Method '" << method.name
<< "' was skipped, as class '" << method.getClassTypeName().value()
<< "' has private array member '" << field.name << "'";
LOG_S(DEBUG) << message.str();
tests.commentBlocks.push_back(message.str());
return true;
}
}
if (typesHandler.isStructLike(method.returnType) && hasPrivateArray(method.returnType, typesHandler)) {
std::stringstream message;
message
<< "Method '" << method.name
<< "' was skipped, as return type '" << method.returnType.typeName()
<< "' has private field";
LOG_S(DEBUG) << message.str();
tests.commentBlocks.push_back(message.str());
return true;
}

if (method.accessSpecifier != types::AS_pubic) {
Expand Down
3 changes: 1 addition & 2 deletions server/src/types/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ namespace types {
bool hasAnonymousStructOrUnion;
bool isCLike;
SubType subType;
//TODO delete then can construct without initializer list
bool canBeConstruct;
bool hasDefaultPublicConstructor;
};

struct EnumInfo: TypeInfo {
Expand Down
10 changes: 5 additions & 5 deletions server/src/types/TypesResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void TypesResolver::resolveStructEx(const clang::RecordDecl *D, const std::strin
structInfo.size = getRecordSize(D);
structInfo.alignment = getDeclAlignment(D);
structInfo.subType = subType;
structInfo.canBeConstruct = false;
structInfo.hasDefaultPublicConstructor = false;
if (auto CXXD = dynamic_cast<const clang::CXXRecordDecl *>(D)) {
LOG_S(MAX) << "Struct/Class " << structInfo.name << " CXX class";
if (!CXXD->isCLike()) {
Expand All @@ -177,13 +177,13 @@ void TypesResolver::resolveStructEx(const clang::RecordDecl *D, const std::strin
for (const auto &ctor: CXXD->ctors()) {
if (ctor->isDefaultConstructor() && !ctor->isDeleted() &&
getAcessSpecifier(ctor) == types::AccessSpecifier::AS_pubic) {
structInfo.canBeConstruct = true;
structInfo.hasDefaultPublicConstructor = true;
break;
}
}
LOG_IF_S(MAX, !structInfo.canBeConstruct) << "Struct/Class "
<< structInfo.name
<< " hasn't default public constructor";
LOG_IF_S(MAX, !structInfo.hasDefaultPublicConstructor) << "Struct/Class "
<< structInfo.name
<< " hasn't default public constructor";
}

addInfo(id, parent->projectTypes->structs, structInfo);
Expand Down
6 changes: 3 additions & 3 deletions server/test/framework/Server_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ namespace {
"sqr_positive");
}

TEST_P(Parameterized_Server_Test, Class_test1) {
TEST_P(Parameterized_Server_Test, Class_test1_cpp) {
auto request = createClassRequest(projectName, suitePath, buildDirRelativePath, srcPaths,
multiple_classes_h, 6);
auto testGen = ClassTestGen(*request, writer.get(), TESTMODE);
Expand All @@ -1137,7 +1137,7 @@ namespace {
"get1");
}

TEST_P(Parameterized_Server_Test, Class_test2) {
TEST_P(Parameterized_Server_Test, Class_test2_cpp) {
auto request = createClassRequest(projectName, suitePath, buildDirRelativePath, srcPaths,
multiple_classes_h, 14);
auto testGen = ClassTestGen(*request, writer.get(), TESTMODE);
Expand All @@ -1151,7 +1151,7 @@ namespace {
"get2");
}

TEST_P(Parameterized_Server_Test, DISABLED_Class_test3) {
TEST_P(Parameterized_Server_Test, DISABLED_Class_test3_cpp) {
auto request = createClassRequest(projectName, suitePath, buildDirRelativePath, srcPaths,
multiple_classes_h, 18);
auto testGen = ClassTestGen(*request, writer.get(), TESTMODE);
Expand Down
31 changes: 20 additions & 11 deletions server/test/framework/Syntax_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace {
fs::path namespace_cpp = getTestFilePath("namespace.cpp");
fs::path rvalue_reference_cpp = getTestFilePath("function_with_rvalue_params.cpp");
fs::path hard_linked_list_c = getTestFilePath("hard_linked_list.c");
fs::path unsupported_class_cpp = getTestFilePath("unsupported_class.cpp");

void SetUp() override {
clearEnv(CompilationUtils::CompilerName::CLANG);
Expand Down Expand Up @@ -2606,47 +2607,47 @@ namespace {
}));
}

TEST_F(Syntax_Test, Default_constructor) {
TEST_F(Syntax_Test, Default_constructor_cpp) {
auto [testGen, status] = createTestForFunction(constructors_cpp, 59);

ASSERT_TRUE(status.ok()) << status.error_message();

testUtils::checkMinNumberOfTests(testGen.tests.at(constructors_cpp).methods.begin().value().testCases, 1);
}

TEST_F(Syntax_Test, Constructor_with_parameters) {
TEST_F(Syntax_Test, Constructor_with_parameters_cpp) {
auto [testGen, status] = createTestForFunction(constructors_cpp, 86);

ASSERT_TRUE(status.ok()) << status.error_message();

testUtils::checkMinNumberOfTests(testGen.tests.at(constructors_cpp).methods.begin().value().testCases, 1);
}

TEST_F(Syntax_Test, Copy_constructor) {
TEST_F(Syntax_Test, Copy_constructor_cpp) {
auto [testGen, status] = createTestForFunction(constructors_cpp, 37);

ASSERT_TRUE(status.ok()) << status.error_message();

testUtils::checkMinNumberOfTests(testGen.tests.at(constructors_cpp).methods.begin().value().testCases, 1);
}

TEST_F(Syntax_Test, Move_constructor) {
TEST_F(Syntax_Test, Move_constructor_cpp) {
auto [testGen, status] = createTestForFunction(constructors_cpp, 67);

ASSERT_TRUE(status.ok()) << status.error_message();

testUtils::checkMinNumberOfTests(testGen.tests.at(constructors_cpp).methods.begin().value().testCases, 1);
}

TEST_F(Syntax_Test, Constructor_with_pointers) {
TEST_F(Syntax_Test, Constructor_with_pointers_cpp) {
auto [testGen, status] = createTestForFunction(constructors_cpp, 21);

ASSERT_TRUE(status.ok()) << status.error_message();

testUtils::checkMinNumberOfTests(testGen.tests.at(constructors_cpp).methods.begin().value().testCases, 2);
}

TEST_F(Syntax_Test, Constructor_with_if_stmt) {
TEST_F(Syntax_Test, Constructor_with_if_stmt_cpp) {
auto [testGen, status] = createTestForFunction(constructors_cpp, 9);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand Down Expand Up @@ -2730,7 +2731,7 @@ namespace {
);
}

TEST_F(Syntax_Test, example_namespace) {
TEST_F(Syntax_Test, example_namespace_cpp) {
auto [testGen, status] = createTestForFunction(namespace_cpp, 3);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand Down Expand Up @@ -2793,7 +2794,7 @@ namespace {
);
}

TEST_F(Syntax_Test, multiple_rvalue_params) {
TEST_F(Syntax_Test, multiple_rvalue_params_cpp) {
auto [testGen, status] = createTestForFunction(rvalue_reference_cpp, 9);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand Down Expand Up @@ -2832,7 +2833,7 @@ namespace {

}

TEST_F(Syntax_Test, const_rvalue_reference) {
TEST_F(Syntax_Test, const_rvalue_reference_cpp) {
auto [testGen, status] = createTestForFunction(rvalue_reference_cpp, 17);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand Down Expand Up @@ -2873,7 +2874,7 @@ namespace {
);
}

TEST_F(Syntax_Test, return_and_get_params) {
TEST_F(Syntax_Test, return_and_get_params_cpp) {
auto [testGen, status] = createTestForFunction(rvalue_reference_cpp, 28);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand Down Expand Up @@ -2913,7 +2914,7 @@ namespace {
);
}

TEST_F(Syntax_Test, rvalue_struct_param) {
TEST_F(Syntax_Test, rvalue_struct_param_cpp) {
auto [testGen, status] = createTestForFunction(rvalue_reference_cpp, 38);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand All @@ -2934,6 +2935,14 @@ namespace {
);
}

TEST_F(Syntax_Test, unsupported_clases_cpp) {
std::vector<size_t> lines = {4, 8, 12, 16};
for (const auto &line: lines) {
auto [testGen, status] = createTestForFunction(unsupported_class_cpp, line);
ASSERT_FALSE(status.ok());
}
}

TEST_F(Syntax_Test, simple_getc) {
auto [testGen, status] = createTestForFunction(input_output_c, 4);

Expand Down
3 changes: 2 additions & 1 deletion server/test/suites/syntax/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ add_executable(syntax1
file.c
bitfields.c
function_with_rvalue_params.cpp
hard_linked_list.c)
hard_linked_list.c
unsupported_class.cpp)
17 changes: 17 additions & 0 deletions server/test/suites/syntax/unsupported_class.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "unsupported_class.h"

int private_array::sum() {
return values[0] + values[1];
}

private_array return_private_array() {
return private_array();
}

bool parameter_private_array(private_array pa) {
return false;
}

int delete_constructor::sum() {
return values[0] + values[1];
}
35 changes: 35 additions & 0 deletions server/test/suites/syntax/unsupported_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef UTBOTCPP_UNSUPPORTED_CLASS_H
#define UTBOTCPP_UNSUPPORTED_CLASS_H


class private_array {
private:
int values[2];
public:
int sum();
};

private_array return_private_array();

bool parameter_private_array(private_array pa);

class delete_constructor {
public:
delete_constructor() = delete;

int values[5];

int sum();
};

class private_constructor {
private_constructor() = default;

public:
int values[2];

int sum();
};


#endif //UTBOTCPP_UNSUPPORTED_CLASS_H

0 comments on commit 07b7f2e

Please sign in to comment.