11#include <boost/test/unit_test.hpp>
13BOOST_AUTO_TEST_SUITE(write_name_tests)
16 size_t writeBufferSize = 0;
19 while (writeBufferSize < qname.size() + 2) {
20 std::vector<uint8_t> writtenName(writeBufferSize, 0);
21 uint8_t *writtenNameBegin = writtenName.data();
23 write_name(&writtenNameBegin, writtenNameBegin + writeBufferSize,
32 std::vector<uint8_t> writtenName(writeBufferSize, 0);
33 uint8_t *writtenNameBegin = writtenName.data();
35 write_name(&writtenNameBegin, writtenNameBegin + writeBufferSize,
38 BOOST_CHECK(writtenName.size() >= expectedName.size());
39 for (
size_t i = 0; i < expectedName.size(); i++) {
47 const int &offset = 12) {
48 size_t writeBufferSize = 0;
51 while (writeBufferSize < qname.size() + 3) {
52 std::vector<uint8_t> writtenName(writeBufferSize, 0);
53 uint8_t *writtenNameBegin = writtenName.data();
55 write_name(&writtenNameBegin, writtenNameBegin + writeBufferSize,
56 qname.c_str(), offset);
63 expectedName[expectedName.size() - 1] = (offset >> 8) | 0xC0;
64 expectedName.push_back(uint8_t(offset));
66 std::vector<uint8_t> writtenName(writeBufferSize, 0);
67 uint8_t *writtenNameBegin = writtenName.data();
69 write_name(&writtenNameBegin, writtenNameBegin + writeBufferSize,
70 qname.c_str(), offset);
72 BOOST_CHECK(writtenName.size() >= expectedName.size());
73 for (
size_t i = 0; i < expectedName.size(); i++) {
80static void CheckWriteName(
const std::string &qname,
const int &offset = 12) {
86 const std::string &qname,
const int &expectedError,
const int &offset = -1,
88 std::vector<uint8_t> writtenName(writeBufferSize, 0);
89 uint8_t *writtenNameBegin = writtenName.data();
90 int ret =
write_name(&writtenNameBegin, writtenNameBegin + writeBufferSize,
119 std::string maxLengthQName = maxLengthLabel +
'.' + maxLengthLabel +
'.' +
120 maxLengthLabel +
'.' + maxLengthLabel;
125 std::string oversizedQName = maxLengthQName;
128 oversizedQName.insert(oversizedQName.end() - 3,
'.');
134BOOST_AUTO_TEST_SUITE_END()
int write_name(uint8_t **outpos, const uint8_t *outend, const char *name, int offset)
constexpr int MAX_LABEL_LENGTH
constexpr int MAX_QUERY_NAME_LENGTH
constexpr int MAX_QUERY_NAME_BUFFER_LENGTH
static std::vector< uint8_t > CreateDNSQuestionNameField(const std::string &queryName)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static void CheckWriteName(const std::string &qname, const int &offset=12)
BOOST_AUTO_TEST_CASE(write_name_simple_tests)
static void CheckWriteNameNoOffset(const std::string &qname)
static void CheckWriteNameWithOffset(const std::string &qname, const int &offset=12)
static void CheckWriteNameError(const std::string &qname, const int &expectedError, const int &offset=-1, const size_t &writeBufferSize=MAX_QUERY_NAME_BUFFER_LENGTH)