2020-12-31 09:48:25 +01:00
|
|
|
// Copyright (c) 2019-2020 The Bitcoin Core developers
|
2019-10-28 16:01:41 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
#include <util/time.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
FUZZ_TARGET(parse_iso8601)
|
2019-10-28 16:01:41 +00:00
|
|
|
{
|
|
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
|
|
|
|
2021-05-09 10:15:00 +02:00
|
|
|
const int64_t random_time = fuzzed_data_provider.ConsumeIntegral<int32_t>();
|
2019-10-28 16:01:41 +00:00
|
|
|
const std::string random_string = fuzzed_data_provider.ConsumeRemainingBytesAsString();
|
|
|
|
|
|
|
|
const std::string iso8601_datetime = FormatISO8601DateTime(random_time);
|
|
|
|
const int64_t parsed_time_1 = ParseISO8601DateTime(iso8601_datetime);
|
|
|
|
if (random_time >= 0) {
|
|
|
|
assert(parsed_time_1 >= 0);
|
|
|
|
if (iso8601_datetime.length() == 20) {
|
|
|
|
assert(parsed_time_1 == random_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const int64_t parsed_time_2 = ParseISO8601DateTime(random_string);
|
|
|
|
assert(parsed_time_2 >= 0);
|
|
|
|
}
|