Author: rgreig
Date: Mon Feb 26 09:46:07 2007
New Revision: 511923

URL: http://svn.apache.org/viewvc?view=rev&rev=511923
Log:
(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.

Added:
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/   (with props)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Properties/
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/SimpleByteBuffer.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/SlicedByteBuffer.cs
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Common.Tests/Qpid/Framing/TestEncodingUtils.cs
Removed:
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/BaseByteBuffer.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/BufferDataException.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/ByteBufferProxy.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/FixedByteBuffer.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/HeapByteBuffer.cs
Modified:
    incubator/qpid/trunk/qpid/dotnet/   (props changed)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/   (props changed)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/ByteBuffer.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/ByteBufferHexDumper.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/IByteBufferAllocator.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/Qpid.Buffer.csproj
    incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/SimpleByteBufferAllocator.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Client/   (props changed)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/   (props changed)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/AmqChannel.cs
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Message/AMQMessageFactory.cs
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Message/AbstractQmsMessage.cs
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Message/QpidBytesMessage.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Message/QpidHeaders.cs
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Message/QpidTextMessage.cs
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/BlockingSocketProcessor.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Codec/   (props changed)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Codec/CumulativeProtocolDecoder.cs
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Codec/Demux/DemuxingProtocolCodecFactory.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/   (props changed)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common.Tests/Qpid.Common.Tests.csproj
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Common.Tests/Qpid/Framing/TestAMQType.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/AMQDataBlockDecoder.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/AMQDataBlockEncoder.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/AMQFrame.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/AMQMethodBody.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/AMQMethodBodyFactory.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/AMQType.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/AMQTypedValue.cs
    
incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/BasicContentHeaderProperties.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/ContentBody.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/ContentHeaderBody.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/EncodingUtils.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/FieldTable.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/HeartbeatBody.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Framing/ProtocolInitiation.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/Qpid.Common.csproj
    incubator/qpid/trunk/qpid/dotnet/Qpid.Common/stylesheets/utils.xsl
    incubator/qpid/trunk/qpid/dotnet/Qpid.Messaging/   (props changed)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Messaging/IHeaders.cs
    incubator/qpid/trunk/qpid/dotnet/Qpid.NET.sln
    incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl/   (props changed)
    incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl.Tests/   (props changed)

Propchange: incubator/qpid/trunk/qpid/dotnet/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Feb 26 09:46:07 2007
@@ -1,3 +1,4 @@
 *.pidb
 build
 dotnet.userprefs
+_ReSharper.Qpid.NET

Propchange: incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Feb 26 09:46:07 2007
@@ -1,2 +1,3 @@
 *.pidb
 bin
+obj

Propchange: incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Feb 26 09:46:07 2007
@@ -0,0 +1,2 @@
+bin
+obj

Added: 
incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs?view=auto&rev=511923
==============================================================================
--- 
incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs 
(added)
+++ 
incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs 
Mon Feb 26 09:46:07 2007
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Qpid.Buffer.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Qpid.Buffer.Tests")]
+[assembly: AssemblyCopyright("Copyright ©  2007")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed 
to COM
+[assembly: Guid("9d967d0b-9454-4f00-8f53-fa86fd62b696")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Revision and Build 
Numbers 
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

Added: 
incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj?view=auto&rev=511923
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj 
(added)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj 
Mon Feb 26 09:46:07 2007
@@ -0,0 +1,59 @@
+<Project DefaultTargets="Build" 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003";>
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.50727</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{74640962-99D0-4D06-B57A-9CD66517CF52}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Qpid.Buffer.Tests</RootNamespace>
+    <AssemblyName>Qpid.Buffer.Tests</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' 
">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <UseVSHostingProcess>true</UseVSHostingProcess>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 
'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, 
PublicKeyToken=96d09a1eb7f44a77">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Qpid.Client.Tests\lib\nunit\nunit.framework.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="SlicedByteBufferTests.cs" />
+    <Compile Include="SimpleByteBufferTests.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Qpid.Buffer\Qpid.Buffer.csproj">
+      <Project>{44384DF2-B0A4-4580-BDBC-EE4BAA87D995}</Project>
+      <Name>Qpid.Buffer</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets 
below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

Added: 
incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs?view=auto&rev=511923
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs 
(added)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs 
Mon Feb 26 09:46:07 2007
@@ -0,0 +1,328 @@
+/*
+ *
+ * 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 NUnit.Framework;
+using Qpid.Buffer;
+
+namespace Qpid.Buffer.Tests
+{
+   /// <summary>
+   /// Tests for the SimpleByteBuffer class
+   /// </summary>
+   [TestFixture]
+   public class SimpleByteBufferTests
+   {
+      [Test]
+      public void CanCreateNewBuffer()
+      {
+         const int size = 10;
+         ByteBuffer buffer = ByteBuffer.Allocate(size);
+         Assert.AreEqual(size, buffer.Capacity);
+         Assert.AreEqual(0, buffer.Position);
+         Assert.AreEqual(size, buffer.Remaining);
+         Assert.AreEqual(true, buffer.HasRemaining);
+      }
+
+      [Test]
+      public void CanWrapArray()
+      {
+         byte[] array = new byte[10];
+         for ( int i=0; i < array.Length; i++ )
+         {
+            array[i] = (byte) i;
+         }
+         ByteBuffer buffer = ByteBuffer.Wrap(array);
+         // the buffer should be the same size, 
+         // and positioned at the end
+         Assert.AreEqual(array.Length, buffer.Capacity);
+         Assert.AreEqual(array.Length, buffer.Position);
+         Assert.AreEqual(array.Length, buffer.Limit);
+      }
+
+      #region Base Read/Write tests
+      //
+      // Base Read/Write tests
+      //
+      [Test]
+      public void CanReadWriteBytes()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Put((byte)0x01).Put((byte)0x02).Put((byte)0x03);
+         buffer.Rewind();
+         Assert.AreEqual(0x01, buffer.GetByte());
+         Assert.AreEqual(0x02, buffer.GetByte());
+         Assert.AreEqual(0x03, buffer.GetByte());
+      }
+
+      [Test]
+      [ExpectedException(typeof(BufferUnderflowException))]
+      public void ThrowOnReadByteWithNoSpace()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(1);
+         buffer.Put((byte)0x01);
+         buffer.GetByte();
+      }
+
+      [Test]
+      [ExpectedException(typeof(BufferOverflowException))]
+      public void ThrowOnWriteByteWithNoSpace()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(1);
+         buffer.Put((byte)0x01).Put((byte)0x02);
+      }
+
+      #endregion Base Read/Write tests
+
+      #region Other Buffer Operations
+      //
+      // Other Buffer Operations
+      //
+      
+      [Test]
+      public void CanFlipBuffer()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Put((byte)0x01).Put((byte)0x02).Put((byte)0x03);
+         buffer.Flip();
+         Assert.AreEqual(10, buffer.Capacity);
+         Assert.AreEqual(3, buffer.Limit);
+         Assert.AreEqual(0, buffer.Position);
+         Assert.AreEqual(3, buffer.Remaining);
+      }
+
+      [Test]
+      public void CanCompactBuffer()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Put((byte)0x01).Put((byte)0x02).Put((byte)0x03);
+         buffer.Flip();
+         buffer.Position = 1;
+         buffer.Compact();
+         Assert.AreEqual(10, buffer.Capacity);
+         Assert.AreEqual(10, buffer.Limit);
+         Assert.AreEqual(2, buffer.Position);
+         Assert.AreEqual(8, buffer.Remaining);
+      }
+
+      [Test]
+      public void CanClearBuffer()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Put((byte)0x01).Put((byte)0x02).Put((byte)0x03);
+         buffer.Flip();
+         buffer.Position = 2;
+         buffer.Clear();
+         Assert.AreEqual(10, buffer.Capacity);
+         Assert.AreEqual(10, buffer.Limit);
+         Assert.AreEqual(0, buffer.Position);
+         Assert.AreEqual(10, buffer.Remaining);
+      }
+
+      [Test]
+      public void CanExpandBuffer()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Put((byte)0x01).Put((byte)0x02).Put((byte)0x03);
+         buffer.Flip();
+         buffer.Position = 2;
+         int pos = buffer.Position;
+         buffer.Expand(20);
+
+         Assert.AreEqual(pos, buffer.Position);
+         Assert.IsTrue(buffer.Remaining >= 20);
+         buffer.Rewind();
+         Assert.AreEqual(0x01, buffer.GetByte());
+      }
+
+      [Test]
+      public void CanAutoExpand()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(2);
+         buffer.IsAutoExpand = true;
+         // should cause autoexpand
+         buffer.Put((byte)0x01).Put((byte)0x02).Put((byte)0x03);
+         Assert.IsTrue(buffer.Capacity > 2);
+      }
+
+      [Test]
+      public void CanGetArray()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Put((byte)0x01).Put((byte)0x02).Put((byte)0x03);
+         buffer.Flip();
+
+         byte[] array = buffer.Array;
+         for ( int i=0; i < buffer.Limit; i++ )
+         {
+            Assert.AreEqual(buffer.GetByte(), array[i]);
+         }
+      }
+
+      [Test]
+      public void CanSkip()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Skip(4);
+         Assert.AreEqual(4, buffer.Position);
+      }
+
+      #endregion // Base Read/Write tests
+
+      #region Typed Accessors
+      //
+      // Typed Accessors
+      //
+      [Test]
+      public void CanReadWriteSByte()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         sbyte value = -12;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetSByte());
+      }
+      [Test]
+      public void CanReadWriteUInt16()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         ushort value = 41233;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetUInt16());
+      }
+      [Test]
+      public void CanReadWriteInt16()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         short value = -21233;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetInt16());
+      }
+      [Test]
+      public void CanReadWriteUInt32()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         uint value = 41233211;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetUInt32());
+      }
+      [Test]
+      public void CanReadWriteInt32()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         int value = -22221233;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetInt32());
+      }
+      [Test]
+      public void CanReadWriteUInt64()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         ulong value = 41233218871;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetUInt64());
+      }
+      [Test]
+      public void CanReadWriteInt64()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         long value = -9887335411;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetInt64());
+      }
+      [Test]
+      public void CanReadWriteFloat()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         float value = -1.2331f;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetFloat());
+      }
+
+      [Test]
+      public void CanReadWriteDouble()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         double value = -1.2331E12;
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetDouble());
+      }
+
+      [Test]
+      public void CanReadWriteChar()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         char value = 'H';
+         buffer.Put(value);
+         buffer.Flip();
+         Assert.AreEqual(value, buffer.GetChar());
+      }
+
+      [Test]
+      public void CanReadWriteByteArray()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Put(new byte[] { 0x01, 0x02, 0x03});
+         buffer.Flip();
+         byte[] data = new byte[3];
+         buffer.GetBytes(data);
+         Assert.AreEqual(0x01, data[0]);
+         Assert.AreEqual(0x02, data[1]);
+         Assert.AreEqual(0x03, data[2]);
+      }
+
+      [Test]
+      public void CanReadWriteByteArrayWithOffset()
+      {
+         ByteBuffer buffer = ByteBuffer.Allocate(10);
+         buffer.Put(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }, 1, 4);
+         buffer.Flip();
+         byte[] data = new byte[3];
+         buffer.GetBytes(data, 2, 1);
+         Assert.AreEqual(0x00, data[0]);
+         Assert.AreEqual(0x00, data[1]);
+         Assert.AreEqual(0x02, data[2]);
+      }
+
+      [Test]
+      public void CanWriteByteBuffer()
+      {
+         ByteBuffer buffer1 = ByteBuffer.Allocate(10);
+         buffer1.Put((byte)0x01).Put((byte)0x02).Put((byte)0x03);
+         buffer1.Flip();
+
+         ByteBuffer buffer2 = ByteBuffer.Allocate(10);
+         buffer2.Put(buffer1);
+         buffer2.Flip();
+         Assert.AreEqual(buffer1.Limit, buffer2.Limit);
+         Assert.AreEqual(0x01, buffer2.GetByte());
+      }
+      #endregion // Typed Accessors
+
+   } // class SimpleByteBufferTests
+}

Added: 
incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs?view=auto&rev=511923
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs 
(added)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs 
Mon Feb 26 09:46:07 2007
@@ -0,0 +1,133 @@
+/*
+ *
+ * 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;
+
+namespace Qpid.Buffer.Tests
+{
+   /// <summary>
+   /// Tests for the SlicedByteBuffer class
+   /// </summary>
+   [TestFixture]
+   public class SlicedByteBufferTests
+   {
+      private ByteBuffer _baseBuffer;
+
+      [SetUp]
+      public void Setup()
+      {
+         const int size = 50;
+         _baseBuffer = ByteBuffer.Allocate(size);
+         for ( byte b = 0; b < 10; b++ )
+         {
+            _baseBuffer.Put(b);
+         }
+         _baseBuffer.Flip();
+      }
+
+      [Test]
+      public void CanSliceBuffer()
+      {
+         _baseBuffer.Position = 5;
+
+         ByteBuffer slice = _baseBuffer.Slice();
+         Assert.AreEqual(5, slice.Capacity);
+         Assert.AreEqual(0, slice.Position);
+         Assert.AreEqual(5, slice.Remaining);
+         Assert.AreEqual(5, slice.Limit);
+      }
+
+      [Test]
+      public void CanReadWriteSlice()
+      {
+         _baseBuffer.Position = 5;
+
+         ByteBuffer slice = _baseBuffer.Slice();
+         slice.Put((byte) 0xFF).Put((byte) 0xF0).Put((byte) 0xA0);
+         slice.Flip();
+
+         Assert.AreEqual(3, slice.Limit);
+         Assert.AreEqual(0xFF, slice.GetByte());
+         Assert.AreEqual(0xF0, slice.GetByte());
+         Assert.AreEqual(0xA0, slice.GetByte());
+      }
+
+      [Test]
+      public void WriteModifiesBaseBufferOnCorrectPosition()
+      {
+         _baseBuffer.Position = 5;
+
+         ByteBuffer slice = _baseBuffer.Slice();
+         slice.Put((byte) 0xFF);
+         slice.Flip();
+         // reading the _baseBuffer at position 5 should yield 0xFF
+         _baseBuffer.Position = 5;
+         Assert.AreEqual(0xFF, _baseBuffer.GetByte());
+         
+      }
+
+      [Test]
+      public void CanReadWriteByteArray()
+      {
+         _baseBuffer.Position = 5;
+
+         ByteBuffer slice = _baseBuffer.Slice();
+         byte[] data = {0xFF, 0xF0, 0xF2, 0xEE, 0x23};
+         slice.Put(data, 2, 2);
+         slice.Flip();
+
+         Assert.AreEqual(2, slice.Limit);
+         Assert.AreEqual(0xF2, slice.GetByte());
+         Assert.AreEqual(0xEE, slice.GetByte());
+      }
+
+      [Test]
+      [ExpectedException(typeof(BufferOverflowException))]
+      public void ThrowWhenWritePastLimit()
+      {
+         _baseBuffer.Position = 5;
+
+         ByteBuffer slice = _baseBuffer.Slice();
+         slice.Put(0x01).Put(0x02);
+      }
+
+
+      [Test]
+      [ExpectedException(typeof(NotSupportedException))]
+      public void ThrowOnCompact()
+      {
+         // we don't support compacting
+         ByteBuffer slice = _baseBuffer.Slice();
+         slice.Compact();
+      }
+
+      [Test]
+      [ExpectedException(typeof(NotSupportedException))]
+      public void ThrowOnResize()
+      {
+         // we don't support resizing
+         ByteBuffer slice = _baseBuffer.Slice();
+         slice.Expand(50);
+      }
+   } // class SlicedByteBufferTests
+}


Reply via email to