Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
added a check to validate that ArrayOffset is independent from Reader…
Browse files Browse the repository at this point in the history
…Index
  • Loading branch information
Aaronontheweb committed May 13, 2016
1 parent 8a97403 commit 8502cf2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/Helios.Tests/Buffer/ByteBufferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information.
// See ThirdPartyNotices.txt for references to third party code used inside Helios.

using System;
using System.Linq;
using System.Text;
using Helios.Buffers;
using Helios.Util;
using Xunit;

namespace Helios.Tests.Buffer
Expand Down Expand Up @@ -186,6 +188,26 @@ public void Should_export_readable_bytes_ToArray()
}

#endregion

#region Array operations

[Fact]
public void Should_get_correct_ArrayOffset_and_copy_ByteBuffer_contents_to_array()
{
var originalBuffer = GetBuffer(1024);
var bytes = Guid.NewGuid().ToByteArray();

// advance the read position beyond the original value
originalBuffer.WriteInt(4).WriteBytes(bytes);
var myInt = originalBuffer.ReadInt();
Assert.Equal(4, myInt);

var newBytes = new byte[originalBuffer.ReadableBytes];
Array.Copy(originalBuffer.Array, originalBuffer.ArrayOffset + originalBuffer.ReaderIndex, newBytes, 0, originalBuffer.ReadableBytes);
Assert.True(bytes.SequenceEqual(newBytes));
}

#endregion
}
}

0 comments on commit 8502cf2

Please sign in to comment.