mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
tests: Add fuzzing harness for functions/classes in flatfile.h
This commit is contained in:
30
src/test/fuzz/flatfile.cpp
Normal file
30
src/test/fuzz/flatfile.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <flatfile.h>
|
||||
#include <optional.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
Optional<FlatFilePos> flat_file_pos = ConsumeDeserializable<FlatFilePos>(fuzzed_data_provider);
|
||||
if (!flat_file_pos) {
|
||||
return;
|
||||
}
|
||||
Optional<FlatFilePos> another_flat_file_pos = ConsumeDeserializable<FlatFilePos>(fuzzed_data_provider);
|
||||
if (another_flat_file_pos) {
|
||||
assert((*flat_file_pos == *another_flat_file_pos) != (*flat_file_pos != *another_flat_file_pos));
|
||||
}
|
||||
(void)flat_file_pos->ToString();
|
||||
flat_file_pos->SetNull();
|
||||
assert(flat_file_pos->IsNull());
|
||||
}
|
||||
Reference in New Issue
Block a user