]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3443] Added additional buffer tests
authorStephen Morris <stephen@isc.org>
Tue, 13 Oct 2015 15:16:29 +0000 (16:16 +0100)
committerStephen Morris <stephen@isc.org>
Tue, 13 Oct 2015 15:16:29 +0000 (16:16 +0100)
Check that an empty buffer can be copied and assigned from.  Also
check that a buffer copy and assignment do create copies of the
data, and the new objects do not merely point to the original data.

src/lib/util/tests/buffer_unittest.cc

index 420c69f39148d4e080c559660f1951f0b14bb7de..02994299885f1a38738319136517969bbb098160 100644 (file)
@@ -237,6 +237,7 @@ TEST_F(BufferTest, outputBufferCopy) {
     EXPECT_NO_THROW({
         OutputBuffer copy(obuffer);
         ASSERT_EQ(sizeof(testdata), copy.getLength());
+        ASSERT_NE(obuffer.getData(), copy.getData());
         for (int i = 0; i < sizeof(testdata); i ++) {
             EXPECT_EQ(testdata[i], copy[i]);
             if (i + 1 < sizeof(testdata)) {
@@ -249,6 +250,13 @@ TEST_F(BufferTest, outputBufferCopy) {
     });
 }
 
+TEST_F(BufferTest, outputEmptyBufferCopy) {
+    EXPECT_NO_THROW({
+        OutputBuffer copy(obuffer);
+        ASSERT_EQ(0, copy.getLength());
+    });
+}
+
 TEST_F(BufferTest, outputBufferAssign) {
     OutputBuffer another(0);
     another.clear();
@@ -257,6 +265,7 @@ TEST_F(BufferTest, outputBufferAssign) {
     EXPECT_NO_THROW({
         another = obuffer;
         ASSERT_EQ(sizeof(testdata), another.getLength());
+        ASSERT_NE(obuffer.getData(), another.getData());
         for (int i = 0; i < sizeof(testdata); i ++) {
             EXPECT_EQ(testdata[i], another[i]);
             if (i + 1 < sizeof(testdata)) {
@@ -269,6 +278,14 @@ TEST_F(BufferTest, outputBufferAssign) {
     });
 }
 
+TEST_F(BufferTest, outputEmptyBufferAssign) {
+    EXPECT_NO_THROW({
+        OutputBuffer copy(0);
+        copy = obuffer;
+        ASSERT_EQ(0, copy.getLength());
+    });
+}
+
 // Check assign to self doesn't break stuff
 TEST_F(BufferTest, outputBufferAssignSelf) {
     EXPECT_NO_THROW(obuffer = obuffer);