Commit cf05a54b authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac404] Spec size methods

One renamed to be more consistent to getFieldSpecDataSize(), other added
(getFieldSpecCount()).
parent 6e2078ec
......@@ -67,7 +67,7 @@ public:
RdataFieldsStore(ConstRdataPtr rdata) {
const RdataFields fields(*rdata);
spec_size_ = fields.getFieldDataSize();
spec_size_ = fields.getFieldSpecDataSize();
spec_store_.resize(spec_size_);
void* cp_spec = &spec_store_[0];
memcpy(cp_spec, fields.getFieldSpecData(), spec_store_.size());
......
......@@ -326,9 +326,16 @@ public:
/// getFieldSpecData() will occupy.
///
/// This method never throws an exception.
unsigned int getFieldDataSize() const { return (nfields_ *
unsigned int getFieldSpecDataSize() const { return (nfields_ *
sizeof *fields_); }
/// \brief Return the number of specs fields.
///
/// It specifies the range of parameter for getFieldSpec().
///
/// This method never throws.
unsigned int getFieldCount() const { return (nfields_); }
/// \brief Return a pointer to a sequence of \c FieldSpec for the
/// \c RdataFields.
///
......
......@@ -71,7 +71,8 @@ RdataFieldsTest::constructCommonTests(const RdataFields& fields,
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, expected_data,
expected_data_len, fields.getData(),
fields.getDataLength());
EXPECT_EQ(sizeof(RdataFields::FieldSpec), fields.getFieldDataSize());
EXPECT_EQ(sizeof(RdataFields::FieldSpec), fields.getFieldSpecDataSize());
EXPECT_EQ(1, fields.getFieldCount());
EXPECT_EQ(RdataFields::DATA, fields.getFieldSpec(0).type);
EXPECT_EQ(4, fields.getFieldSpec(0).len);
......@@ -103,7 +104,8 @@ TEST_F(RdataFieldsTest, constructFromParams) {
//
void
RdataFieldsTest::constructCommonTestsNS(const RdataFields& fields) {
EXPECT_EQ(sizeof(RdataFields::FieldSpec), fields.getFieldDataSize());
EXPECT_EQ(sizeof(RdataFields::FieldSpec), fields.getFieldSpecDataSize());
EXPECT_EQ(1, fields.getFieldCount());
EXPECT_EQ(RdataFields::COMPRESSIBLE_NAME, fields.getFieldSpec(0).type);
EXPECT_EQ(ns_name.getLength(), fields.getFieldSpec(0).len);
......@@ -143,7 +145,8 @@ void
RdataFieldsTest::constructCommonTestsTXT(const RdataFields& fields) {
// Since all fields are plain data, they are handled as a single data
// field.
EXPECT_EQ(sizeof(RdataFields::FieldSpec), fields.getFieldDataSize());
EXPECT_EQ(sizeof(RdataFields::FieldSpec), fields.getFieldSpecDataSize());
EXPECT_EQ(1, fields.getFieldCount());
EXPECT_EQ(RdataFields::DATA, fields.getFieldSpec(0).type);
EXPECT_EQ(expected_wire.size(), fields.getFieldSpec(0).len);
......@@ -190,7 +193,9 @@ RdataFieldsTest::constructCommonTestsRRSIG(const RdataFields& fields) {
// this is a variable length field. In this test it's a 13-byte field.
// - a variable-length data field for the signature. In this tests
// it's a 15-byte field.
ASSERT_EQ(3 * sizeof(RdataFields::FieldSpec), fields.getFieldDataSize());
EXPECT_EQ(3 * sizeof(RdataFields::FieldSpec),
fields.getFieldSpecDataSize());
EXPECT_EQ(3, fields.getFieldCount());
EXPECT_EQ(RdataFields::DATA, fields.getFieldSpec(0).type);
EXPECT_EQ(18, fields.getFieldSpec(0).len);
EXPECT_EQ(RdataFields::INCOMPRESSIBLE_NAME, fields.getFieldSpec(1).type);
......@@ -256,14 +261,14 @@ TEST_F(RdataFieldsTest, convertRdatatoParams) {
expected_wire.erase(expected_wire.begin(), expected_wire.begin() + 2);
// Copy the data in separate storage
vector<uint8_t> spec_store(fields.getFieldDataSize());
vector<uint8_t> spec_store(fields.getFieldSpecDataSize());
void* cp_spec = &spec_store[0];
memcpy(cp_spec, fields.getFieldSpecData(), spec_store.size());
vector<uint8_t> data_store(fields.getDataLength());
memcpy(&data_store[0], fields.getData(), fields.getDataLength());
// Restore the data in the form of RdataFields
const RdataFields fields_byparams(cp_spec, fields.getFieldDataSize(),
const RdataFields fields_byparams(cp_spec, fields.getFieldSpecDataSize(),
&data_store[0], fields.getDataLength());
// Check it's valid
......@@ -275,7 +280,8 @@ TEST_F(RdataFieldsTest, convertRdatatoParams) {
//
void
RdataFieldsTest::constructCommonTestsOPT(const RdataFields& fields) {
EXPECT_EQ(0, fields.getFieldDataSize());
EXPECT_EQ(0, fields.getFieldSpecDataSize());
EXPECT_EQ(0, fields.getFieldCount());
EXPECT_EQ(0, fields.getDataLength());
EXPECT_EQ((const uint8_t*) NULL, fields.getData());
fields.toWire(obuffer);
......
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