Ejemplo n.º 1
0
// Tests reading and writing of a single long variant from and to binary files
TEST_F(TestVariant, FileIOBinaryIOMultipleTypes) {
    BinaryFileStream stream;

    // Values we'll be testing for
    long value1 = 123;
    std::string value2 = "test";
    auto value3 = nullptr;

    // Initialize variants
    Variant variant1(value1);
    Variant variant2(value2);
    Variant variant3(value3);

    // Open stream for writing
    stream.open(filename, std::ios::out);

    // Write variants
    stream << variant1;
    stream << variant2;
    stream << variant3;

    // Close stream
    stream.close();

    // Open stream for reading
    stream.open(filename, std::ios::in);

    // Initialize a final variant for storage of data read from the stream
    Variant variant("a value that must not conflict with the tests");

    stream >> variant;
    EXPECT_EQ(variant, value1);

    stream >> variant;
    EXPECT_EQ(variant, value2);

    stream >> variant;
    EXPECT_EQ(variant, value3);

    // Lets make sure this was all the data. We need to read again to set the
    // EOF bit
    char tc;
    EXPECT_FALSE(stream.get(tc));

    // Ensure EOF
    EXPECT_TRUE(stream.eof());

    // Close stream
    stream.close();
}