From 6a5f27bed218eae35412b2dd1773f02e57f84043 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 6 May 2014 09:17:53 -0700 Subject: [PATCH] Add test. --- test/gtest-extra-test.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index 9215fa7c..077bd476 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -504,6 +504,28 @@ TEST(FileTest, Read) { EXPECT_READ(f, "language: cpp"); } +#ifdef _WIN32 +// The count argument to the read function is unsigned on Windows, so check +// if integer overflow is handled properly. +TEST(FileTest, ReadCountOverflow) { + if (sizeof(std::size_t) == sizeof(unsigned)) + return; + File read_end, write_end; + File::pipe(read_end, write_end); + Write(write_end, "test"); + write_end.close(); + char buffer[4]; + std::size_t offset = 0; + std::size_t count = std::numeric_limits::max() + std::size_t(1); + std::streamsize n = 0; + do { + n = read_end.read(buffer + offset, count); + offset += n; + } while (n != 0); + EXPECT_EQ("test", std::string(buffer, offset)); +} +#endif + TEST(FileTest, ReadError) { File read_end, write_end; File::pipe(read_end, write_end);