mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-26 10:59:49 +08:00
Motivation: Implement commonly used string-based operations (originally Netty CharSequence) for byte buffers. Modifications: Added read/write/get/set strings methods to byte buffers. Also reduced unsafe pin/unpins for byte operations. Result: String-based operations are supported in DotNetty
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
namespace DotNetty.Buffers.Tests
|
|
{
|
|
using System;
|
|
using Xunit;
|
|
|
|
public class EmptyByteBufferTests
|
|
{
|
|
[Fact]
|
|
public void IsWritable()
|
|
{
|
|
var empty = new EmptyByteBuffer(UnpooledByteBufferAllocator.Default);
|
|
Assert.False(empty.IsWritable());
|
|
Assert.False(empty.IsWritable(1));
|
|
}
|
|
|
|
[Fact]
|
|
public void WriteEmptyByteBuf()
|
|
{
|
|
var empty = new EmptyByteBuffer(UnpooledByteBufferAllocator.Default);
|
|
empty.WriteBytes(Unpooled.Empty); // Ok
|
|
IByteBuffer nonEmpty = UnpooledByteBufferAllocator.Default.Buffer().WriteBoolean(false);
|
|
Assert.Throws<IndexOutOfRangeException>(() => empty.WriteBytes(nonEmpty));
|
|
nonEmpty.Release();
|
|
}
|
|
|
|
[Fact]
|
|
public void IsReadable()
|
|
{
|
|
var empty = new EmptyByteBuffer(UnpooledByteBufferAllocator.Default);
|
|
Assert.False(empty.IsReadable());
|
|
Assert.False(empty.IsReadable(1));
|
|
}
|
|
|
|
[Fact]
|
|
public void Array()
|
|
{
|
|
var empty = new EmptyByteBuffer(UnpooledByteBufferAllocator.Default);
|
|
Assert.True(empty.HasArray);
|
|
Assert.Empty(empty.Array);
|
|
Assert.Equal(0, empty.ArrayOffset);
|
|
}
|
|
|
|
[Fact]
|
|
public void MemoryAddress()
|
|
{
|
|
var empty = new EmptyByteBuffer(UnpooledByteBufferAllocator.Default);
|
|
Assert.False(empty.HasMemoryAddress);
|
|
Assert.Throws<NotSupportedException>(() => empty.GetPinnableMemoryAddress());
|
|
}
|
|
}
|
|
}
|