20 #include "ns3/buffer.h"
21 #include "ns3/double.h"
22 #include "ns3/random-variable-stream.h"
47 void EnsureWrittenBytes(
Buffer b, uint32_t n, uint8_t array[]);
50 void DoRun()
override;
63 uint8_t* expected = array;
66 for (uint32_t j = 0; j < n; j++)
68 if (got[j] != expected[j])
75 std::ostringstream failure;
76 failure <<
"Buffer -- ";
77 failure <<
"expected: n=";
79 failure.setf(std::ios::hex, std::ios::basefield);
80 for (uint32_t j = 0; j < n; j++)
82 failure << (uint16_t)expected[j] <<
" ";
84 failure.setf(std::ios::dec, std::ios::basefield);
86 failure.setf(std::ios::hex, std::ios::basefield);
87 for (uint32_t j = 0; j < n; j++)
89 failure << (uint16_t)got[j] <<
" ";
100 #define ENSURE_WRITTEN_BYTES(buffer, n, ...) \
102 uint8_t bytes[] = {__VA_ARGS__}; \
103 EnsureWrittenBytes(buffer, n, bytes); \
133 ENSURE_WRITTEN_BYTES(buffer, 10, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
182 0x0123456789abcdefLLU,
183 "Could not read expected value");
193 #if defined(__clang__)
194 #if __has_warning("-Wself-assign-overloaded")
195 #pragma clang diagnostic push
196 #pragma clang diagnostic ignored "-Wself-assign-overloaded"
200 #if defined(__clang__)
201 #if __has_warning("-Wself-assign-overloaded")
202 #pragma clang diagnostic pop
259 ENSURE_WRITTEN_BYTES(buffer, 11, 0x30, 0x31, 0x32, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
296 const uint32_t actualSize = 72602;
297 const uint32_t chunkSize = 67624;
308 for (uint32_t i = 0; i < actualSize; i++)
316 iter.
Prev(chunkSize);
349 ENSURE_WRITTEN_BYTES(buffer, 9, 0x1, 0x2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3, 0x4);
354 ENSURE_WRITTEN_BYTES(other, 9, 0x1, 0x2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3, 0x4);
357 std::string ct(
"This is the next content of the buffer.");
361 i.
Write((
const uint8_t*)ct.c_str(), ct.size());
362 uint32_t sizeBuffer = buffer.
GetSize();
364 const uint8_t* evilBuffer = buffer.
PeekData();
366 auto cBuf = (uint8_t*)malloc(sizeBuffer);
367 uint32_t copyLen = buffer.
CopyData(cBuf, sizeBuffer);
369 for (uint32_t i = 0; i < sizeBuffer; i++)
372 *(((
const uint8_t*)ct.c_str()) + i),
373 "Bad buffer copied data");
static BufferTestSuite g_bufferTestSuite
Static variable for test initialization.
#define ENSURE_WRITTEN_BYTES(buffer, n,...)
void DoRun() override
Implementation to actually run this TestCase.
void EnsureWrittenBytes(Buffer b, uint32_t n, uint8_t array[])
Checks the buffer content.
iterator in a Buffer instance
void WriteU64(uint64_t data)
void WriteHtonU64(uint64_t data)
void WriteU8(uint8_t data)
void Write(const uint8_t *buffer, uint32_t size)
void WriteU16(uint16_t data)
void WriteHtolsbU64(uint64_t data)
void WriteHtonU16(uint16_t data)
void WriteHtonU32(uint32_t data)
void Prev()
go backward by one byte
void Next()
go forward by one byte
automatically resized byte buffer
Buffer CreateFragment(uint32_t start, uint32_t length) const
void CopyData(std::ostream *os, uint32_t size) const
Copy the specified amount of data from the buffer to the given output stream.
void RemoveAtEnd(uint32_t end)
void AddAtStart(uint32_t start)
Buffer::Iterator Begin() const
void AddAtEnd(uint32_t end)
Buffer::Iterator End() const
void RemoveAtStart(uint32_t start)
const uint8_t * PeekData() const
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.