MCPcopy Create free account
hub / github.com/bytedance/bolt / TEST_F

Function TEST_F

bolt/buffer/tests/BufferTest.cpp:64–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62};
63
64TEST_F(BufferTest, testAlignedBuffer) {
65 static constexpr int32_t kHeaderSize = sizeof(AlignedBuffer);
66 const int32_t size = 1024 * 7;
67 const int32_t sizeWithHeader = size + kHeaderSize;
68 BufferPtr other;
69 {
70 const char* testString = "1234567\0";
71 const int32_t testStringLength = strlen(testString);
72 BufferPtr buffer = AlignedBuffer::allocate<char>(size, pool_.get(), 'i');
73 EXPECT_EQ(buffer->as<char>()[0], 'i');
74 EXPECT_TRUE(buffer->isMutable());
75 EXPECT_EQ(buffer->size(), size);
76 EXPECT_GE(buffer->capacity(), size);
77 buffer->setSize(buffer->capacity());
78 memcpy(
79 buffer->asMutable<uint8_t>() + buffer->capacity() - testStringLength,
80 testString,
81 testStringLength);
82 other = buffer;
83 EXPECT_EQ(pool_->currentBytes(), pool_->preferredSize(sizeWithHeader));
84
85 AlignedBuffer::reallocate<char>(&other, size * 3, 'e');
86 EXPECT_NE(other, buffer);
87
88 // No longer multiply referenced.
89 EXPECT_GE(other->capacity(), 3 * size);
90 EXPECT_EQ(other->size(), 3 * size);
91 EXPECT_EQ(
92 memcmp(
93 other->as<uint8_t>() + buffer->capacity() - testStringLength,
94 testString,
95 testStringLength),
96 0);
97 EXPECT_EQ(other->as<char>()[buffer->capacity()], 'e');
98 EXPECT_EQ(
99 pool_->currentBytes(),
100 pool_->preferredSize(sizeWithHeader) +
101 pool_->preferredSize(3 * size + kHeaderSize));
102 }
103 EXPECT_EQ(
104 pool_->currentBytes(), pool_->preferredSize(3 * size + kHeaderSize));
105 other = nullptr;
106 BufferPtr bits = AlignedBuffer::allocate<bool>(65, pool_.get(), true);
107 EXPECT_EQ(bits->size(), 9);
108 EXPECT_EQ(bits->as<uint8_t>()[8], 0xff);
109 bits = nullptr;
110 EXPECT_EQ(pool_->currentBytes(), 0);
111}
112
113TEST_F(BufferTest, testAsRange) {
114 // Simple 2 element vector.

Callers

nothing calls this directly

Calls 15

memcpyFunction · 0.85
EndsWithFunction · 0.85
isMutableMethod · 0.80
preferredSizeMethod · 0.80
strMethod · 0.80
uniqueMethod · 0.80
asMutableRange<bool>Method · 0.80
asRange<bool>Method · 0.80
to_stringFunction · 0.50
maxFunction · 0.50
createFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected