예제 #1
0
    // Read the records and verify the consistency.
    void readRecords (RandomAccessFile& file,
                      int numRecords,
                      HeapBlock <Record> const& records,
                      std::int64_t seedValue)
    {
        using namespace UnitTestUtilities;

        for (int i = 0; i < numRecords; ++i)
        {
            Record const& record (records [i]);

            int const bytes = record.bytes;

            Payload p1 (bytes);
            Payload p2 (bytes);

            p1.repeatableRandomFill (bytes, bytes, record.index + seedValue);

            file.setPosition (record.offset);

            Result result = file.read (p2.data.getData (), bytes);

            expect (result.wasOk (), "Should be ok");

            if (result.wasOk ())
            {
                p2.bytes = bytes;

                expect (p1 == p2, "Should be equal");
            }
        }
    }
예제 #2
0
    // Write all the records to the file.
    // The payload is pseudo-randomly generated.
    void writeRecords (RandomAccessFile& file,
                       int numRecords,
                       HeapBlock <Record> const& records,
                       std::int64_t seedValue)
    {
        using namespace UnitTestUtilities;

        for (int i = 0; i < numRecords; ++i)
        {
            Payload p (records [i].bytes);

            p.repeatableRandomFill (records [i].bytes,
                                    records [i].bytes,
                                    records [i].index + seedValue);

            file.setPosition (records [i].offset);

            Result result = file.write (p.data.getData (), p.bytes);

            expect (result.wasOk (), "Should be ok");
        }
    }