]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3211] More cosmetic changes
authorFrancis Dupont <fdupont@isc.org>
Fri, 8 Mar 2024 09:03:49 +0000 (10:03 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 19 Mar 2024 23:18:24 +0000 (00:18 +0100)
src/lib/util/buffer.h
src/lib/util/tests/buffer_unittest.cc

index 318e7e686c693e0b7719b249ce8e7b0883ecdfa5..78b3cde93ea74f5eab95abc1525ff8bc0da6f8a4 100644 (file)
@@ -5,23 +5,22 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #ifndef BUFFER_H
-#define BUFFER_H 1
-
-#include <stdlib.h>
-#include <cstring>
-#include <vector>
-
-#include <stdint.h>
+#define BUFFER_H
 
 #include <exceptions/exceptions.h>
 
 #include <boost/shared_ptr.hpp>
 
+#include <cstring>
+#include <stdint.h>
+#include <stdlib.h>
+#include <vector>
+
 namespace isc {
 namespace util {
 
 ///
-/// \brief A standard DNS module exception that is thrown if an out-of-range
+/// @brief A standard DNS module exception that is thrown if an out-of-range
 /// buffer operation is being performed.
 ///
 class InvalidBufferPosition : public isc::OutOfRange {
@@ -30,7 +29,7 @@ public:
         isc::OutOfRange(file, line, what) {}
 };
 
-///\brief The \c InputBuffer class is a buffer abstraction for manipulating
+/// @brief The @c InputBuffer class is a buffer abstraction for manipulating
 /// read-only data.
 ///
 /// The main purpose of this class is to provide a safe placeholder for
@@ -41,21 +40,22 @@ public:
 /// socket) and the rest of the Kea DNS library.  One common usage of this
 /// class for an application would therefore be something like this:
 ///
-/// \code unsigned char buf[1024];
+/// @code unsigned char buf[1024];
 /// struct sockaddr addr;
 /// socklen_t addrlen = sizeof(addr);
 /// int cc = recvfrom(s, buf, sizeof(buf), 0, &addr, &addrlen);
 /// InputBuffer buffer(buf, cc);
-/// // pass the buffer to a DNS message object to parse the message \endcode
+/// // pass the buffer to a DNS message object to parse the message
+/// @endcode
 ///
 /// Other Kea DNS classes will then use methods of this class to get access
 /// to the data, but the application normally doesn't have to care about the
 /// details.
 ///
-/// An \c InputBuffer object internally holds a reference to the given data,
+/// An @c InputBuffer object internally holds a reference to the given data,
 /// rather than make a local copy of the data.  Also, it does not have an
 /// ownership of the given data.  It is application's responsibility to ensure
-/// the data remains valid throughout the lifetime of the \c InputBuffer
+/// the data remains valid throughout the lifetime of the @c InputBuffer
 /// object.  Likewise, this object generally assumes the data isn't modified
 /// throughout its lifetime; if the application modifies the data while this
 /// object retains a reference to it, the result is undefined.  The application
@@ -88,14 +88,14 @@ public:
 class InputBuffer {
 public:
     ///
-    /// \name Constructors and Destructor
+    /// @name Constructors and Destructor
     //@{
-    /// \brief Constructor from variable length of data.
+    /// @brief Constructor from variable length of data.
     ///
     /// It is caller's responsibility to ensure that the data is valid as long
     /// as the buffer exists.
-    /// \param data A pointer to the data stored in the buffer.
-    /// \param len The length of the data in bytes.
+    /// @param data A pointer to the data stored in the buffer.
+    /// @param len The length of the data in bytes.
     InputBuffer(const void* data, size_t len) :
       base_(static_cast<const uint8_t*>(data)), current_(base_),
       end_(base_ + len) {
@@ -103,28 +103,28 @@ public:
     //@}
 
     ///
-    /// \name Getter Methods
+    /// @name Getter Methods
     //@{
-    /// \brief Return the length of the data stored in the buffer.
+    /// @brief Return the length of the data stored in the buffer.
     size_t getLength() const {
         return (static_cast<size_t>(end_ - base_));
     }
 
-    /// \brief Return the current read position.
+    /// @brief Return the current read position.
     size_t getPosition() const {
         return (static_cast<size_t>(current_ - base_));
     }
     //@}
 
     ///
-    /// \name Setter Methods
+    /// @name Setter Methods
     ///
     //@{
-    /// \brief Set the read position of the buffer to the given value.
+    /// @brief Set the read position of the buffer to the given value.
     ///
     /// The new position must be in the valid range of the buffer; otherwise
-    /// an exception of class \c isc::dns::InvalidBufferPosition will be thrown.
-    /// \param position The new position (offset from the beginning of the
+    /// an exception of class @c isc::dns::InvalidBufferPosition will be thrown.
+    /// @param position The new position (offset from the beginning of the
     /// buffer).
     void setPosition(size_t position) {
         if (base_ + position > end_) {
@@ -135,12 +135,12 @@ public:
     //@}
 
     ///
-    /// \name Methods for reading data from the buffer.
+    /// @name Methods for reading data from the buffer.
     //@{
-    /// \brief Peek an unsigned 8-bit integer from the buffer and return it.
+    /// @brief Peek an unsigned 8-bit integer from the buffer and return it.
     ///
     /// If the remaining length of the buffer is smaller than 8-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
+    /// exception of class @c isc::dns::InvalidBufferPosition will be thrown.
     uint8_t peekUint8() {
         if (current_ + sizeof(uint8_t) > end_) {
             throwError("read beyond end of buffer");
@@ -149,10 +149,10 @@ public:
         return (*current_);
     }
 
-    /// \brief Read an unsigned 8-bit integer from the buffer and return it.
+    /// @brief Read an unsigned 8-bit integer from the buffer and return it.
     ///
     /// If the remaining length of the buffer is smaller than 8-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
+    /// exception of class @c isc::dns::InvalidBufferPosition will be thrown.
     uint8_t readUint8() {
         uint8_t ret = peekUint8();
         current_ += sizeof(uint8_t);
@@ -160,11 +160,11 @@ public:
         return (ret);
     }
 
-    /// \brief Peek an unsigned 16-bit integer in network byte order from the
+    /// @brief Peek an unsigned 16-bit integer in network byte order from the
     /// buffer, and return it.
     ///
     /// If the remaining length of the buffer is smaller than 16-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
+    /// exception of class @c isc::dns::InvalidBufferPosition will be thrown.
     uint16_t peekUint16() {
         if (current_ + sizeof(uint16_t) > end_) {
             throwError("read beyond end of buffer");
@@ -177,11 +177,11 @@ public:
         return (ret);
     }
 
-    /// \brief Read an unsigned 16-bit integer in network byte order from the
+    /// @brief Read an unsigned 16-bit integer in network byte order from the
     /// buffer, and return it.
     ///
     /// If the remaining length of the buffer is smaller than 16-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
+    /// exception of class @c isc::dns::InvalidBufferPosition will be thrown.
     uint16_t readUint16() {
         uint16_t ret = peekUint16();
         current_ += sizeof(uint16_t);
@@ -189,11 +189,11 @@ public:
         return (ret);
     }
 
-    /// \brief Read an unsigned 32-bit integer in network byte order from the
+    /// @brief Read an unsigned 32-bit integer in network byte order from the
     /// buffer, and return it.
     ///
     /// If the remaining length of the buffer is smaller than 32-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
+    /// exception of class @c isc::dns::InvalidBufferPosition will be thrown.
     uint32_t peekUint32() {
         if (current_ + sizeof(uint32_t) > end_) {
             throwError("read beyond end of buffer");
@@ -208,11 +208,11 @@ public:
         return (ret);
     }
 
-    /// \brief Read an unsigned 32-bit integer in network byte order from the
+    /// @brief Read an unsigned 32-bit integer in network byte order from the
     /// buffer, and return it.
     ///
     /// If the remaining length of the buffer is smaller than 32-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
+    /// exception of class @c isc::dns::InvalidBufferPosition will be thrown.
     uint32_t readUint32() {
         uint32_t ret = peekUint32();
         current_ += sizeof(uint32_t);
@@ -220,12 +220,12 @@ public:
         return (ret);
     }
 
-    /// \brief Peek data of the specified length from the buffer and copy it to
+    /// @brief Peek data of the specified length from the buffer and copy it to
     /// the caller supplied buffer.
     ///
     /// The data is copied as stored in the buffer; no conversion is performed.
     /// If the remaining length of the buffer is smaller than the specified
-    /// length, an exception of class \c isc::dns::InvalidBufferPosition will
+    /// length, an exception of class @c isc::dns::InvalidBufferPosition will
     /// be thrown.
     void peekData(void* data, size_t len) {
         if (current_ + len > end_) {
@@ -235,12 +235,12 @@ public:
         static_cast<void>(std::memmove(data, current_, len));
     }
 
-    /// \brief Read data of the specified length from the buffer and copy it to
+    /// @brief Read data of the specified length from the buffer and copy it to
     /// the caller supplied buffer.
     ///
     /// The data is copied as stored in the buffer; no conversion is performed.
     /// If the remaining length of the buffer is smaller than the specified
-    /// length, an exception of class \c isc::dns::InvalidBufferPosition will
+    /// length, an exception of class @c isc::dns::InvalidBufferPosition will
     /// be thrown.
     void readData(void* data, size_t len) {
         peekData(data, len);
@@ -279,7 +279,7 @@ public:
     //@}
 
 private:
-    /// \brief A common helper to throw an exception on invalid operation.
+    /// @brief A common helper to throw an exception on invalid operation.
     ///
     /// Experiments showed that throwing from each method makes the buffer
     /// operation slower, so we consolidate it here, and let the methods
@@ -288,18 +288,18 @@ private:
         isc_throw(InvalidBufferPosition, msg);
     }
 
-    /// \brief Base of the buffer.
+    /// @brief Base of the buffer.
     const uint8_t* base_;
 
-    /// \brief Current poisition in the buffer.
+    /// @brief Current poisition in the buffer.
     const uint8_t* current_;
 
-    /// \brief End of the buffer (address of the byte after).
+    /// @brief End of the buffer (address of the byte after).
     const uint8_t* end_;
 };
 
 ///
-///\brief The \c OutputBuffer class is a buffer abstraction for manipulating
+/// @brief The @c OutputBuffer class is a buffer abstraction for manipulating
 /// mutable data.
 ///
 /// The main purpose of this class is to provide a safe workplace for
@@ -307,33 +307,33 @@ private:
 /// <em>safe</em> means that it automatically allocates necessary memory and
 /// avoid buffer overrun.
 ///
-/// Like for the \c InputBuffer class, applications normally use this class only
+/// Like for the @c InputBuffer class, applications normally use this class only
 /// in a limited situation.  One common usage of this class for an application
 /// would be something like this:
 ///
-/// \code OutputBuffer buffer(4096); // give a sufficiently large initial size
+/// @code OutputBuffer buffer(4096); // give a sufficiently large initial size
 /// // pass the buffer to a DNS message object to construct a wire-format
 /// // DNS message.
 /// struct sockaddr to;
 /// sendto(s, buffer.getDataAsVP(), buffer.getLength(), 0, &to, sizeof(to));
-/// \endcode
+/// @endcode
 ///
-/// where the \c getData() method gives a reference to the internal memory
-/// region stored in the \c buffer object.  This is a suboptimal design in that
+/// where the @c getData() method gives a reference to the internal memory
+/// region stored in the @c buffer object.  This is a suboptimal design in that
 /// it exposes an encapsulated "handle" of an object to its user.
 /// Unfortunately, there is no easy way to avoid this without involving
 /// expensive data copy if we want to use this object with a legacy API such as
 /// a BSD socket interface.  And, indeed, this is one major purpose for this
 /// object.  Applications should use this method only under such a special
 /// circumstance.  It should also be noted that the memory region returned by
-/// \c getData() may be invalidated after a subsequent write operation.
+/// @c getData() may be invalidated after a subsequent write operation.
 ///
-/// An \c OutputBuffer class object automatically extends its memory region when
+/// An @c OutputBuffer class object automatically extends its memory region when
 /// data is written beyond the end of the current buffer.  However, it will
 /// involve performance overhead such as reallocating more memory and copying
 /// data.  It is therefore recommended to construct the buffer object with a
 /// sufficiently large initial size.
-/// The \c getCapacity() method provides the current maximum size of data
+/// The @c getCapacity() method provides the current maximum size of data
 /// (including the portion already written) that can be written into the buffer
 /// without causing memory reallocation.
 ///
@@ -341,15 +341,15 @@ private:
 /// stream: it begins with the head of the buffer, and once some length of data
 /// is written into the buffer, the next write operation will take place from
 /// the end of the buffer.  Other methods to emulate "random access" are also
-/// provided (e.g., \c writeUint16At()).  The normal write operations are
+/// provided (e.g., @c writeUint16At()).  The normal write operations are
 /// normally exception-free as this class automatically extends the buffer
 /// when necessary.  However, in extreme cases such as an attempt of writing
-/// multi-GB data, a separate exception (e.g., \c std::bad_alloc) may be thrown
+/// multi-GB data, a separate exception (e.g., @c std::bad_alloc) may be thrown
 /// by the system.  This also applies to the constructor with a very large
 /// initial size.
 ///
 /// Note to developers: it may make more sense to introduce an abstract base
-/// class for the \c OutputBuffer and define the simple implementation as a
+/// class for the @c OutputBuffer and define the simple implementation as a
 /// concrete derived class.  That way we can provide flexibility for future
 /// extension such as more efficient buffer implementation or allowing users
 /// to have their own customized version without modifying the source code.
@@ -358,16 +358,16 @@ private:
 /// implementation unnecessarily complicated while we were still not certain
 /// if we really want that flexibility.  We may revisit the class design as
 /// we see more applications of the class.  The same considerations apply to
-/// the \c InputBuffer and \c MessageRenderer classes.
+/// the @c InputBuffer and @c MessageRenderer classes.
 class OutputBuffer {
 public:
     ///
-    /// \name Constructors and Destructor
+    /// @name Constructors and Destructor
     ///
     //@{
-    /// \brief Constructor from the initial size of the buffer.
+    /// @brief Constructor from the initial size of the buffer.
     ///
-    /// \param len The initial allocated length of the buffer in bytes.
+    /// @param len The initial allocated length of the buffer in bytes.
     OutputBuffer(size_t len) : buffer_()
     {
         if (len != 0) {
@@ -375,11 +375,11 @@ public:
         }
     }
 
-    /// \brief Copy constructor
+    /// @brief Copy constructor
     ///
-    /// \param other Source object from which to make a copy.
+    /// @param other Source object from which to make a copy.
     ///
-    /// \note It is assumed that the source object is consistent, i.e.
+    /// @note It is assumed that the source object is consistent, i.e.
     /// size_ <= allocated_, and that if allocated_ is greater than zero,
     /// buffer_ points to valid memory.
     OutputBuffer(const OutputBuffer& other) :
@@ -391,17 +391,17 @@ public:
         }
     }
 
-    /// \brief Destructor
+    /// @brief Destructor
     ~OutputBuffer() {
         buffer_.clear();
     }
     //@}
 
-    /// \brief Assignment operator
+    /// @brief Assignment operator
     ///
-    /// \param other Object to copy into "this".
+    /// @param other Object to copy into "this".
     ///
-    /// \note It is assumed that the source object is consistent, i.e.
+    /// @note It is assumed that the source object is consistent, i.e.
     /// size_ <= allocated_, and that if allocated_ is greater than zero,
     /// buffer_ points to valid memory.
     OutputBuffer& operator =(const OutputBuffer& other) {
@@ -417,17 +417,17 @@ public:
     }
 
     ///
-    /// \name Getter Methods
+    /// @name Getter Methods
     ///
     //@{
-    /// \brief Return the current capacity of the buffer.
+    /// @brief Return the current capacity of the buffer.
     size_t getCapacity() const {
         return (buffer_.capacity());
     }
 
-    /// \brief Return a pointer to the head of the data stored in the buffer.
+    /// @brief Return a pointer to the head of the data stored in the buffer.
     ///
-    /// The caller can assume that the subsequent \c getLength() bytes are
+    /// The caller can assume that the subsequent @c getLength() bytes are
     /// identical to the stored data of the buffer.
     ///
     /// Note: The pointer returned by this method may be invalidated after a
@@ -440,22 +440,22 @@ public:
         }
     }
 
-    /// \brief Return data as a pointer to void.
+    /// @brief Return data as a pointer to void.
     const void* getDataAsVP() const {
         return (static_cast<const void*>(getData()));
     }
 
-    /// \brief Return the length of data written in the buffer.
+    /// @brief Return the length of data written in the buffer.
     size_t getLength() const {
         return (buffer_.size());
     }
 
-    /// \brief Return the value of the buffer at the specified position.
+    /// @brief Return the value of the buffer at the specified position.
     ///
-    /// \c pos must specify the valid position of the buffer; otherwise an
-    /// exception class of \c InvalidBufferPosition will be thrown.
+    /// @c pos must specify the valid position of the buffer; otherwise an
+    /// exception class of @c InvalidBufferPosition will be thrown.
     ///
-    /// \param pos The position in the buffer to be returned.
+    /// @param pos The position in the buffer to be returned.
     uint8_t operator[](size_t pos) const {
         if (pos >= buffer_.size()) {
             isc_throw(InvalidBufferPosition,
@@ -464,35 +464,35 @@ public:
         return (buffer_[pos]);
     }
 
-    /// \brief Return the buffer.
+    /// @brief Return the buffer.
     ///
-    /// \note The main use is to avoid a copy.
+    /// @note The main use is to avoid a copy.
     const std::vector<uint8_t>& getVector() const {
         return (buffer_);
     }
     //@}
 
     ///
-    /// \name Methods for writing data into the buffer.
+    /// @name Methods for writing data into the buffer.
     ///
     //@{
-    /// \brief Insert a specified length of gap at the end of the buffer.
+    /// @brief Insert a specified length of gap at the end of the buffer.
     ///
     /// The caller should not assume any particular value to be inserted.
     /// This method is provided as a shortcut to make a hole in the buffer
-    /// that is to be filled in later, e.g, by \ref writeUint16At().
-    /// \param len The length of the gap to be inserted in bytes.
+    /// that is to be filled in later, e.g, by @ref writeUint16At().
+    /// @param len The length of the gap to be inserted in bytes.
     void skip(size_t len) {
         buffer_.resize(buffer_.size() + len);
     }
 
-    /// \brief Trim the specified length of data from the end of the buffer.
+    /// @brief Trim the specified length of data from the end of the buffer.
     ///
     /// The specified length must not exceed the current data size of the
-    /// buffer; otherwise an exception of class \c isc::OutOfRange will
+    /// buffer; otherwise an exception of class @c isc::OutOfRange will
     /// be thrown.
     ///
-    /// \param len The length of data that should be trimmed.
+    /// @param len The length of data that should be trimmed.
     void trim(size_t len) {
         if (len > buffer_.size()) {
             isc_throw(OutOfRange, "trimming too large from output buffer");
@@ -500,26 +500,26 @@ public:
         buffer_.resize(buffer_.size() - len);
     }
 
-    /// \brief Clear buffer content.
+    /// @brief Clear buffer content.
     void clear() {
         buffer_.clear();
     }
 
-    /// \brief Write an unsigned 8-bit integer into the buffer.
+    /// @brief Write an unsigned 8-bit integer into the buffer.
     ///
-    /// \param data The 8-bit integer to be written into the buffer.
+    /// @param data The 8-bit integer to be written into the buffer.
     void writeUint8(uint8_t data) {
         buffer_.push_back(data);
     }
 
-    /// \brief Write an unsigned 8-bit integer into the buffer.
+    /// @brief Write an unsigned 8-bit integer into the buffer.
     ///
     /// The position must be lower than the size of the buffer,
-    /// otherwise an exception of class \c isc::dns::InvalidBufferPosition
+    /// otherwise an exception of class @c isc::dns::InvalidBufferPosition
     /// will be thrown.
     ///
-    /// \param data The 8-bit integer to be written into the buffer.
-    /// \param pos The position in the buffer to write the data.
+    /// @param data The 8-bit integer to be written into the buffer.
+    /// @param pos The position in the buffer to write the data.
     void writeUint8At(uint8_t data, size_t pos) {
         if (pos + sizeof(data) > buffer_.size()) {
             isc_throw(InvalidBufferPosition, "write at invalid position");
@@ -527,26 +527,26 @@ public:
         buffer_[pos] = data;
     }
 
-    /// \brief Write an unsigned 16-bit integer in host byte order into the
+    /// @brief Write an unsigned 16-bit integer in host byte order into the
     /// buffer in network byte order.
     ///
-    /// \param data The 16-bit integer to be written into the buffer.
+    /// @param data The 16-bit integer to be written into the buffer.
     void writeUint16(uint16_t data) {
         buffer_.push_back(static_cast<uint8_t>((data & 0xff00U) >> 8));
         buffer_.push_back(static_cast<uint8_t>(data & 0x00ffU));
     }
 
-    /// \brief Write an unsigned 16-bit integer in host byte order at the
+    /// @brief Write an unsigned 16-bit integer in host byte order at the
     /// specified position of the buffer in network byte order.
     ///
     /// The buffer must have a sufficient room to store the given data at the
     /// given position, that is, <code>pos + 2 < getLength()</code>;
-    /// otherwise an exception of class \c isc::dns::InvalidBufferPosition will
+    /// otherwise an exception of class @c isc::dns::InvalidBufferPosition will
     /// be thrown.
     /// Note also that this method never extends the buffer.
     ///
-    /// \param data The 16-bit integer to be written into the buffer.
-    /// \param pos The beginning position in the buffer to write the data.
+    /// @param data The 16-bit integer to be written into the buffer.
+    /// @param pos The beginning position in the buffer to write the data.
     void writeUint16At(uint16_t data, size_t pos) {
         if (pos + sizeof(data) > buffer_.size()) {
             isc_throw(InvalidBufferPosition, "write at invalid position");
@@ -556,10 +556,10 @@ public:
         buffer_[pos + 1] = static_cast<uint8_t>(data & 0x00ffU);
     }
 
-    /// \brief Write an unsigned 32-bit integer in host byte order
+    /// @brief Write an unsigned 32-bit integer in host byte order
     /// into the buffer in network byte order.
     ///
-    /// \param data The 32-bit integer to be written into the buffer.
+    /// @param data The 32-bit integer to be written into the buffer.
     void writeUint32(uint32_t data) {
         buffer_.push_back(static_cast<uint8_t>((data & 0xff000000) >> 24));
         buffer_.push_back(static_cast<uint8_t>((data & 0x00ff0000) >> 16));
@@ -567,10 +567,10 @@ public:
         buffer_.push_back(static_cast<uint8_t>(data & 0x000000ff));
     }
 
-    /// \brief Write an unsigned 64-bit integer in host byte order
+    /// @brief Write an unsigned 64-bit integer in host byte order
     /// into the buffer in network byte order.
     ///
-    /// \param data The 64-bit integer to be written into the buffer.
+    /// @param data The 64-bit integer to be written into the buffer.
     void writeUint64(uint64_t data) {
         buffer_.push_back(static_cast<uint8_t>((data & 0xff00000000000000) >> 56));
         buffer_.push_back(static_cast<uint8_t>((data & 0x00ff000000000000) >> 48));
@@ -582,12 +582,12 @@ public:
         buffer_.push_back(static_cast<uint8_t>(data &  0x00000000000000ff));
     }
 
-    /// \brief Copy an arbitrary length of data into the buffer.
+    /// @brief Copy an arbitrary length of data into the buffer.
     ///
     /// No conversion on the copied data is performed.
     ///
-    /// \param data A pointer to the data to be copied into the buffer.
-    /// \param len The length of the data in bytes.
+    /// @param data A pointer to the data to be copied into the buffer.
+    /// @param len The length of the data in bytes.
     void writeData(const void *data, size_t len) {
         if (len == 0) {
             return;
@@ -603,7 +603,7 @@ private:
     std::vector<uint8_t> buffer_;
 };
 
-/// \brief Pointer-like types pointing to \c InputBuffer or \c OutputBuffer
+/// @brief Pointer-like types pointing to @c InputBuffer or @c OutputBuffer
 ///
 /// These types are expected to be used as an argument in asynchronous
 /// callback functions.  The internal reference-counting will ensure that
@@ -614,8 +614,5 @@ typedef boost::shared_ptr<OutputBuffer> OutputBufferPtr;
 
 } // namespace util
 } // namespace isc
-#endif  // BUFFER_H
 
-// Local Variables:
-// mode: c++
-// End:
+#endif  // BUFFER_H
index cd6670085e0a5b5420808696a96ec4f7e0f97b39..1978b4745bf0bff26528b7eaf78d29b7b8cd7a81 100644 (file)
@@ -6,29 +6,25 @@
 
 #include <config.h>
 
-#include <gtest/gtest.h>
-
 #include <exceptions/exceptions.h>
+#include <util/buffer.h>
 
 #ifdef EXPECT_DEATH
 #include <util/unittests/resource.h>
 #include <util/unittests/check_valgrind.h>
 #endif /* EXPECT_DEATH */
 
-#include <util/buffer.h>
+#include <gtest/gtest.h>
 
 using namespace isc;
+using namespace isc::util;
 
 namespace {
 
-using isc::util::InputBuffer;
-using isc::util::OutputBuffer;
-
 class BufferTest : public ::testing::Test {
 protected:
     BufferTest() : ibuffer(testdata, sizeof(testdata)), obuffer(0),
-                   expected_size(0)
-    {
+                   expected_size(0) {
         data16 = (2 << 8) | 3;
         data32 = (4 << 24) | (5 << 16) | (6 << 8) | 7;
         memset(vdata, 0, sizeof(testdata));
@@ -116,12 +112,10 @@ TEST_F(BufferTest, outputBufferExtend) {
 }
 
 TEST_F(BufferTest, outputBufferWrite) {
-    const uint8_t* cp;
-
     obuffer.writeUint8(1);
     expected_size += sizeof(uint8_t);
     EXPECT_EQ(expected_size, obuffer.getLength());
-    cp = obuffer.getData();
+    const uint8_t* cp = obuffer.getData();
     EXPECT_EQ(1, *cp);
 
     obuffer.writeUint16(data16);
@@ -223,13 +217,13 @@ TEST_F(BufferTest, outputBufferClear) {
 }
 
 TEST_F(BufferTest, outputBufferCopy) {
-    obuffer.writeData(testdata, sizeof(testdata));
-
     EXPECT_NO_THROW({
+        obuffer.writeData(testdata, sizeof(testdata));
+
         OutputBuffer copy(obuffer);
         ASSERT_EQ(sizeof(testdata), copy.getLength());
         ASSERT_NE(obuffer.getData(), copy.getData());
-        for (int i = 0; i < sizeof(testdata); i ++) {
+        for (size_t i = 0; i < sizeof(testdata); ++i) {
             EXPECT_EQ(testdata[i], copy[i]);
             if (i + 1 < sizeof(testdata)) {
                 obuffer.writeUint16At(0, i);
@@ -250,11 +244,11 @@ TEST_F(BufferTest, outputEmptyBufferCopy) {
 }
 
 TEST_F(BufferTest, outputBufferAssign) {
-    OutputBuffer another(0);
-    another.clear();
-    obuffer.writeData(testdata, sizeof(testdata));
-
     EXPECT_NO_THROW({
+        OutputBuffer another(0);
+        another.clear();
+        obuffer.writeData(testdata, sizeof(testdata));
+
         another = obuffer;
         ASSERT_EQ(sizeof(testdata), another.getLength());
         ASSERT_NE(obuffer.getData(), another.getData());
@@ -272,10 +266,8 @@ TEST_F(BufferTest, outputBufferAssign) {
 
 TEST_F(BufferTest, outputEmptyBufferAssign) {
     OutputBuffer copy(0);
-    ASSERT_NO_THROW({
-        copy = obuffer;
-    });
-    ASSERT_EQ(0, copy.getLength());
+    EXPECT_NO_THROW(copy = obuffer;);
+    EXPECT_EQ(0, copy.getLength());
     EXPECT_EQ(0, copy.getData());
 }
 
@@ -284,52 +276,32 @@ TEST_F(BufferTest, outputBufferAssignSelf) {
     EXPECT_NO_THROW(obuffer = obuffer);
 }
 
-TEST_F(BufferTest, outputBufferZeroSize) {
-    // Some OSes might return NULL on malloc for 0 size, so check it works
-    EXPECT_NO_THROW({
-        OutputBuffer first(0);
-        OutputBuffer copy(first);
-        OutputBuffer second(0);
-        second = first;
-    });
-}
-
 TEST_F(BufferTest, inputBufferReadVectorChunks) {
     std::vector<uint8_t> vec;
 
     // check that vector can read the whole buffer
     ibuffer.readVector(vec, 3);
     EXPECT_EQ(3, vec.size());
-
     EXPECT_EQ(0, memcmp(&vec[0], testdata, 3));
-
-    EXPECT_NO_THROW(
-        ibuffer.readVector(vec, 2)
-    );
-
+    EXPECT_NO_THROW(ibuffer.readVector(vec, 2));
     ASSERT_EQ(2, vec.size());
     EXPECT_EQ(0, memcmp(&vec[0], &testdata[3], 2));
 }
 
 // Tests whether uint64 can be written properly.
 TEST_F(BufferTest, writeUint64) {
-
     uint64_t val1 = 0x0102030405060708ul;
     uint64_t val2 = 0xfffffffffffffffful;
-
     uint8_t exp_val1[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
     uint8_t exp_val2[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
-    const uint8_t* cp;
-
     obuffer.writeUint64(val1);
     ASSERT_EQ(sizeof(uint64_t), obuffer.getLength());
-    cp = obuffer.getData();
+    const uint8_t* cp = obuffer.getData();
     EXPECT_TRUE(cp);
     EXPECT_FALSE(memcmp(exp_val1, obuffer.getData(), sizeof(uint64_t)));
 
     EXPECT_NO_THROW(obuffer.clear());
-
     obuffer.writeUint64(val2);
     ASSERT_EQ(sizeof(uint64_t), obuffer.getLength());
     cp = obuffer.getData();