9 #include <boost/test/unit_test.hpp>
17 unsigned char bytes[] = { 3, 4, 5, 6 };
18 std::vector<unsigned char> vch;
25 BOOST_CHECK((vch == std::vector<unsigned char>{{1, 2}}));
27 BOOST_CHECK((vch == std::vector<unsigned char>{{1, 2}}));
31 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2}}));
33 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2}}));
38 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2, 0}}));
40 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2, 0}}));
45 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 1, 2}}));
47 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 1, 2}}));
52 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 0, 1, 2}}));
54 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 0, 1, 2}}));
58 BOOST_CHECK((vch == std::vector<unsigned char>{{3, 4, 5, 6}}));
60 BOOST_CHECK((vch == std::vector<unsigned char>{{3, 4, 5, 6}}));
65 BOOST_CHECK((vch == std::vector<unsigned char>{{8, 8, 1, 3, 4, 5, 6, 2}}));
67 BOOST_CHECK((vch == std::vector<unsigned char>{{8, 8, 1, 3, 4, 5, 6, 2}}));
75 for (uint8_t j = 0; j < 40; ++j) {
76 fwrite(&j, 1, 1, file);
85 }
catch (
const std::exception& e) {
87 "Rewind limit must be less than buffer size") !=
nullptr);
121 }
catch (
const std::exception& e) {
123 "Read attempted past buffer limit") !=
nullptr);
131 for (uint8_t j = 3; j < 10; ++j) {
164 for (uint8_t j = 0; j <
sizeof(a); ++j) {
174 }
catch (
const std::exception& e) {
176 "CBufferedFile::Fill: end of file") !=
nullptr);
197 fs::remove(
"streams_test_tmp");
205 for (
int rep = 0; rep < 50; ++rep) {
207 size_t fileSize = InsecureRandRange(256);
208 for (uint8_t i = 0; i < fileSize; ++i) {
209 fwrite(&i, 1, 1, file);
213 size_t bufSize = InsecureRandRange(300) + 1;
214 size_t rewindSize = InsecureRandRange(bufSize);
216 size_t currentPos = 0;
218 for (
int step = 0; step < 100; ++step) {
219 if (currentPos >= fileSize)
230 switch (InsecureRandRange(5)) {
233 if (currentPos + 1 > fileSize)
237 for (uint8_t i = 0; i < 1; ++i) {
245 if (currentPos + 2 > fileSize)
249 for (uint8_t i = 0; i < 2; ++i) {
257 if (currentPos + 5 > fileSize)
261 for (uint8_t i = 0; i < 5; ++i) {
269 size_t find = currentPos + InsecureRandRange(8);
270 if (find >= fileSize)
272 bf.
FindByte(
static_cast<char>(find));
285 size_t requestPos = InsecureRandRange(maxPos + 4);
286 bool okay = bf.
SetPos(requestPos);
294 if (requestPos <= maxPos &&
295 maxPos > rewindSize &&
296 requestPos >= maxPos - rewindSize) {
303 if (maxPos < currentPos)
307 fs::remove(
"streams_test_tmp");
Non-refcounted RAII wrapper around a FILE* that implements a ring buffer to deserialize from.
bool SetLimit(uint64_t nPos=std::numeric_limits< uint64_t >::max())
prevent reading beyond a certain position no argument removes the limit
bool SetPos(uint64_t nPos)
rewind to a given reading position
BOOST_AUTO_TEST_SUITE_END()
FILE * fopen(const fs::path &p, const char *mode)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
BOOST_AUTO_TEST_CASE(streams_vector_writer)
@ ZEROS
Seed with a compile time constant of zeros.