diff options
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r-- | tests/stdio_test.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 31acfec90..a7df78448 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -1093,3 +1093,31 @@ TEST(STDIO_TEST, fseek_ftell_unseekable) { fclose(fp); #endif } + +TEST(STDIO_TEST, lots_of_concurrent_files) { + std::vector<TemporaryFile*> tfs; + std::vector<FILE*> fps; + + for (size_t i = 0; i < 256; ++i) { + TemporaryFile* tf = new TemporaryFile; + tfs.push_back(tf); + FILE* fp = fopen(tf->filename, "w+"); + fps.push_back(fp); + fprintf(fp, "hello %zu!\n", i); + fflush(fp); + } + + for (size_t i = 0; i < 256; ++i) { + rewind(fps[i]); + + char buf[BUFSIZ]; + ASSERT_TRUE(fgets(buf, sizeof(buf), fps[i]) != nullptr); + + char expected[BUFSIZ]; + snprintf(expected, sizeof(expected), "hello %zu!\n", i); + ASSERT_STREQ(expected, buf); + + fclose(fps[i]); + delete tfs[i]; + } +} |