Fix test.

This commit is contained in:
Victor Zverovich 2014-05-03 13:18:58 -07:00
parent b808503bc1
commit 7b2568a3a9

View File

@ -268,7 +268,7 @@ std::string Read(File &f, std::size_t count) {
} }
#define EXPECT_READ(file, expected_content) \ #define EXPECT_READ(file, expected_content) \
EXPECT_EQ(expected_content, Read(f, std::strlen(expected_content))) EXPECT_EQ(expected_content, Read(file, std::strlen(expected_content)))
TEST(FileTest, Read) { TEST(FileTest, Read) {
File f(".travis.yml", File::RDONLY); File f(".travis.yml", File::RDONLY);
@ -282,19 +282,19 @@ TEST(FileTest, ReadError) {
} }
TEST(FileTest, Write) { TEST(FileTest, Write) {
// TODO: use pipes const char MESSAGE[] = "test";
const char EXPECTED[] = "test"; File read_end;
{ {
File f("out", File::WRONLY); File write_end;
enum { SIZE = sizeof(EXPECTED) - 1 }; File::pipe(read_end, write_end);
enum { SIZE = sizeof(MESSAGE) - 1 };
std::streamsize offset = 0, count = 0; std::streamsize offset = 0, count = 0;
do { do {
count = f.write(EXPECTED + offset, SIZE - offset); count = write_end.write(MESSAGE + offset, SIZE - offset);
offset += count; offset += count;
} while (offset < SIZE && count != 0); } while (offset < SIZE && count != 0);
} }
File f("out", File::RDONLY); EXPECT_READ(read_end, MESSAGE);
EXPECT_READ(f, EXPECTED);
} }
TEST(FileTest, Dup) { TEST(FileTest, Dup) {