Skip to content

Commit 29161a4

Browse files
ladisginkorifey
authored andcommitted
update cpp example, small fix for c++
1 parent 3f4c8a3 commit 29161a4

File tree

18 files changed

+20
-232
lines changed

18 files changed

+20
-232
lines changed

integration-tests/cpp-example/Refs.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

integration-tests/cpp-example/Refs.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

integration-tests/cpp-example/SimpleClass.cpp

Lines changed: 0 additions & 38 deletions
This file was deleted.

integration-tests/cpp-example/SimpleClass.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

integration-tests/cpp-example/VirtualMethods.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

integration-tests/cpp-example/VirtualMethods.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

integration-tests/cpp-example/build.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

integration-tests/cpp-example/cxx_lib/point_2d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Point_2d operator-(Point_2d lhs, const Point_2d& rhs) {
5151
}
5252

5353

54-
double get_dist(const Point_2d& lhs, Point_2d& rhs) {
54+
double get_dist(const Point_2d& lhs, const Point_2d& rhs) {
5555
auto t = lhs - rhs;
5656
return t.get_dist_to_zero();
5757
}

integration-tests/cpp-example/cxx_lib/point_2d.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#define POINT_2D_HPP
77

88
class Point_2d {
9-
public:
9+
private:
1010
int x;
11+
public:
1112
int y;
1213

1314
Point_2d();
@@ -24,12 +25,15 @@ class Point_2d {
2425
friend Point_2d operator-(Point_2d lhs, const Point_2d& rhs);
2526

2627
double get_dist_to_zero() const;
28+
friend double get_dist(const Point_2d& lhs, const Point_2d& rhs);
29+
friend void set_to_zero(Point_2d& point);
30+
friend void set_abs_by_ref(Point_2d& point);
2731
};
2832

2933
Point_2d operator+(const Point_2d& lhs, const Point_2d& rhs);
3034
Point_2d operator-(Point_2d lhs, const Point_2d& rhs);
3135

32-
double get_dist(const Point_2d& lhs, Point_2d& rhs);
36+
double get_dist(const Point_2d& lhs, const Point_2d& rhs);
3337

3438
void set_to_zero(Point_2d& point);
3539

integration-tests/cpp-example/cxx_lib/triangle.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
33
*/
44

5-
#include "triangle.hpp"
5+
#include "triangle.h"
6+
#include "point_2d.hpp"
67
#include <cmath>
78

89

@@ -35,9 +36,9 @@ double Triangle::get_perimeter() {
3536
}
3637

3738
double Triangle::get_area() {
38-
auto side1 = get_dist(vertex[0], vertex[1]);
39-
auto side2 = get_dist(vertex[1], vertex[2]);
40-
auto side3 = get_dist(vertex[2], vertex[0]);
39+
double side1 = get_dist(vertex[0], vertex[1]);
40+
double side2 = get_dist(vertex[1], vertex[2]);
41+
double side3 = get_dist(vertex[2], vertex[0]);
4142
auto p = this->get_perimeter();
4243
return sqrt(p * (p - side1) * (p - side2) * (p - side3));
4344
}

integration-tests/cpp-example/cxx_lib/triangle.hpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

integration-tests/cpp-example/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
33
*/
44

5-
#include "SimpleClass.h"
6-
75
int main(int argc, char** argv) {
86
return 0;
97
}

integration-tests/cpp-example/std/Strings.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

integration-tests/cpp-example/std/Strings.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

server/src/printers/KleePrinter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fs::path KleePrinter::writeTmpKleeFile(
8080
ss << NL;
8181
writeStubsForStructureFields(tests);
8282

83-
writePrivateAccessMacros(typesHandler, tests);
83+
writePrivateAccessMacros(typesHandler, tests, false);
8484

8585
for (const auto &[methodName, testMethod] : tests.methods) {
8686
if (!methodFilter(testMethod)) {
@@ -354,8 +354,7 @@ void KleePrinter::genReturnDeclaration(const Tests::MethodDescription &testMetho
354354
: testMethod.returnType;
355355
bool maybeArray = returnType.maybeReturnArray();
356356
bool isPointer = testMethod.returnType.isObjectPointer();
357-
auto baseType = returnType.baseType();
358-
ss << TAB_N() << returnType.baseType() << " " << KleeUtils::RESULT_VARIABLE_NAME;
357+
strDeclareVar(returnType.baseType(), KleeUtils::RESULT_VARIABLE_NAME, std::nullopt, std::nullopt, false);
359358
makeBracketsForStrPredicate(predicateInfo);
360359
if (maybeArray) {
361360
size_t size = types::TypesHandler::getElementsNumberInPointerOneDim(PointerUsage::RETURN);

server/src/printers/Printer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ namespace printer {
9797
if (needDecorate()) {
9898
ss << NameDecorator::decorate(type) << additionalPointers << " "
9999
<< NameDecorator::decorate(name);
100+
} else if (getLanguage() == utbot::Language::CXX) {
101+
ss << types::TypesHandler::cBoolToCpp(std::string(type)) << additionalPointers << " " << name;
100102
} else {
101103
ss << type << additionalPointers << " " << name;
102104
}
@@ -579,7 +581,7 @@ namespace printer {
579581
stubName, "stub", makeStatic);
580582
}
581583

582-
void Printer::writePrivateAccessMacros(types::TypesHandler const *typesHandler, const Tests &tests) {
584+
void Printer::writePrivateAccessMacros(types::TypesHandler const *typesHandler, const Tests &tests, bool onlyChangeable) {
583585
if (srcLanguage == utbot::Language::CXX) {
584586
ss << NL;
585587
strInclude("access_private.hpp");
@@ -588,7 +590,7 @@ namespace printer {
588590
for (const auto &[methodName, testMethod] : tests.methods) {
589591
addAccessor(typesHandler, testMethod.returnType, checkedOnPrivate);
590592
for (const auto& param : testMethod.params) {
591-
if (param.isChangeable()) {
593+
if (!onlyChangeable || param.isChangeable()) {
592594
addAccessor(typesHandler, param.type, checkedOnPrivate);
593595
}
594596
}

server/src/printers/Printer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ namespace printer {
229229
const string& name,
230230
const string& stubName, bool needToTypedef, bool makeStatic);
231231

232-
void writePrivateAccessMacros(types::TypesHandler const *typesHandler, const Tests &tests);
232+
void writePrivateAccessMacros(types::TypesHandler const *typesHandler, const Tests &tests, bool onlyChangeable);
233233

234234
void genStubForStructFunctionPointer(const string& structName,
235235
const string& fieldName,

server/src/printers/TestsPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void TestsPrinter::genHeaders(Tests &tests, const fs::path& generatedHeaderPath)
176176
}
177177
}
178178

179-
writePrivateAccessMacros(typesHandler, tests);
179+
writePrivateAccessMacros(typesHandler, tests, true);
180180
}
181181

182182
static string getTestName(const Tests::MethodDescription &methodDescription, int testNum) {

0 commit comments

Comments
 (0)