File tree Expand file tree Collapse file tree 7 files changed +45
-3
lines changed Expand file tree Collapse file tree 7 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -725,6 +725,9 @@ size_t KTestObjectParser::getOffsetInStruct(Tests::TypeAndVarName &objTypeAndNam
725
725
size_t sizeInBits = typesHandler.typeSize (objTypeAndName.type );
726
726
size_t offset = offsetInBits / sizeInBits;
727
727
PrinterUtils::appendIndicesToVarName (objTypeAndName.varName , sizes, offset);
728
+ if (objTypeAndName.type .isConstQualifiedValue ()) {
729
+ PrinterUtils::appendConstCast (objTypeAndName.varName );
730
+ }
728
731
offsetInBits %= sizeInBits;
729
732
return offsetInBits;
730
733
}
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ namespace printer {
14
14
ss << NL;
15
15
ss << PrinterUtils::redirectStdin << NL;
16
16
ss << PrinterUtils::writeToFile << NL;
17
- ss << PrinterUtils::fromBytes;
17
+ ss << PrinterUtils::fromBytes << NL;
18
+ ss << PrinterUtils::constCast;
18
19
headerCode += ss.str ();
19
20
FileSystemUtils::writeToFile (testHeaderFilePath, headerCode);
20
21
}
Original file line number Diff line number Diff line change @@ -68,6 +68,13 @@ namespace PrinterUtils {
68
68
varName += indices;
69
69
}
70
70
71
+ void appendConstCast (std::string &varName) {
72
+ if (varName.empty ()) {
73
+ return ;
74
+ }
75
+ varName = StringUtils::stringFormat (" constCast(%s)" , varName);
76
+ }
77
+
71
78
std::string initializePointer (const std::string &type,
72
79
const std::string &value,
73
80
size_t additionalPointersCount,
Original file line number Diff line number Diff line change 12
12
#include < string>
13
13
14
14
namespace PrinterUtils {
15
+ const std::string constCast = " template<typename T>\n "
16
+ " T& constCast(const T &val) {\n "
17
+ " return const_cast<T&>(val);\n "
18
+ " }\n " ;
19
+
15
20
const std::string fromBytes = " template<typename T, size_t N>\n "
16
21
" T from_bytes(const char (&bytes)[N]) {\n "
17
22
" T result;\n "
@@ -81,6 +86,8 @@ namespace PrinterUtils {
81
86
82
87
void appendIndicesToVarName (std::string &varName, const std::vector<size_t > &sizes, size_t offset);
83
88
89
+ void appendConstCast (std::string &varName);
90
+
84
91
std::string getKleePrefix (bool forKlee);
85
92
86
93
std::string wrapUserValue (const testsgen::ValidationType &type, const std::string &value);
Original file line number Diff line number Diff line change @@ -2120,7 +2120,7 @@ namespace {
2120
2120
auto testGen = FileTestGen (*request, writer.get (), TESTMODE);
2121
2121
Status status = Server::TestsGenServiceImpl::ProcessBaseTestRequest (testGen, writer.get ());
2122
2122
ASSERT_TRUE (status.ok ()) << status.error_message ();
2123
- EXPECT_GE (testUtils::getNumberOfTests (testGen.tests ), 2 );
2123
+ EXPECT_GE (testUtils::getNumberOfTests (testGen.tests ), 4 );
2124
2124
2125
2125
fs::path testsDirPath = getTestFilePath (" tests" );
2126
2126
@@ -2146,7 +2146,7 @@ namespace {
2146
2146
auto resultsMap = coverageGenerator.getTestResultMap ();
2147
2147
auto tests = coverageGenerator.getTestsToLaunch ();
2148
2148
2149
- StatusCountMap expectedStatusCountMap{ { testsgen::TEST_PASSED, 2 } };
2149
+ StatusCountMap expectedStatusCountMap{ { testsgen::TEST_PASSED, 4 } };
2150
2150
testUtils::checkStatuses (resultsMap, tests);
2151
2151
}
2152
2152
Original file line number Diff line number Diff line change @@ -24,3 +24,25 @@ int func_with_multi_dim_pointer(struct MainStruct **str) {
24
24
}
25
25
return sz ;
26
26
}
27
+
28
+ int func_with_multi_dim_pointer_to_const (const struct MainStruct * * str ) {
29
+ if (!str ) {
30
+ return 0 ;
31
+ }
32
+ str ++ ;
33
+ struct MainStruct * ptr = * str ;
34
+ int sz = 0 ;
35
+ if (ptr ) {
36
+ struct ElementStruct * e = ptr -> list .head ;
37
+ struct ElementStruct * n ;
38
+ for (int i = 0 ; i < 5 ; i ++ ) {
39
+ if (e ) {
40
+ n = e -> next ;
41
+ sz ++ ;
42
+ } else {
43
+ break ;
44
+ }
45
+ }
46
+ }
47
+ return sz ;
48
+ }
Original file line number Diff line number Diff line change @@ -19,4 +19,6 @@ struct MainStruct {
19
19
20
20
int func_with_multi_dim_pointer (struct MainStruct * * str );
21
21
22
+ int func_with_multi_dim_pointer_to_const (const struct MainStruct * * str );
23
+
22
24
#endif // UNITTESTBOT_MULTI_DIM_POINTERS_H
You can’t perform that action at this time.
0 commit comments