Skip to content

Commit 086ea79

Browse files
committed
add test
1 parent 1444cd8 commit 086ea79

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

test/testio.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,23 @@ class TestIO : public TestFixture {
693693
" fwrite(X::data(), sizeof(char), buffer.size(), d->file);\n"
694694
"}");
695695
ASSERT_EQUALS("[test.cpp:9:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\n", errout_str());
696+
697+
check("struct MemStream {\n"
698+
" char buf[1024];\n"
699+
" int pos = 0;\n"
700+
" void fwrite(const void *ptr, size_t n) { memcpy(buf + pos, ptr, n); pos += (int)n; }\n"
701+
"};\n"
702+
"struct FileStream {\n"
703+
" FILE *fp;\n"
704+
" size_t _fread(void *ptr, size_t n) { return ::fread(ptr, 1, n, fp); }\n"
705+
" size_t fread(void *ptr, size_t n) { return _fread(ptr, n); }\n"
706+
" void copy_to(MemStream *dst, size_t n) {\n"
707+
" char tmp[256];\n"
708+
" fread(tmp, n);\n"
709+
" dst->fwrite(tmp, n);\n"
710+
" }\n"
711+
"};\n");
712+
ASSERT_EQUALS("", errout_str());
696713
}
697714

698715
void seekOnAppendedFile() {

0 commit comments

Comments
 (0)