Changeset View
Changeset View
Standalone View
Standalone View
src/test/fuzz/locale.cpp
// Copyright (c) 2020 The Bitcoin Core developers | // Copyright (c) 2020 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/string.h> | |||||
#include <test/fuzz/FuzzedDataProvider.h> | #include <test/fuzz/FuzzedDataProvider.h> | ||||
#include <test/fuzz/fuzz.h> | #include <test/fuzz/fuzz.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <cassert> | #include <cassert> | ||||
#include <clocale> | #include <clocale> | ||||
▲ Show 20 Lines • Show All 786 Lines • ▼ Show 20 Lines | void test_one_input(const std::vector<uint8_t> &buffer) { | ||||
int64_t parseint64_out_without_locale; | int64_t parseint64_out_without_locale; | ||||
const bool parseint64_without_locale = | const bool parseint64_without_locale = | ||||
ParseInt64(random_string, &parseint64_out_without_locale); | ParseInt64(random_string, &parseint64_out_without_locale); | ||||
const int64_t atoi64_without_locale = atoi64(random_string); | const int64_t atoi64_without_locale = atoi64(random_string); | ||||
const int atoi_without_locale = atoi(random_string); | const int atoi_without_locale = atoi(random_string); | ||||
const int64_t atoi64c_without_locale = atoi64(random_string.c_str()); | const int64_t atoi64c_without_locale = atoi64(random_string.c_str()); | ||||
const int64_t random_int64 = | const int64_t random_int64 = | ||||
fuzzed_data_provider.ConsumeIntegral<int64_t>(); | fuzzed_data_provider.ConsumeIntegral<int64_t>(); | ||||
const std::string i64tostr_without_locale = i64tostr(random_int64); | const std::string tostring_without_locale = ToString(random_int64); | ||||
const int32_t random_int32 = | const int32_t random_int32 = | ||||
fuzzed_data_provider.ConsumeIntegral<int32_t>(); | fuzzed_data_provider.ConsumeIntegral<int32_t>(); | ||||
const std::string strprintf_int_without_locale = | const std::string strprintf_int_without_locale = | ||||
strprintf("%d", random_int64); | strprintf("%d", random_int64); | ||||
const double random_double = | const double random_double = | ||||
fuzzed_data_provider.ConsumeFloatingPoint<double>(); | fuzzed_data_provider.ConsumeFloatingPoint<double>(); | ||||
const std::string strprintf_double_without_locale = | const std::string strprintf_double_without_locale = | ||||
strprintf("%f", random_double); | strprintf("%f", random_double); | ||||
Show All 16 Lines | if (parseint64_without_locale) { | ||||
assert(parseint64_out_without_locale == parseint64_out_with_locale); | assert(parseint64_out_without_locale == parseint64_out_with_locale); | ||||
} | } | ||||
const int64_t atoi64_with_locale = atoi64(random_string); | const int64_t atoi64_with_locale = atoi64(random_string); | ||||
assert(atoi64_without_locale == atoi64_with_locale); | assert(atoi64_without_locale == atoi64_with_locale); | ||||
const int64_t atoi64c_with_locale = atoi64(random_string.c_str()); | const int64_t atoi64c_with_locale = atoi64(random_string.c_str()); | ||||
assert(atoi64c_without_locale == atoi64c_with_locale); | assert(atoi64c_without_locale == atoi64c_with_locale); | ||||
const int atoi_with_locale = atoi(random_string); | const int atoi_with_locale = atoi(random_string); | ||||
assert(atoi_without_locale == atoi_with_locale); | assert(atoi_without_locale == atoi_with_locale); | ||||
const std::string i64tostr_with_locale = i64tostr(random_int64); | const std::string tostring_with_locale = ToString(random_int64); | ||||
assert(i64tostr_without_locale == i64tostr_with_locale); | assert(tostring_without_locale == tostring_with_locale); | ||||
const std::string strprintf_int_with_locale = strprintf("%d", random_int64); | const std::string strprintf_int_with_locale = strprintf("%d", random_int64); | ||||
assert(strprintf_int_without_locale == strprintf_int_with_locale); | assert(strprintf_int_without_locale == strprintf_int_with_locale); | ||||
const std::string strprintf_double_with_locale = | const std::string strprintf_double_with_locale = | ||||
strprintf("%f", random_double); | strprintf("%f", random_double); | ||||
assert(strprintf_double_without_locale == strprintf_double_with_locale); | assert(strprintf_double_without_locale == strprintf_double_with_locale); | ||||
const std::locale current_cpp_locale; | const std::locale current_cpp_locale; | ||||
assert(current_cpp_locale == std::locale::classic()); | assert(current_cpp_locale == std::locale::classic()); | ||||
} | } |