ios: Add diagstreambuf

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
2023-07-25 12:38:20 +02:00
parent 07f42442e0
commit 516b428d4b
3 changed files with 359 additions and 5 deletions

View File

@@ -55,5 +55,53 @@ namespace UnitTests
Assert::IsTrue(f.good());
Assert::IsTrue(val == data[_countof(data) - 2]);
}
TEST_METHOD(diagstream)
{
constexpr size_t n = 3;
{
unique_ptr<ofstream> f[n];
vector<ofstream*> fv(n);
for (size_t i = 0; i < n; ++i)
{
WCHAR path[MAX_PATH];
ExpandEnvironmentStringsW(stdex::sprintf(L"%%temp%%\\file%zu.dat", NULL, i).c_str(), path, _countof(path));
f[i].reset(new ofstream(path, ios_base::out | ios_base::binary));
fv[i] = f[i].get();
}
stdex::odiagstream d(fv.begin(), fv.end(), 8);
srand(0);
auto write_some_random = [](_Inout_ ostream& f, _In_ size_t amount)
{
for (size_t i = 0; i < amount; ++i) {
auto r = static_cast<uint32_t>(rand());
f.write(reinterpret_cast<const char*>(&r), sizeof(r) / sizeof(char));
}
};
write_some_random(d, 15);
d.seekp(3);
write_some_random(d, 2);
d.seekp(28);
write_some_random(d, 7);
}
{
unique_ptr<ifstream> f[n];
vector<ifstream*> fv(n);
for (size_t i = 0; i < n; ++i)
{
WCHAR path[MAX_PATH];
ExpandEnvironmentStringsW(stdex::sprintf(L"%%temp%%\\file%zu.dat", NULL, i).c_str(), path, _countof(path));
f[i].reset(new ifstream(path, ios_base::in | ios_base::binary));
fv[i] = f[i].get();
}
stdex::idiagstream d(fv.begin(), fv.end(), 8);
do {
uint32_t r;
d.read(reinterpret_cast<char*>(&r), sizeof(r) / sizeof(char));
} while (!d.eof());
}
}
};
}

View File

@@ -24,3 +24,5 @@
#include <stdex/vector_queue.hpp>
#include <CppUnitTest.h>
#include <cstdlib>