TEST(DataTypeStringData, Basic) {
        char buf[100];
        StringData a("a");
        StringData b("bb");
        StringData c("ccc");

        {
            DataRangeCursor drc(buf, buf + sizeof(buf));

            ASSERT_OK(drc.writeAndAdvance(Terminated<'\0', StringData>(a)));
            ASSERT_OK(drc.writeAndAdvance(Terminated<'\0', StringData>(b)));
            ASSERT_OK(drc.writeAndAdvance(Terminated<'\0', StringData>(c)));

            ASSERT_EQUALS(1 + 2 + 3 + 3, drc.data() - buf);
        }

        {
            ConstDataRangeCursor cdrc(buf, buf + sizeof(buf));

            Terminated<'\0', StringData> tsd;

            ASSERT_OK(cdrc.readAndAdvance(&tsd));
            ASSERT_EQUALS(a, tsd.value);

            ASSERT_OK(cdrc.readAndAdvance(&tsd));
            ASSERT_EQUALS(b, tsd.value);

            ASSERT_OK(cdrc.readAndAdvance(&tsd));
            ASSERT_EQUALS(c, tsd.value);
        }
    }
示例#2
0
TEST(DataRangeCursor, ConstDataRangeCursorType) {
    char buf[] = "foo";

    ConstDataRangeCursor cdrc(buf, buf + sizeof(buf));

    ConstDataRangeCursor out(nullptr, nullptr);

    ASSERT_OK(cdrc.readIntoNoThrow(&out));
    ASSERT_EQUALS(buf, out.data());
}
示例#3
0
TEST(DataRangeCursor, ConstDataRangeCursorType) {
    char buf[] = "foo";

    ConstDataRangeCursor cdrc(buf, buf + sizeof(buf));

    ConstDataRangeCursor out(nullptr, nullptr);

    auto inner = cdrc.read(&out);

    ASSERT_OK(inner);
    ASSERT_EQUALS(buf, out.data());
}
示例#4
0
TEST(DataRangeCursor, DataRangeCursor) {
    char buf[100] = {0};

    DataRangeCursor dc(buf, buf + 14);

    ASSERT_OK(dc.writeAndAdvanceNoThrow<uint16_t>(1));
    ASSERT_OK(dc.writeAndAdvanceNoThrow<LittleEndian<uint32_t>>(2));
    ASSERT_OK(dc.writeAndAdvanceNoThrow<BigEndian<uint64_t>>(3));
    ASSERT_NOT_OK(dc.writeAndAdvanceNoThrow<char>(1));

    ConstDataRangeCursor cdrc(buf, buf + sizeof(buf));

    ASSERT_EQUALS(static_cast<uint16_t>(1), cdrc.readAndAdvance<uint16_t>());
    ASSERT_EQUALS(static_cast<uint32_t>(2), cdrc.readAndAdvance<LittleEndian<uint32_t>>());
    ASSERT_EQUALS(static_cast<uint64_t>(3), cdrc.readAndAdvance<BigEndian<uint64_t>>());
    ASSERT_EQUALS(static_cast<char>(0), cdrc.readAndAdvance<char>());
}
示例#5
0
TEST(DataRangeCursor, DataRangeCursor) {
    char buf[100] = {0};

    DataRangeCursor dc(buf, buf + 14);

    ASSERT_EQUALS(true, dc.writeAndAdvance<uint16_t>(1).isOK());
    ASSERT_EQUALS(true, dc.writeAndAdvance<LittleEndian<uint32_t>>(2).isOK());
    ASSERT_EQUALS(true, dc.writeAndAdvance<BigEndian<uint64_t>>(3).isOK());
    ASSERT_EQUALS(false, dc.writeAndAdvance<char>(1).isOK());

    ConstDataRangeCursor cdrc(buf, buf + sizeof(buf));

    ASSERT_EQUALS(static_cast<uint16_t>(1), cdrc.readAndAdvance<uint16_t>().getValue());
    ASSERT_EQUALS(static_cast<uint32_t>(2),
                  cdrc.readAndAdvance<LittleEndian<uint32_t>>().getValue());
    ASSERT_EQUALS(static_cast<uint64_t>(3), cdrc.readAndAdvance<BigEndian<uint64_t>>().getValue());
    ASSERT_EQUALS(static_cast<char>(0), cdrc.readAndAdvance<char>().getValue());
}
示例#6
0
TEST(DataRangeCursor, ConstDataRangeCursor) {
    char buf[14];

    DataView(buf).write<uint16_t>(1);
    DataView(buf).write<LittleEndian<uint32_t>>(2, sizeof(uint16_t));
    DataView(buf).write<BigEndian<uint64_t>>(3, sizeof(uint16_t) + sizeof(uint32_t));

    ConstDataRangeCursor cdrc(buf, buf + sizeof(buf));
    ConstDataRangeCursor backup(cdrc);

    ASSERT_EQUALS(static_cast<uint16_t>(1), cdrc.readAndAdvance<uint16_t>());
    ASSERT_EQUALS(static_cast<uint32_t>(2), cdrc.readAndAdvance<LittleEndian<uint32_t>>());
    ASSERT_EQUALS(static_cast<uint64_t>(3), cdrc.readAndAdvance<BigEndian<uint64_t>>());
    ASSERT_NOT_OK(cdrc.readAndAdvanceNoThrow<char>());

    // test skip()
    cdrc = backup;
    ASSERT_OK(cdrc.skipNoThrow<uint32_t>());
    ASSERT_OK(cdrc.advanceNoThrow(10));
    ASSERT_NOT_OK(cdrc.readAndAdvanceNoThrow<char>());
}
示例#7
0
TEST(DataRangeCursor, ConstDataRangeCursor) {
    char buf[14];

    DataView(buf).write<uint16_t>(1);
    DataView(buf).write<LittleEndian<uint32_t>>(2, sizeof(uint16_t));
    DataView(buf).write<BigEndian<uint64_t>>(3, sizeof(uint16_t) + sizeof(uint32_t));

    ConstDataRangeCursor cdrc(buf, buf + sizeof(buf));
    ConstDataRangeCursor backup(cdrc);

    ASSERT_EQUALS(static_cast<uint16_t>(1), cdrc.readAndAdvance<uint16_t>().getValue());
    ASSERT_EQUALS(static_cast<uint32_t>(2),
                  cdrc.readAndAdvance<LittleEndian<uint32_t>>().getValue());
    ASSERT_EQUALS(static_cast<uint64_t>(3), cdrc.readAndAdvance<BigEndian<uint64_t>>().getValue());
    ASSERT_EQUALS(false, cdrc.readAndAdvance<char>().isOK());

    // test skip()
    cdrc = backup;
    ASSERT_EQUALS(true, cdrc.skip<uint32_t>().isOK());
    ;
    ASSERT_EQUALS(true, cdrc.advance(10).isOK());
    ASSERT_EQUALS(false, cdrc.readAndAdvance<char>().isOK());
}