Commit e9fa0685 authored by Kenton Varda's avatar Kenton Varda

Tweaks.

parent 64a0ca66
...@@ -234,9 +234,11 @@ TEST(WireFormat, StructRoundTrip) { ...@@ -234,9 +234,11 @@ TEST(WireFormat, StructRoundTrip) {
EXPECT_EQ(34 * WORDS, segment->getSize()); EXPECT_EQ(34 * WORDS, segment->getSize());
checkStruct(builder.asReader()); checkStruct(builder.asReader());
checkStruct(StructReader::readRootTrusted(segment->getStartPtr(), nullptr));
checkStruct(StructReader::readRoot(segment->getStartPtr(), nullptr, segment, 4));
} }
TEST(WireFormat, StructRoundTrip_FarPointers) { TEST(WireFormat, StructRoundTrip_MultipleSegments) {
std::unique_ptr<MessageBuilder> message = newMallocMessage(1 * WORDS); std::unique_ptr<MessageBuilder> message = newMallocMessage(1 * WORDS);
SegmentBuilder* segment = message->getSegmentWithAvailable(1 * WORDS); SegmentBuilder* segment = message->getSegmentWithAvailable(1 * WORDS);
word* rootLocation = segment->allocate(1 * WORDS); word* rootLocation = segment->allocate(1 * WORDS);
...@@ -245,23 +247,12 @@ TEST(WireFormat, StructRoundTrip_FarPointers) { ...@@ -245,23 +247,12 @@ TEST(WireFormat, StructRoundTrip_FarPointers) {
StructBuilder::initRoot(segment, rootLocation, FieldNumber(16), 2 * WORDS, 4 * REFERENCES); StructBuilder::initRoot(segment, rootLocation, FieldNumber(16), 2 * WORDS, 4 * REFERENCES);
setupStruct(builder); setupStruct(builder);
// word count: // Verify that we made 15 segments.
// 1 root reference ASSERT_TRUE(message->tryGetSegment(SegmentId(14)) != nullptr);
// 6 root struct EXPECT_EQ(nullptr, message->tryGetSegment(SegmentId(15)));
// 1 sub message
// 2 3-element int32 list
// 13 struct list
// 1 tag
// 12 4x struct
// 1 data segment
// 1 reference segment
// 1 sub-struct
// 11 list list
// 5 references to sub-lists
// 6 sub-lists (4x 1 word, 1x 2 words)
// -----
// 34
// Check that each segment has the expected size. Recall that the first word of each segment will
// actually be a reference to the first thing allocated within that segment.
EXPECT_EQ( 1 * WORDS, message->getSegment(SegmentId( 0))->getSize()); // root ref EXPECT_EQ( 1 * WORDS, message->getSegment(SegmentId( 0))->getSize()); // root ref
EXPECT_EQ( 7 * WORDS, message->getSegment(SegmentId( 1))->getSize()); // root struct EXPECT_EQ( 7 * WORDS, message->getSegment(SegmentId( 1))->getSize()); // root struct
EXPECT_EQ( 2 * WORDS, message->getSegment(SegmentId( 2))->getSize()); // sub-struct EXPECT_EQ( 2 * WORDS, message->getSegment(SegmentId( 2))->getSize()); // sub-struct
......
...@@ -567,7 +567,7 @@ StructReader StructReader::readRootTrusted(const word* location, const word* def ...@@ -567,7 +567,7 @@ StructReader StructReader::readRootTrusted(const word* location, const word* def
StructReader StructReader::readRoot(const word* location, const word* defaultValue, StructReader StructReader::readRoot(const word* location, const word* defaultValue,
SegmentReader* segment, int recursionLimit) { SegmentReader* segment, int recursionLimit) {
if (segment->containsInterval(location, location + 1 * REFERENCES * WORDS_PER_REFERENCE)) { if (!segment->containsInterval(location, location + 1 * REFERENCES * WORDS_PER_REFERENCE)) {
segment->getMessage()->reportInvalidData("Root location out-of-bounds."); segment->getMessage()->reportInvalidData("Root location out-of-bounds.");
location = nullptr; location = nullptr;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment