diff --git a/integration-tests/cpp-example/Refs.cpp b/integration-tests/cpp-example/Refs.cpp deleted file mode 100644 index 6327e3151..000000000 --- a/integration-tests/cpp-example/Refs.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -#include "Refs.h" - -int Refs::foo(int& a) { - a++; - if (a > 5) { - return 10; - } - return 20; -} - -int& Refs::bar(char c) { - intRef = 5; - return intRef; -} \ No newline at end of file diff --git a/integration-tests/cpp-example/Refs.h b/integration-tests/cpp-example/Refs.h deleted file mode 100644 index a6bdbe982..000000000 --- a/integration-tests/cpp-example/Refs.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -class Refs { -public: - Refs() = default; - - int foo(int& a); - - int& bar(char c); - -private: - int intRef; -}; \ No newline at end of file diff --git a/integration-tests/cpp-example/SimpleClass.cpp b/integration-tests/cpp-example/SimpleClass.cpp deleted file mode 100644 index 127811f70..000000000 --- a/integration-tests/cpp-example/SimpleClass.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -#include "SimpleClass.h" - -SimpleClass::SimpleClass() { - c = 10; -} - -int SimpleClass::sum_with_c(int a) { - if (a % 2 == 0) { - return a + c; - } - return 17; -} - -int SimpleClass::sub_with_c(int a, int b) { - if (a == c) { - c++; - return a - c; - } - return a - b; -} - -int SimpleClass::mul_with_c(int a, int b) { - if (a != 0 && b != 0) { - return a * b * c; - } - return 2; -} - -int outer_func(int a, int b) { - if (a - b != 12) { - return a * a - 2 * a * b + b * b; - } - return 21; -} \ No newline at end of file diff --git a/integration-tests/cpp-example/SimpleClass.h b/integration-tests/cpp-example/SimpleClass.h deleted file mode 100644 index f71eff182..000000000 --- a/integration-tests/cpp-example/SimpleClass.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -class SimpleClass { -public: - SimpleClass(); - - int sum_with_c(int a); - - int sub_with_c(int a, int b); - - int mul_with_c(int a, int b); -private: - int c; -}; - -int outer_func(int a, int b); \ No newline at end of file diff --git a/integration-tests/cpp-example/VirtualMethods.cpp b/integration-tests/cpp-example/VirtualMethods.cpp deleted file mode 100644 index 69e17f082..000000000 --- a/integration-tests/cpp-example/VirtualMethods.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -#include "VirtualMethods.h" - -Animal::Animal() : type("Animal") {} - -string Animal::getType() { - return type; -} - -Dog::Dog() : type("Dog") {} - -string Dog::getType() { - return type; -} - -Cat::Cat() : type("Cat") {} - -string Cat::getType() { - return type; -} - -string concatTypes() { - auto* animal1 = new Animal(); - Animal* dog1 = new Dog(); - Animal* cat1 = new Cat(); - return animal1->getType() + " " + dog1->getType() + " " + cat1->getType(); -} diff --git a/integration-tests/cpp-example/VirtualMethods.h b/integration-tests/cpp-example/VirtualMethods.h deleted file mode 100644 index e6050b75c..000000000 --- a/integration-tests/cpp-example/VirtualMethods.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -#ifndef CPP_PROJECT_VIRTUALMETHODS_H -#define CPP_PROJECT_VIRTUALMETHODS_H - -#include -#include -using namespace std; - -class Animal { -private: - string type; - -public: - Animal(); - - virtual string getType(); -}; - -class Dog : public Animal { -private: - string type; - -public: - Dog(); - - string getType() override; -}; - -class Cat : public Animal { -private: - string type; - -public: - Cat(); - - string getType() override; -}; - -string concatTypes(); - -#endif //CPP_PROJECT_VIRTUALMETHODS_H diff --git a/integration-tests/cpp-example/build.sh b/integration-tests/cpp-example/build.sh deleted file mode 100644 index 9bd052b8b..000000000 --- a/integration-tests/cpp-example/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -# -# Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. -# - -rm -rf build && mkdir -p build && cd build && cmake .. && /opt/bear/bin/bear make -j8 \ No newline at end of file diff --git a/integration-tests/cpp-example/cxx_lib/point_2d.cpp b/integration-tests/cpp-example/cxx_lib/point_2d.cpp index a146607aa..fe3082ad2 100644 --- a/integration-tests/cpp-example/cxx_lib/point_2d.cpp +++ b/integration-tests/cpp-example/cxx_lib/point_2d.cpp @@ -51,7 +51,7 @@ Point_2d operator-(Point_2d lhs, const Point_2d& rhs) { } -double get_dist(const Point_2d& lhs, Point_2d& rhs) { +double get_dist(const Point_2d& lhs, const Point_2d& rhs) { auto t = lhs - rhs; return t.get_dist_to_zero(); } diff --git a/integration-tests/cpp-example/cxx_lib/point_2d.hpp b/integration-tests/cpp-example/cxx_lib/point_2d.hpp index 3041e3d16..853d568e1 100644 --- a/integration-tests/cpp-example/cxx_lib/point_2d.hpp +++ b/integration-tests/cpp-example/cxx_lib/point_2d.hpp @@ -6,8 +6,9 @@ #define POINT_2D_HPP class Point_2d { -public: +private: int x; +public: int y; Point_2d(); @@ -24,12 +25,15 @@ class Point_2d { friend Point_2d operator-(Point_2d lhs, const Point_2d& rhs); double get_dist_to_zero() const; + friend double get_dist(const Point_2d& lhs, const Point_2d& rhs); + friend void set_to_zero(Point_2d& point); + friend void set_abs_by_ref(Point_2d& point); }; Point_2d operator+(const Point_2d& lhs, const Point_2d& rhs); Point_2d operator-(Point_2d lhs, const Point_2d& rhs); -double get_dist(const Point_2d& lhs, Point_2d& rhs); +double get_dist(const Point_2d& lhs, const Point_2d& rhs); void set_to_zero(Point_2d& point); diff --git a/integration-tests/cpp-example/cxx_lib/triangle.cpp b/integration-tests/cpp-example/cxx_lib/triangle.cpp index e143c4ed2..ed67083a8 100644 --- a/integration-tests/cpp-example/cxx_lib/triangle.cpp +++ b/integration-tests/cpp-example/cxx_lib/triangle.cpp @@ -2,7 +2,8 @@ * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. */ -#include "triangle.hpp" +#include "triangle.h" +#include "point_2d.hpp" #include @@ -35,9 +36,9 @@ double Triangle::get_perimeter() { } double Triangle::get_area() { - auto side1 = get_dist(vertex[0], vertex[1]); - auto side2 = get_dist(vertex[1], vertex[2]); - auto side3 = get_dist(vertex[2], vertex[0]); + double side1 = get_dist(vertex[0], vertex[1]); + double side2 = get_dist(vertex[1], vertex[2]); + double side3 = get_dist(vertex[2], vertex[0]); auto p = this->get_perimeter(); return sqrt(p * (p - side1) * (p - side2) * (p - side3)); } \ No newline at end of file diff --git a/integration-tests/cpp-example/cxx_lib/triangle.hpp b/integration-tests/cpp-example/cxx_lib/triangle.hpp deleted file mode 100644 index d187bc763..000000000 --- a/integration-tests/cpp-example/cxx_lib/triangle.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -#ifndef TRAINGLE_HPP -#define TRAINGLE_HPP - -#include "abstract_shape.hpp" - -class Triangle : Abstract_shape { -public: - Point_2d vertex[3]; - - Triangle(); - Triangle(Point_2d a, Point_2d b, Point_2d c); - - Shapes get_shape_type() const override; - unsigned int get_vertex_count() const override; - Point_2d* get_vertex() override; - double get_perimeter() override; - double get_area() override; -}; - - -#endif //TRAINGLE_HPP \ No newline at end of file diff --git a/integration-tests/cpp-example/main.cpp b/integration-tests/cpp-example/main.cpp index 3068aae96..07302c9ee 100644 --- a/integration-tests/cpp-example/main.cpp +++ b/integration-tests/cpp-example/main.cpp @@ -2,8 +2,6 @@ * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. */ -#include "SimpleClass.h" - int main(int argc, char** argv) { return 0; } \ No newline at end of file diff --git a/integration-tests/cpp-example/std/Strings.cpp b/integration-tests/cpp-example/std/Strings.cpp deleted file mode 100644 index 8ace2c232..000000000 --- a/integration-tests/cpp-example/std/Strings.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -#include "Strings.h" - -int doubleLen(const string &s) { - if (s == "abc") return -1; - return s.size() * 2; -} diff --git a/integration-tests/cpp-example/std/Strings.h b/integration-tests/cpp-example/std/Strings.h deleted file mode 100644 index dd03150ee..000000000 --- a/integration-tests/cpp-example/std/Strings.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. - */ - -#ifndef CPP_PROJECT_STRINGS_H -#define CPP_PROJECT_STRINGS_H - -#include -using namespace std; - -int doubleLen(const string& s); - -#endif //CPP_PROJECT_STRINGS_H diff --git a/server/src/printers/KleePrinter.cpp b/server/src/printers/KleePrinter.cpp index d4bcd5211..7f1be7d25 100644 --- a/server/src/printers/KleePrinter.cpp +++ b/server/src/printers/KleePrinter.cpp @@ -80,7 +80,7 @@ fs::path KleePrinter::writeTmpKleeFile( ss << NL; writeStubsForStructureFields(tests); - writePrivateAccessMacros(typesHandler, tests); + writePrivateAccessMacros(typesHandler, tests, false); for (const auto &[methodName, testMethod] : tests.methods) { if (!methodFilter(testMethod)) { @@ -354,8 +354,7 @@ void KleePrinter::genReturnDeclaration(const Tests::MethodDescription &testMetho : testMethod.returnType; bool maybeArray = returnType.maybeReturnArray(); bool isPointer = testMethod.returnType.isObjectPointer(); - auto baseType = returnType.baseType(); - ss << TAB_N() << returnType.baseType() << " " << KleeUtils::RESULT_VARIABLE_NAME; + strDeclareVar(returnType.baseType(), KleeUtils::RESULT_VARIABLE_NAME, std::nullopt, std::nullopt, false); makeBracketsForStrPredicate(predicateInfo); if (maybeArray) { size_t size = types::TypesHandler::getElementsNumberInPointerOneDim(PointerUsage::RETURN); diff --git a/server/src/printers/Printer.cpp b/server/src/printers/Printer.cpp index 2749ad9cf..d6275bc6d 100644 --- a/server/src/printers/Printer.cpp +++ b/server/src/printers/Printer.cpp @@ -97,6 +97,8 @@ namespace printer { if (needDecorate()) { ss << NameDecorator::decorate(type) << additionalPointers << " " << NameDecorator::decorate(name); + } else if (getLanguage() == utbot::Language::CXX) { + ss << types::TypesHandler::cBoolToCpp(std::string(type)) << additionalPointers << " " << name; } else { ss << type << additionalPointers << " " << name; } @@ -579,7 +581,7 @@ namespace printer { stubName, "stub", makeStatic); } - void Printer::writePrivateAccessMacros(types::TypesHandler const *typesHandler, const Tests &tests) { + void Printer::writePrivateAccessMacros(types::TypesHandler const *typesHandler, const Tests &tests, bool onlyChangeable) { if (srcLanguage == utbot::Language::CXX) { ss << NL; strInclude("access_private.hpp"); @@ -588,7 +590,7 @@ namespace printer { for (const auto &[methodName, testMethod] : tests.methods) { addAccessor(typesHandler, testMethod.returnType, checkedOnPrivate); for (const auto& param : testMethod.params) { - if (param.isChangeable()) { + if (!onlyChangeable || param.isChangeable()) { addAccessor(typesHandler, param.type, checkedOnPrivate); } } diff --git a/server/src/printers/Printer.h b/server/src/printers/Printer.h index 503060de1..23124a485 100644 --- a/server/src/printers/Printer.h +++ b/server/src/printers/Printer.h @@ -229,7 +229,7 @@ namespace printer { const string& name, const string& stubName, bool needToTypedef, bool makeStatic); - void writePrivateAccessMacros(types::TypesHandler const *typesHandler, const Tests &tests); + void writePrivateAccessMacros(types::TypesHandler const *typesHandler, const Tests &tests, bool onlyChangeable); void genStubForStructFunctionPointer(const string& structName, const string& fieldName, diff --git a/server/src/printers/TestsPrinter.cpp b/server/src/printers/TestsPrinter.cpp index 0725d2f3b..a3d7afeca 100644 --- a/server/src/printers/TestsPrinter.cpp +++ b/server/src/printers/TestsPrinter.cpp @@ -176,7 +176,7 @@ void TestsPrinter::genHeaders(Tests &tests, const fs::path& generatedHeaderPath) } } - writePrivateAccessMacros(typesHandler, tests); + writePrivateAccessMacros(typesHandler, tests, true); } static string getTestName(const Tests::MethodDescription &methodDescription, int testNum) {