UnitTests: Fix flacky tests

There were multiple reasons why the tests were flacky. First
Utils::reverseCompare had a bug. Now

std::lexicographical_compare(first.rbegin(), first.rend(),
                             second.rbegin(), second.rend())

is used.

Second the check StorageCache::checkEntries was not const. So it would
change the vector which it was iterating. So the iterator could be an
dangling.

Fixes: QDS-10197
Change-Id: I84fca6a2b24e1cae9fb85a01b6208de7e58240df
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2023-06-29 15:36:24 +02:00
committed by Tim Jenssen
parent cc244f6bed
commit 941e890804
8 changed files with 54 additions and 59 deletions

View File

@@ -131,38 +131,6 @@ constexpr int compare(SmallStringView first, SmallStringView second) noexcept
return first.compare(second);
}
namespace Internal {
constexpr int reverse_memcmp(const char *first, const char *second, size_t n)
{
const char *currentFirst = first + n - 1;
const char *currentSecond = second + n - 1;
while (n > 0) {
// If the current characters differ, return an appropriately signed
// value; otherwise, keep searching backwards
int difference = *currentFirst - *currentSecond;
if (difference != 0)
return difference;
--currentFirst;
--currentSecond;
--n;
}
return 0;
}
} // namespace Internal
constexpr int reverseCompare(SmallStringView first, SmallStringView second) noexcept
{
int difference = Internal::reverse_memcmp(first.data(), second.data(), first.size());
if (difference == 0)
return int(first.size()) - int(second.size());
return difference;
}
} // namespace Utils
constexpr Utils::SmallStringView operator""_sv(const char *const string, size_t size)