diff options
| author | Robert Greig <rgreig@apache.org> | 2007-02-26 17:46:07 +0000 |
|---|---|---|
| committer | Robert Greig <rgreig@apache.org> | 2007-02-26 17:46:07 +0000 |
| commit | 3bfaba7fd65f251b68e8c4085582a4b62edf8e5d (patch) | |
| tree | 6e90ae3729802623450af664e0a39a52f5f1b3f3 /dotnet/Qpid.Common.Tests | |
| parent | 2ea003c24ab3170dec118af6f9f8c128241cec65 (diff) | |
| download | qpid-python-3bfaba7fd65f251b68e8c4085582a4b62edf8e5d.tar.gz | |
(Patch submitted by Tomas Restrepo) QPID-ByteBuffer.diff.
Completely refactors the byte buffer implementation, doing away with a complex inheritance hierarchy.
Fixes reading and writing of field table to permit interop with Java client.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@511923 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'dotnet/Qpid.Common.Tests')
| -rw-r--r-- | dotnet/Qpid.Common.Tests/Qpid.Common.Tests.csproj | 1 | ||||
| -rw-r--r-- | dotnet/Qpid.Common.Tests/Qpid/Framing/TestAMQType.cs | 66 | ||||
| -rw-r--r-- | dotnet/Qpid.Common.Tests/Qpid/Framing/TestEncodingUtils.cs | 60 |
3 files changed, 94 insertions, 33 deletions
diff --git a/dotnet/Qpid.Common.Tests/Qpid.Common.Tests.csproj b/dotnet/Qpid.Common.Tests/Qpid.Common.Tests.csproj index 8c5142e690..684d21b324 100644 --- a/dotnet/Qpid.Common.Tests/Qpid.Common.Tests.csproj +++ b/dotnet/Qpid.Common.Tests/Qpid.Common.Tests.csproj @@ -40,6 +40,7 @@ <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Qpid\Collections\TestLinkedHashtable.cs" />
+ <Compile Include="Qpid\Framing\TestEncodingUtils.cs" />
<Compile Include="Qpid\Framing\TestAMQType.cs" />
</ItemGroup>
<ItemGroup>
diff --git a/dotnet/Qpid.Common.Tests/Qpid/Framing/TestAMQType.cs b/dotnet/Qpid.Common.Tests/Qpid/Framing/TestAMQType.cs index 805d728db6..f5ff30182d 100644 --- a/dotnet/Qpid.Common.Tests/Qpid/Framing/TestAMQType.cs +++ b/dotnet/Qpid.Common.Tests/Qpid/Framing/TestAMQType.cs @@ -34,12 +34,12 @@ namespace Qpid.Framing.Tests public void LONG_STRING_ReadWrite()
{
AMQType type = AMQType.LONG_STRING;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
const string VALUE = "simple string 1";
type.WriteToBuffer(VALUE, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(VALUE, value.Value);
}
@@ -75,12 +75,12 @@ namespace Qpid.Framing.Tests public void UINT32_ReadWrite()
{
AMQType type = AMQType.UINT32;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
const uint VALUE = 0xFFEEDDCC;
type.WriteToBuffer(VALUE, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(VALUE, value.Value);
}
@@ -113,11 +113,11 @@ namespace Qpid.Framing.Tests public void VOID_ReadWrite()
{
AMQType type = AMQType.VOID;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
type.WriteToBuffer(null, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(null, value.Value);
}
@@ -152,11 +152,11 @@ namespace Qpid.Framing.Tests public void BOOLEAN_ReadWrite()
{
AMQType type = AMQType.BOOLEAN;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
type.WriteToBuffer(true, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(true, value.Value);
}
@@ -167,24 +167,24 @@ namespace Qpid.Framing.Tests public void INT16_ReadWrite()
{
AMQType type = AMQType.INT16;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
const short VALUE = -32765;
type.WriteToBuffer(VALUE, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(VALUE, value.Value);
}
//public void UINT16_ReadWrite()
//{
// AMQType type = AMQType.UINT16;
- // ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ // ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
// const ushort VALUE = 64321;
// type.WriteToBuffer(VALUE, buffer);
- // buffer.flip();
- // buffer.position(0);
+ // buffer.Flip();
+ // buffer.Rewind();
// AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
// Assert.AreEqual(VALUE, value.Value);
//}
@@ -195,12 +195,12 @@ namespace Qpid.Framing.Tests public void INT32_ReadWrite()
{
AMQType type = AMQType.INT32;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
const int VALUE = -39273563;
type.WriteToBuffer(VALUE, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(VALUE, value.Value);
}
@@ -211,12 +211,12 @@ namespace Qpid.Framing.Tests public void INT64_ReadWrite()
{
AMQType type = AMQType.INT64;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
const long VALUE = -(2^43+1233123);
type.WriteToBuffer(VALUE, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(VALUE, value.Value);
}
@@ -224,12 +224,12 @@ namespace Qpid.Framing.Tests public void UINT64_ReadWrite()
{
AMQType type = AMQType.UINT64;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
const ulong VALUE = (2 ^ 61 + 1233123);
type.WriteToBuffer(VALUE, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(VALUE, value.Value);
}
@@ -240,12 +240,12 @@ namespace Qpid.Framing.Tests public void FLOAT_ReadWrite()
{
AMQType type = AMQType.FLOAT;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
const float VALUE = 1.2345000E-035f;
type.WriteToBuffer(VALUE, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(VALUE, value.Value);
}
@@ -256,12 +256,12 @@ namespace Qpid.Framing.Tests public void DOUBLE_ReadWrite()
{
AMQType type = AMQType.DOUBLE;
- ByteBuffer buffer = (new SimpleByteBufferAllocator()).Allocate(0x1000, false);
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
const double VALUE = 1.2345000E-045;
type.WriteToBuffer(VALUE, buffer);
- buffer.flip();
- buffer.position(0);
+ buffer.Flip();
+ buffer.Rewind();
AMQTypedValue value = AMQTypedValue.ReadFromBuffer(buffer);
Assert.AreEqual(VALUE, value.Value);
}
diff --git a/dotnet/Qpid.Common.Tests/Qpid/Framing/TestEncodingUtils.cs b/dotnet/Qpid.Common.Tests/Qpid/Framing/TestEncodingUtils.cs new file mode 100644 index 0000000000..7c6615ed1e --- /dev/null +++ b/dotnet/Qpid.Common.Tests/Qpid/Framing/TestEncodingUtils.cs @@ -0,0 +1,60 @@ +/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+using System;
+using NUnit.Framework;
+using Qpid.Buffer;
+using Qpid.Framing;
+
+namespace Qpid.Framing.Tests
+{
+ [TestFixture]
+ public class TestEncodingUtils
+ {
+ [Test]
+ public void CanReadLongAsShortString()
+ {
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
+ EncodingUtils.WriteShortStringBytes(buffer, "98878122");
+ buffer.Flip();
+ long value = EncodingUtils.ReadLongAsShortString(buffer);
+ Assert.AreEqual(98878122, value);
+ }
+ [Test]
+ public void CanReadLongAsShortStringNegative()
+ {
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
+ EncodingUtils.WriteShortStringBytes(buffer, "-98878122");
+ buffer.Flip();
+ long value = EncodingUtils.ReadLongAsShortString(buffer);
+ Assert.AreEqual(-98878122, value);
+ }
+ [Test]
+ public void CanReadLongAsShortStringEmpty()
+ {
+ ByteBuffer buffer = ByteBuffer.Allocate(0x1000);
+ EncodingUtils.WriteShortStringBytes(buffer, "");
+ buffer.Flip();
+ long value = EncodingUtils.ReadLongAsShortString(buffer);
+ Assert.AreEqual(0, value);
+ }
+
+ }
+}
|
