Skip to content

Change representation of char* from string to array #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions server/src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,17 @@ void KTestObjectParser::getTestParamView(const Tests::MethodDescription &methodD
Tests::TestCaseDescription &testCaseDescription,
const Tests::MethodParam& methodParam,
std::shared_ptr<AbstractValueView> &testParamView) {
auto paramType = methodParam.type.maybeJustPointer() ? methodParam.type.baseTypeObj() : methodParam.type;
const auto usage = types::PointerUsage::PARAMETER;
types::Type paramType = methodParam.type.arrayCloneMultiDim(usage);
auto type = typesHandler.getReturnTypeToCheck(paramType);

if (CollectionUtils::containsKey(methodDescription.functionPointers, methodParam.name)) {
testParamView = testParameterView(
emptyKleeParam, { paramType, methodParam.name }, PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName,
emptyKleeParam, { type, methodParam.name }, PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName,
testCaseDescription.lazyReferences, methodDescription);
} else {
const auto kleeParam = getKleeParamOrThrow(rawKleeParams, methodParam.name);
testParamView = testParameterView(kleeParam, { paramType, methodParam.name }, PointerUsage::PARAMETER,
testParamView = testParameterView(kleeParam, { type, methodParam.name }, PointerUsage::PARAMETER,
testCaseDescription.lazyAddressToName, testCaseDescription.lazyReferences,
methodDescription);
}
Expand Down
14 changes: 11 additions & 3 deletions server/test/framework/Regression_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,16 @@ namespace {
auto predicate = [](const tests::Tests::MethodTestCase &testCase) {
auto s = testCase.paramValues[0].view->getEntryValue(nullptr);
s = s.substr(1, s.length() - 2);
size_t i = 0;
unsigned int sum = 0;
//Hash count of word`s letters
while (s.substr(i, 4) != "'\\0'"){
sum += s[i + 1];
i += 5;// Go to next letter
}

auto actual = testCase.returnValue.view->getEntryValue(nullptr);
auto expected = std::to_string(std::accumulate(s.begin(), s.end(), 0));
auto expected = std::to_string(sum);
return actual == expected;
};

Expand All @@ -254,12 +262,12 @@ namespace {
std::vector<TestCasePredicate>(
{ [&predicate](const tests::Tests::MethodTestCase &testCase) {
// empty string
return testCase.paramValues[0].view->getEntryValue(nullptr).length() == 2 &&
return testCase.paramValues[0].view->getEntryValue(nullptr).substr(2, 2) == "\\0" &&
predicate(testCase);
},
[&predicate](const tests::Tests::MethodTestCase &testCase) {
// non-empty string
return testCase.paramValues[0].view->getEntryValue(nullptr).length() > 2 &&
return testCase.paramValues[0].view->getEntryValue(nullptr).substr(2, 2) != "\\0" &&
predicate(testCase);
} }),
"hash");
Expand Down
10 changes: 7 additions & 3 deletions server/test/framework/Syntax_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ namespace {
{[] (const tests::Tests::MethodTestCase& testCase) {
auto entryValue = testCase.paramValues[0].view->getEntryValue(nullptr);
auto returnValue = stoll(testCase.returnValue.view->getEntryValue(nullptr));
return static_cast<unsigned char>(entryValue[1]) ==
return static_cast<unsigned char>(entryValue[2]) ==
static_cast<unsigned char>(returnValue);
}
}),
Expand Down Expand Up @@ -1187,10 +1187,14 @@ namespace {
testGen.tests.at(qualifiers_c).methods.begin().value().testCases,
std::vector<TestCasePredicate>(
{[] (const tests::Tests::MethodTestCase& testCase) {
return testCase.paramValues[0].view->getEntryValue(nullptr) == "\"hello\"" && stoi(testCase.returnValue.view->getEntryValue(nullptr)) == 1;
auto param_values = testCase.paramValues[0].view->getEntryValue(nullptr);
const int word_end = 31; //End of word "hello" in param_values string
return param_values == ("{'h', 'e', 'l', 'l', 'o', '\\0'," + param_values.substr(word_end)) && stoi(testCase.returnValue.view->getEntryValue(nullptr)) == 1;
},
[] (const tests::Tests::MethodTestCase& testCase) {
return testCase.paramValues[0].view->getEntryValue(nullptr) != "\"hello\"" && stoi(testCase.returnValue.view->getEntryValue(nullptr)) == 0;
auto param_values = testCase.paramValues[0].view->getEntryValue(nullptr);
const int word_end = 31; //End of word "hello" in param_values string
return param_values != ("{'h', 'e', 'l', 'l', 'o', '\\0'," + param_values.substr(word_end)) && stoi(testCase.returnValue.view->getEntryValue(nullptr)) == 0;
}
})
);
Expand Down