Esempio n. 1
0
void VFSNodeUnit::_testBinaryFileIO(const VString& seriesLabel, VFSNode& node, VAbstractFileStream& fileStream) {
    // This output line is just to mark which kind of file i/o we're doing:
    this->logStatus(seriesLabel);

    VBinaryIOStream io(fileStream);

    fileStream.openWrite();

    io.writeS8(1);
    io.writeU8(2);
    io.writeS16(3);
    io.writeU16(4);
    io.writeS32(5L);
    io.writeU32(6L);
    io.writeS64(CONST_S64(7));
    io.writeU64(CONST_U64(8));
    io.writeFloat(9.9f);
    io.writeDouble(3.1415926);
    io.writeBool(true);
    io.writeString("hello");
    io.flush();

    fileStream.close();

    VUNIT_ASSERT_TRUE_LABELED(node.size() != 0, "non-empty file");
    VUNIT_ASSERT_TRUE_LABELED(node.isFile(), "is file");
    VUNIT_ASSERT_FALSE_LABELED(node.isDirectory(), "is not directory");

    fileStream.openReadOnly();

    VUNIT_ASSERT_TRUE_LABELED(io.readS8() == 1, "S8 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readU8() == 2, "U8 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readS16() == 3, "S16 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readU16() == 4, "U16 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readS32() == 5L, "S32 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readU32() == 6L, "U32 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readS64() == CONST_S64(7), "S64 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readU64() == CONST_U64(8), "U64 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readFloat() == 9.9f, "Float match");
    VUNIT_ASSERT_TRUE_LABELED(io.readDouble() == 3.1415926, "Double match");
    VUNIT_ASSERT_TRUE_LABELED(io.readBool() == true, "Bool match");
    VUNIT_ASSERT_TRUE_LABELED(io.readString() == "hello", "String match");
    try {
        // We should not be able to read any more data.
        (void) io.readU8();
        // If we get here, there's junk past the proper end of the file.
        VUNIT_ASSERT_FAILURE("EOF mark position");
    } catch (const VEOFException& /*ex*/) {
        VUNIT_ASSERT_SUCCESS("EOF mark position");
    } catch (...) {
        VUNIT_ASSERT_FAILURE("EOF mark position (unexpected exception type)");
    }

    fileStream.close();
}
Esempio n. 2
0
void VFSNodeUnit::_testTextFileIO(const VString& seriesLabel, VFSNode& node, VAbstractFileStream& fileStream) {
    // This output line is just to mark which kind of file i/o we're doing:
    this->logStatus(seriesLabel);

    VTextIOStream io(fileStream);
    fileStream.openWrite();

    for (VStringVector::const_iterator i = mTextFileLines.begin(); i != mTextFileLines.end(); ++i)
        io.writeLine(*i);

    io.flush();

    fileStream.close();

    VUNIT_ASSERT_TRUE_LABELED(node.size() != 0, "non-empty file");
    VUNIT_ASSERT_TRUE_LABELED(node.isFile(), "is file");
    VUNIT_ASSERT_FALSE_LABELED(node.isDirectory(), "is not directory");

    fileStream.openReadOnly();

    VString line;
    int lineNumber = 1;
    for (VStringVector::const_iterator i = mTextFileLines.begin(); i != mTextFileLines.end(); ++i) {
        io.readLine(line);
        VUNIT_ASSERT_EQUAL_LABELED(line, *i, VSTRING_FORMAT("Line %d match", lineNumber));
        ++lineNumber;
    }

    try {
        // We should not be able to read any more lines.
        io.readLine(line);
        // If we get here, there's junk past the proper end of the file.
        VUNIT_ASSERT_FAILURE("EOF mark position");
    } catch (const VEOFException& /*ex*/) {
        VUNIT_ASSERT_SUCCESS("EOF mark position");
    } catch (...) {
        VUNIT_ASSERT_FAILURE("EOF mark position (unexpected exception type)");
    }

    fileStream.close();
}
Esempio n. 3
0
// static
void VFSNode::copyFile(const VFSNode& source, const VFSNode& dest) {
    VBufferedFileStream fs(source);
    fs.openReadOnly();
    VBinaryIOStream in(fs);
    VFSNode::safelyOverwriteFile(dest, source.size(), in);
}