10using namespace stdex::stream;
12using namespace Microsoft::VisualStudio::CppUnitTestFramework;
22 constexpr uint32_t total = 1000;
26 for (uint32_t i = 0; i < total; ++i) {
27 Assert::IsTrue(writer.ok());
31 Assert::AreEqual<stdex::stream::fpos_t>(0, source.seekbeg(0));
35 for (uint32_t i = 0; i < total; ++i) {
37 Assert::IsTrue(reader.ok());
38 Assert::AreEqual(i, x);
41 Assert::IsFalse(reader.ok());
47 constexpr uint32_t total = 1000;
51 sstring filename2, filename3;
52 filename2 = filename3 = temp_path();
53 filename2 += _T(
"stdex-stream-replicator-2.tmp");
56 mode_for_reading | mode_for_writing | mode_create | mode_binary);
58 filename3 += _T(
"stdex-stream-replicator-3.tmp");
61 mode_for_reading | mode_for_writing | mode_create | mode_binary,
70 for (uint32_t i = 0; i < total; ++i) {
71 Assert::IsTrue(writer.
ok());
82 for (uint32_t i = 0; i < total; ++i) {
84 Assert::IsTrue(f1.ok());
85 Assert::AreEqual(i, x);
87 Assert::IsTrue(f2_buf.ok());
88 Assert::AreEqual(i, x);
90 Assert::IsTrue(f3.ok());
91 Assert::AreEqual(i, x);
94 Assert::IsFalse(f1.ok());
96 Assert::IsFalse(f2_buf.ok());
98 Assert::IsFalse(f3.ok());
102 std::filesystem::remove(filename2);
104 std::filesystem::remove(filename3);
107 TEST_METHOD(open_close)
109 cached_file dat(invalid_handle, state_t::fail, 4096);
110 const sstring filepath = temp_path();
111 constexpr uint32_t count = 3;
112 sstring filename[count];
113 stdex::stream::fpos_t start[count];
114 for (uint32_t i = 0; i < count; ++i) {
115 filename[i] = filepath + sprintf(_T(
"stdex-stream-open_close%u.tmp"), NULL, i);
116 dat.open(filename[i].c_str(), mode_for_reading | mode_for_writing | share_none | mode_preserve_existing | mode_binary);
117 Assert::IsTrue(dat.ok());
118 start[i] = dat.tell();
119 Assert::AreNotEqual(fpos_max, start[i]);
120 for (uint32_t j = 0; j < 31 + 11 * i; ++j) {
121 dat << j * count + i;
122 Assert::IsTrue(dat.ok());
126 for (uint32_t i = 0; i < count; ++i) {
127 dat.open(filename[i].c_str(), mode_for_reading | mode_open_existing | share_none | mode_binary);
128 Assert::IsTrue(dat.ok());
134 Assert::AreEqual(i, x % count);
138 for (uint32_t i = 0; i < count; ++i)
139 std::filesystem::remove(filename[i]);
142 TEST_METHOD(file_stat)
144 sstring path(temp_path());
150 static sstring temp_path()
153 TCHAR temp_path[MAX_PATH];
154 Assert::IsTrue(ExpandEnvironmentStrings(_T(
"%TEMP%\\"), temp_path, _countof(temp_path)) < MAX_PATH);
Provides read-ahead stream capability.
Definition stream.hpp:1246
Provides write-back stream capability.
Definition stream.hpp:1313
bool ok() const
Returns true if the stream state is clean i.e. previous operation was succesful.
Definition stream.hpp:175
Buffered read/write stream.
Definition stream.hpp:1384
Cached file-system file.
Definition stream.hpp:3099
File-system file.
Definition stream.hpp:2691
static bool readonly(const stdex::schar_t *filename)
Checks if file/folder/symlink is read-only.
Definition stream.hpp:3069
static bool exists(const stdex::schar_t *filename)
Checks if file/folder/symlink likely exists.
Definition stream.hpp:3041
In-memory file.
Definition stream.hpp:3183
Replicates writing of the same data to multiple streams.
Definition stream.hpp:1077
void push_back(basic *source)
Adds stream on the list.
Definition stream.hpp:1096