Bitcoin Core 22.99.0
P2P Digital Currency
parse_iso8601.cpp
Go to the documentation of this file.
1// Copyright (c) 2019-2020 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6#include <test/fuzz/fuzz.h>
7#include <util/time.h>
8
9#include <cassert>
10#include <cstdint>
11#include <string>
12#include <vector>
13
14FUZZ_TARGET(parse_iso8601)
15{
16 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
17
18 const int64_t random_time = fuzzed_data_provider.ConsumeIntegral<int32_t>();
19 const std::string random_string = fuzzed_data_provider.ConsumeRemainingBytesAsString();
20
21 const std::string iso8601_datetime = FormatISO8601DateTime(random_time);
22 const int64_t parsed_time_1 = ParseISO8601DateTime(iso8601_datetime);
23 if (random_time >= 0) {
24 assert(parsed_time_1 >= 0);
25 if (iso8601_datetime.length() == 20) {
26 assert(parsed_time_1 == random_time);
27 }
28 }
29
30 const int64_t parsed_time_2 = ParseISO8601DateTime(random_string);
31 assert(parsed_time_2 >= 0);
32}
std::string ConsumeRemainingBytesAsString()
FUZZ_TARGET(parse_iso8601)
int64_t ParseISO8601DateTime(const std::string &str)
Definition: time.cpp:158
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
Definition: time.cpp:132
assert(!tx.IsCoinBase())