Browse Source

[2091a] cleanup: removed the previous "from raw" ctor and getLabelsData().

these were basically for this serialization, but now that we have a
different version of serialization/deserialization, we don't need them
for this purpose.  Until we see the need for them for specific purposes,
it'd be better to clean them up.
JINMEI Tatuya 12 years ago
parent
commit
ecd6c30cc2
3 changed files with 0 additions and 248 deletions
  1. 0 38
      src/lib/dns/labelsequence.cc
  2. 0 29
      src/lib/dns/labelsequence.h
  3. 0 181
      src/lib/dns/tests/labelsequence_unittest.cc

+ 0 - 38
src/lib/dns/labelsequence.cc

@@ -23,34 +23,6 @@
 namespace isc {
 namespace dns {
 
-LabelSequence::LabelSequence(const uint8_t* data,
-                             const uint8_t* offsets,
-                             size_t offsets_size) :
-    data_(data),
-    offsets_(offsets),
-    first_label_(0),
-    last_label_(offsets_size - 1)
-{
-    if (data == NULL || offsets == NULL) {
-        isc_throw(BadValue,
-                  "Null pointer passed to LabelSequence constructor");
-    }
-    if (offsets_size == 0) {
-        isc_throw(BadValue, "Zero offsets to LabelSequence constructor");
-    }
-    if (offsets_size > Name::MAX_LABELS) {
-        isc_throw(BadValue, "MAX_LABELS exceeded");
-    }
-    for (size_t cur_offset = 0; cur_offset < offsets_size; ++cur_offset) {
-        if (offsets[cur_offset] > Name::MAX_LABELLEN) {
-            isc_throw(BadValue, "MAX_LABEL_LEN exceeded");
-        }
-        if (cur_offset > 0 && offsets[cur_offset] <= offsets[cur_offset - 1]) {
-            isc_throw(BadValue, "Offset smaller than previous offset");
-        }
-    }
-}
-
 LabelSequence::LabelSequence(const void* buf) {
     if (buf == NULL) {
         isc_throw(BadValue,
@@ -89,16 +61,6 @@ LabelSequence::getData(size_t *len) const {
     return (&data_[offsets_[first_label_]]);
 }
 
-void
-LabelSequence::getOffsetData(size_t* len,
-                             uint8_t placeholder[Name::MAX_LABELS]) const
-{
-    *len = getLabelCount();
-    for (size_t i = 0; i < *len; ++i) {
-        placeholder[i] = offsets_[first_label_ + i] - offsets_[first_label_];
-    }
-}
-
 size_t
 LabelSequence::getDataLength() const {
     const size_t last_label_len = data_[offsets_[last_label_]] + 1;

+ 0 - 29
src/lib/dns/labelsequence.h

@@ -60,25 +60,6 @@ public:
         last_label_(name.getLabelCount() - 1)
     {}
 
-    /// \brief Constructs a LabelSequence for the given data
-    ///
-    /// \note The associated data MUST remain in scope during the lifetime
-    /// of this LabelSequence, since only the pointers are copied.
-    ///
-    /// \note No validation is done on the given data upon construction;
-    ///       use with care.
-    ///
-    /// \exception isc::BadValue if basic checks for the input data, or
-    ///            offsets fails.
-    ///
-    /// \param data The raw data for the domain name, in wire format
-    /// \param offsets The offsets of the labels in the domain name data,
-    ///        as given by a Name object or another LabelSequence
-    /// \param offsets_size The size of the offsets data
-    LabelSequence(const uint8_t* data,
-                  const uint8_t* offsets,
-                  size_t offsets_size);
-
     /// \brief Constructor from serialized image.
     ///
     /// This constructor restores a \c LabelSequence object from a serialized
@@ -128,16 +109,6 @@ public:
     /// \return Pointer to the wire-format data of this label sequence
     const uint8_t* getData(size_t* len) const;
 
-    /// \brief Return the offset data for this LabelSequence
-    ///
-    /// The offsets are returned in the <code>placeholder</code> array.
-    ///
-    /// \param len Pointer to a size_t where the number of offsets
-    ///        will be stored
-    /// \param placeholder Array where the offset data will be returned
-    void getOffsetData(size_t* len,
-                       uint8_t placeholder[Name::MAX_LABELS]) const;
-
     /// \brief Return the length of the wire-format data of this LabelSequence
     ///
     /// This method returns the number of octets for the data that would

+ 0 - 181
src/lib/dns/tests/labelsequence_unittest.cc

@@ -422,93 +422,6 @@ TEST_F(LabelSequenceTest, getData) {
     getDataCheck("\000", 1, ls7);
 };
 
-TEST_F(LabelSequenceTest, getOffsetData) {
-    size_t len;
-    uint8_t placeholder[Name::MAX_LABELS];
-
-    Name nx("x.isc.example.org");
-    LabelSequence lsx(nx);
-
-    // x.isc.example.org.
-    lsx.getOffsetData(&len, placeholder);
-    EXPECT_EQ(5, len);
-    EXPECT_EQ(0, placeholder[0]);
-    EXPECT_EQ(2, placeholder[1]);
-    EXPECT_EQ(6, placeholder[2]);
-    EXPECT_EQ(14, placeholder[3]);
-    EXPECT_EQ(18, placeholder[4]);
-
-    lsx.stripLeft(2);
-
-    // example.org.
-    lsx.getOffsetData(&len, placeholder);
-    EXPECT_EQ(3, len);
-    EXPECT_EQ(0, placeholder[0]);
-    EXPECT_EQ(8, placeholder[1]);
-    EXPECT_EQ(12, placeholder[2]);
-
-    lsx.stripLeft(1);
-
-    // org.
-    lsx.getOffsetData(&len, placeholder);
-    EXPECT_EQ(2, len);
-    EXPECT_EQ(0, placeholder[0]);
-    EXPECT_EQ(4, placeholder[1]);
-
-    lsx.stripLeft(1);
-
-    // .
-    lsx.getOffsetData(&len, placeholder);
-    EXPECT_EQ(1, len);
-    EXPECT_EQ(0, placeholder[0]);
-
-    Name ny("y.isc.example.org");
-    LabelSequence lsy(ny);
-
-    // y.isc.example.org.
-    lsy.getOffsetData(&len, placeholder);
-    EXPECT_EQ(5, len);
-    EXPECT_EQ(0, placeholder[0]);
-    EXPECT_EQ(2, placeholder[1]);
-    EXPECT_EQ(6, placeholder[2]);
-    EXPECT_EQ(14, placeholder[3]);
-    EXPECT_EQ(18, placeholder[4]);
-
-    lsy.stripRight(1);
-
-    // y.isc.example.org
-    lsy.getOffsetData(&len, placeholder);
-    EXPECT_EQ(4, len);
-    EXPECT_EQ(0, placeholder[0]);
-    EXPECT_EQ(2, placeholder[1]);
-    EXPECT_EQ(6, placeholder[2]);
-    EXPECT_EQ(14, placeholder[3]);
-
-    lsy.stripRight(1);
-
-    // y.isc.example
-    lsy.getOffsetData(&len, placeholder);
-    EXPECT_EQ(3, len);
-    EXPECT_EQ(0, placeholder[0]);
-    EXPECT_EQ(2, placeholder[1]);
-    EXPECT_EQ(6, placeholder[2]);
-
-    lsy.stripLeft(1);
-
-    // isc.example
-    lsy.getOffsetData(&len, placeholder);
-    EXPECT_EQ(2, len);
-    EXPECT_EQ(0, placeholder[0]);
-    EXPECT_EQ(4, placeholder[1]);
-
-    lsy.stripLeft(1);
-
-    // example
-    lsy.getOffsetData(&len, placeholder);
-    EXPECT_EQ(1, len);
-    EXPECT_EQ(0, placeholder[0]);
-};
-
 TEST_F(LabelSequenceTest, stripLeft) {
     EXPECT_TRUE(ls1.equals(ls3));
     ls1.stripLeft(0);
@@ -777,100 +690,6 @@ TEST_F(LabelSequenceTest, LeftShiftOperator) {
     EXPECT_EQ(ls1.toText(), oss.str());
 }
 
-// Test different ways of construction, and see if they compare
-TEST(LabelSequence, rawConstruction) {
-    Name n("example.org");
-
-    uint8_t data[] = { 0x07, 'e', 'x', 'a', 'm', 'p', 'l', 'e',
-                       0x03, 'o', 'r', 'g',
-                       0x00 };
-    uint8_t offsets[] = { 0, 8, 12 };
-    size_t offsets_size = 3;
-
-    LabelSequence s1(n);
-    LabelSequence s2(s1);
-    LabelSequence s3(data, offsets, offsets_size);
-
-    // Assuming equality is transitive, so only comparing 1 to 2 and 1 to 3
-    NameComparisonResult result = s1.compare(s2);
-    EXPECT_EQ(isc::dns::NameComparisonResult::EQUAL,
-              result.getRelation());
-    EXPECT_EQ(0, result.getOrder());
-    EXPECT_EQ(3, result.getCommonLabels());
-
-    result = s1.compare(s3);
-    EXPECT_EQ(isc::dns::NameComparisonResult::EQUAL,
-              result.getRelation());
-    EXPECT_EQ(0, result.getOrder());
-    EXPECT_EQ(3, result.getCommonLabels());
-
-    // Modify the data and make sure it's not equal anymore
-    data[2] = 'f';
-    result = s1.compare(s3);
-    EXPECT_EQ(isc::dns::NameComparisonResult::COMMONANCESTOR,
-              result.getRelation());
-    EXPECT_EQ(2, result.getCommonLabels());
-
-    s1.stripRight(1);
-    s3.stripRight(1);
-
-    result = s1.compare(s3);
-    EXPECT_EQ(isc::dns::NameComparisonResult::COMMONANCESTOR,
-              result.getRelation());
-    EXPECT_EQ(1, result.getCommonLabels());
-
-    data[9] = 'f';
-    result = s1.compare(s3);
-    EXPECT_EQ(isc::dns::NameComparisonResult::NONE, result.getRelation());
-    EXPECT_EQ(0, result.getCommonLabels());
-}
-
-// Test with some data that exceeds limits (MAX_LABELS and MAX_LABEL_LEN)
-TEST(LabelSequence, badRawConstruction) {
-    uint8_t data[1] = { 0 };
-    uint8_t offsets[1] = { 0 };
-
-    EXPECT_THROW(LabelSequence(NULL, offsets, 1), isc::BadValue);
-    EXPECT_THROW(LabelSequence(data, NULL, 1), isc::BadValue);
-    EXPECT_THROW(LabelSequence(data, offsets, 0), isc::BadValue);
-
-    // exceed MAX_LABELS
-    EXPECT_THROW(LabelSequence(data, offsets, 127), isc::BadValue);
-
-    // exceed MAX_LABEL_LEN
-    uint8_t offsets_toolonglabel[1] = { 64 };
-    EXPECT_THROW(LabelSequence(data, offsets_toolonglabel, 1), isc::BadValue);
-
-    // Add an offset that is lower than the previous offset
-    uint8_t offsets_lower[3] = { 0, 8, 4 };
-    EXPECT_THROW(LabelSequence(data, offsets_lower, 3), isc::BadValue);
-
-    // Add an offset that is equal to the previous offset
-    uint8_t offsets_noincrease[3] = { 0, 8, 8 };
-    EXPECT_THROW(LabelSequence(data, offsets_noincrease, 3), isc::BadValue);
-}
-
-TEST_F(LabelSequenceTest, serializedLength) {
-    // Initially, the labels are "example.org."
-    const size_t base_size = n1.getLength() + n1.getLabelCount() + 1;
-    EXPECT_EQ(base_size, ls1.getSerializedLength());
-
-    // Strip off the trailing dot.  We'll lose 1 label and 1-byte data
-    LabelSequence ls1_stripped = ls1;
-    ls1_stripped.stripRight(1);
-    EXPECT_EQ(base_size - 2, ls1_stripped.getSerializedLength());
-
-    // Strip off the leftmost label (example).  We'll lose 1 label and
-    // 8-byte data (1 + len('example')).
-    ls1_stripped = ls1;
-    ls1_stripped.stripLeft(1);
-    EXPECT_EQ(base_size - 9, ls1_stripped.getSerializedLength());
-
-    // Longest possible serialized length.  Confirm there's indeed such a case.
-    EXPECT_EQ(LabelSequence::MAX_SERIALIZED_LENGTH,
-              LabelSequence(n_maxlabel).getSerializedLength());
-}
-
 TEST_F(LabelSequenceTest, serialize) {
     // placeholder for serialized data
     uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];