diff options
Diffstat (limited to 'qpid/dotnet/Qpid.Buffer.Tests')
| -rw-r--r-- | qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs | 56 | ||||
| -rw-r--r-- | qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj | 83 | ||||
| -rw-r--r-- | qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs | 333 | ||||
| -rw-r--r-- | qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs | 133 | ||||
| -rw-r--r-- | qpid/dotnet/Qpid.Buffer.Tests/default.build | 48 |
5 files changed, 653 insertions, 0 deletions
diff --git a/qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs b/qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..2f49033c2d --- /dev/null +++ b/qpid/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,56 @@ +/* + * + * 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.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("Apache.Qpid.Buffer.Tests")] +[assembly: AssemblyDescription("Built from svn revision number: ")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Apache Software Foundation")] +[assembly: AssemblyProduct("Apache.Qpid.Buffer.Tests")] +[assembly: AssemblyCopyright("Apache Software Foundation")] +[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("0.5.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj b/qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj new file mode 100644 index 0000000000..72d3ccc82f --- /dev/null +++ b/qpid/dotnet/Qpid.Buffer.Tests/Qpid.Buffer.Tests.csproj @@ -0,0 +1,83 @@ +<!-- + + 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. + +--> + +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> + <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>Apache.Qpid.Buffer.Tests</RootNamespace> + <AssemblyName>Apache.Qpid.Buffer.Tests</AssemblyName> + <FileUpgradeFlags> + </FileUpgradeFlags> + <OldToolsVersion>2.0</OldToolsVersion> + <UpgradeBackupLocation> + </UpgradeBackupLocation> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\bin\net-2.0\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\net-2.0\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="**\*.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> diff --git a/qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs b/qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs new file mode 100644 index 0000000000..b028bdb1ee --- /dev/null +++ b/qpid/dotnet/Qpid.Buffer.Tests/SimpleByteBufferTests.cs @@ -0,0 +1,333 @@ +/* + * + * 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 Apache.Qpid.Buffer; + +namespace Apache.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); + buffer.Rewind(); + Assert.AreEqual((byte)0x02, buffer.GetByte()); + Assert.AreEqual((byte)0x03, buffer.GetByte()); + } + + [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 +} + + diff --git a/qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs b/qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs new file mode 100644 index 0000000000..7dec7c390f --- /dev/null +++ b/qpid/dotnet/Qpid.Buffer.Tests/SlicedByteBufferTests.cs @@ -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 Apache.Qpid.Buffer; + +namespace Apache.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 +} diff --git a/qpid/dotnet/Qpid.Buffer.Tests/default.build b/qpid/dotnet/Qpid.Buffer.Tests/default.build new file mode 100644 index 0000000000..77e95fb9d9 --- /dev/null +++ b/qpid/dotnet/Qpid.Buffer.Tests/default.build @@ -0,0 +1,48 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> + +<project name="Apache.Qpid.Buffer" default="test"> + + <target name="build"> + <csc target="library" + define="${build.defines}" + warnaserror="true" debug="${build.debug}" + output="${build.dir}/${project::get-name()}.Tests.dll"> + + <sources> + <include name="**/*.cs" /> + </sources> + <references> + <include name="${build.dir}/nunit.framework.dll" /> + <include name="${build.dir}/${project::get-name()}.dll" /> + </references> + + </csc> + </target> + <target name="test" depends="build"> + <nunit2> + <formatter type="${nant.formatter}" usefile="false" /> + <test assemblyname="${build.dir}/${project::get-name()}.Tests.dll" /> + </nunit2> + </target> +</project> + |
