aboutsummaryrefslogtreecommitdiff
path: root/src/test/streams_tests.cpp
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-09-26 13:46:19 +0100
committerfanquake <fanquake@gmail.com>2023-09-26 14:01:44 +0100
commitc9f288244b8d183e09a917025922b99e3368ef78 (patch)
tree564eb028ffe4a696d0463768051c85cb0a50cf51 /src/test/streams_tests.cpp
parentdcfbf3c2107c3cb9d343ebfa0eee78278dea8d66 (diff)
parentfa56c421be04af846f479c30749b17e6663ab418 (diff)
Merge bitcoin/bitcoin#28483: refactor: Return CAutoFile from BlockManager::Open*File()
fa56c421be04af846f479c30749b17e6663ab418 Return CAutoFile from BlockManager::Open*File() (MarcoFalke) 9999b89cd37fb2a23c5ebcd91d9cb31d69375933 Make BufferedFile to be a CAutoFile wrapper (MarcoFalke) fa389d902fbf5fac19fba8c5d0c5e0a25f15ca63 refactor: Drop unused fclose() from BufferedFile (MarcoFalke) Pull request description: This is required for https://github.com/bitcoin/bitcoin/pull/28052, but makes sense on its own, because offloading logic to `CAutoFile` instead of re-implementing it allows to delete code and complexity. ACKs for top commit: TheCharlatan: Re-ACK fa56c421be04af846f479c30749b17e6663ab418 willcl-ark: tACK fa56c421be Tree-SHA512: fe4638f3a6bd3f9d968cfb9ae3259c9d6cd278fe2912cbc90289851311c8c781099db4c160e775960975c4739098d9af801a8d2d12603f371f8edfe134d8f85a
Diffstat (limited to 'src/test/streams_tests.cpp')
-rw-r--r--src/test/streams_tests.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp
index 99740ee779..8ff65b5377 100644
--- a/src/test/streams_tests.cpp
+++ b/src/test/streams_tests.cpp
@@ -249,18 +249,18 @@ BOOST_AUTO_TEST_CASE(streams_serializedata_xor)
BOOST_AUTO_TEST_CASE(streams_buffered_file)
{
fs::path streams_test_filename = m_args.GetDataDirBase() / "streams_test_tmp";
- FILE* file = fsbridge::fopen(streams_test_filename, "w+b");
+ CAutoFile file{fsbridge::fopen(streams_test_filename, "w+b"), 333};
// The value at each offset is the offset.
for (uint8_t j = 0; j < 40; ++j) {
- fwrite(&j, 1, 1, file);
+ file << j;
}
- rewind(file);
+ std::rewind(file.Get());
// The buffer size (second arg) must be greater than the rewind
// amount (third arg).
try {
- BufferedFile bfbad{file, 25, 25, 333};
+ BufferedFile bfbad{file, 25, 25};
BOOST_CHECK(false);
} catch (const std::exception& e) {
BOOST_CHECK(strstr(e.what(),
@@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
}
// The buffer is 25 bytes, allow rewinding 10 bytes.
- BufferedFile bf{file, 25, 10, 333};
+ BufferedFile bf{file, 25, 10};
BOOST_CHECK(!bf.eof());
// This member has no functional effect.
@@ -375,7 +375,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
BOOST_CHECK(bf.GetPos() <= 30U);
// We can explicitly close the file, or the destructor will do it.
- bf.fclose();
+ file.fclose();
fs::remove(streams_test_filename);
}
@@ -383,15 +383,15 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
BOOST_AUTO_TEST_CASE(streams_buffered_file_skip)
{
fs::path streams_test_filename = m_args.GetDataDirBase() / "streams_test_tmp";
- FILE* file = fsbridge::fopen(streams_test_filename, "w+b");
+ CAutoFile file{fsbridge::fopen(streams_test_filename, "w+b"), 333};
// The value at each offset is the byte offset (e.g. byte 1 in the file has the value 0x01).
for (uint8_t j = 0; j < 40; ++j) {
- fwrite(&j, 1, 1, file);
+ file << j;
}
- rewind(file);
+ std::rewind(file.Get());
// The buffer is 25 bytes, allow rewinding 10 bytes.
- BufferedFile bf{file, 25, 10, 333};
+ BufferedFile bf{file, 25, 10};
uint8_t i;
// This is like bf >> (7-byte-variable), in that it will cause data
@@ -425,7 +425,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_skip)
bf.SkipTo(13);
BOOST_CHECK_EQUAL(bf.GetPos(), 13U);
- bf.fclose();
+ file.fclose();
fs::remove(streams_test_filename);
}
@@ -436,16 +436,16 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
fs::path streams_test_filename = m_args.GetDataDirBase() / "streams_test_tmp";
for (int rep = 0; rep < 50; ++rep) {
- FILE* file = fsbridge::fopen(streams_test_filename, "w+b");
+ CAutoFile file{fsbridge::fopen(streams_test_filename, "w+b"), 333};
size_t fileSize = InsecureRandRange(256);
for (uint8_t i = 0; i < fileSize; ++i) {
- fwrite(&i, 1, 1, file);
+ file << i;
}
- rewind(file);
+ std::rewind(file.Get());
size_t bufSize = InsecureRandRange(300) + 1;
size_t rewindSize = InsecureRandRange(bufSize);
- BufferedFile bf{file, bufSize, rewindSize, 333};
+ BufferedFile bf{file, bufSize, rewindSize};
size_t currentPos = 0;
size_t maxPos = 0;
for (int step = 0; step < 100; ++step) {