Skip to content

Commit c9e1ca7

Browse files
authored
Change representation of char* from string to array (#532)
1 parent 7af7938 commit c9e1ca7

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

server/src/Tests.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,14 +923,17 @@ void KTestObjectParser::getTestParamView(const Tests::MethodDescription &methodD
923923
Tests::TestCaseDescription &testCaseDescription,
924924
const Tests::MethodParam& methodParam,
925925
std::shared_ptr<AbstractValueView> &testParamView) {
926-
auto paramType = methodParam.type.maybeJustPointer() ? methodParam.type.baseTypeObj() : methodParam.type;
926+
const auto usage = types::PointerUsage::PARAMETER;
927+
types::Type paramType = methodParam.type.arrayCloneMultiDim(usage);
928+
auto type = typesHandler.getReturnTypeToCheck(paramType);
929+
927930
if (CollectionUtils::containsKey(methodDescription.functionPointers, methodParam.name)) {
928931
testParamView = testParameterView(
929-
emptyKleeParam, { paramType, methodParam.name }, PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName,
932+
emptyKleeParam, { type, methodParam.name }, PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName,
930933
testCaseDescription.lazyReferences, methodDescription);
931934
} else {
932935
const auto kleeParam = getKleeParamOrThrow(rawKleeParams, methodParam.name);
933-
testParamView = testParameterView(kleeParam, { paramType, methodParam.name }, PointerUsage::PARAMETER,
936+
testParamView = testParameterView(kleeParam, { type, methodParam.name }, PointerUsage::PARAMETER,
934937
testCaseDescription.lazyAddressToName, testCaseDescription.lazyReferences,
935938
methodDescription);
936939
}

server/test/framework/Regression_Tests.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,16 @@ namespace {
244244
auto predicate = [](const tests::Tests::MethodTestCase &testCase) {
245245
auto s = testCase.paramValues[0].view->getEntryValue(nullptr);
246246
s = s.substr(1, s.length() - 2);
247+
size_t i = 0;
248+
unsigned int sum = 0;
249+
//Hash count of word`s letters
250+
while (s.substr(i, 4) != "'\\0'"){
251+
sum += s[i + 1];
252+
i += 5;// Go to next letter
253+
}
254+
247255
auto actual = testCase.returnValue.view->getEntryValue(nullptr);
248-
auto expected = std::to_string(std::accumulate(s.begin(), s.end(), 0));
256+
auto expected = std::to_string(sum);
249257
return actual == expected;
250258
};
251259

@@ -254,12 +262,12 @@ namespace {
254262
std::vector<TestCasePredicate>(
255263
{ [&predicate](const tests::Tests::MethodTestCase &testCase) {
256264
// empty string
257-
return testCase.paramValues[0].view->getEntryValue(nullptr).length() == 2 &&
265+
return testCase.paramValues[0].view->getEntryValue(nullptr).substr(2, 2) == "\\0" &&
258266
predicate(testCase);
259267
},
260268
[&predicate](const tests::Tests::MethodTestCase &testCase) {
261269
// non-empty string
262-
return testCase.paramValues[0].view->getEntryValue(nullptr).length() > 2 &&
270+
return testCase.paramValues[0].view->getEntryValue(nullptr).substr(2, 2) != "\\0" &&
263271
predicate(testCase);
264272
} }),
265273
"hash");

server/test/framework/Syntax_Tests.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ namespace {
416416
{[] (const tests::Tests::MethodTestCase& testCase) {
417417
auto entryValue = testCase.paramValues[0].view->getEntryValue(nullptr);
418418
auto returnValue = stoll(testCase.returnValue.view->getEntryValue(nullptr));
419-
return static_cast<unsigned char>(entryValue[1]) ==
419+
return static_cast<unsigned char>(entryValue[2]) ==
420420
static_cast<unsigned char>(returnValue);
421421
}
422422
}),
@@ -1187,10 +1187,14 @@ namespace {
11871187
testGen.tests.at(qualifiers_c).methods.begin().value().testCases,
11881188
std::vector<TestCasePredicate>(
11891189
{[] (const tests::Tests::MethodTestCase& testCase) {
1190-
return testCase.paramValues[0].view->getEntryValue(nullptr) == "\"hello\"" && stoi(testCase.returnValue.view->getEntryValue(nullptr)) == 1;
1190+
auto param_values = testCase.paramValues[0].view->getEntryValue(nullptr);
1191+
const int word_end = 31; //End of word "hello" in param_values string
1192+
return param_values == ("{'h', 'e', 'l', 'l', 'o', '\\0'," + param_values.substr(word_end)) && stoi(testCase.returnValue.view->getEntryValue(nullptr)) == 1;
11911193
},
11921194
[] (const tests::Tests::MethodTestCase& testCase) {
1193-
return testCase.paramValues[0].view->getEntryValue(nullptr) != "\"hello\"" && stoi(testCase.returnValue.view->getEntryValue(nullptr)) == 0;
1195+
auto param_values = testCase.paramValues[0].view->getEntryValue(nullptr);
1196+
const int word_end = 31; //End of word "hello" in param_values string
1197+
return param_values != ("{'h', 'e', 'l', 'l', 'o', '\\0'," + param_values.substr(word_end)) && stoi(testCase.returnValue.view->getEntryValue(nullptr)) == 0;
11941198
}
11951199
})
11961200
);

0 commit comments

Comments
 (0)