summaryrefslogtreecommitdiff
path: root/qpid/dotnet
diff options
context:
space:
mode:
authorArnaud Simon <arnaudsimon@apache.org>2008-10-02 12:34:45 +0000
committerArnaud Simon <arnaudsimon@apache.org>2008-10-02 12:34:45 +0000
commit16abe32b572646be5e0a6a0b21cde553fa56bd67 (patch)
treeabffb1877f59f7601375499c857630f4da1d6ab4 /qpid/dotnet
parentdd2ed172b017cae24354bb0b7be9bd1f44249f3d (diff)
downloadqpid-python-16abe32b572646be5e0a6a0b21cde553fa56bd67.tar.gz
qpid-1277: fixed header conversion issues + added test
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@701107 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/dotnet')
-rw-r--r--qpid/dotnet/client-010/client/client.suobin204288 -> 517120 bytes
-rw-r--r--qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs10
-rw-r--r--qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs10
-rw-r--r--qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs2
-rw-r--r--qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs2
-rw-r--r--qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs8
-rw-r--r--qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs2
-rw-r--r--qpid/dotnet/client-010/test/Test.csproj1
-rw-r--r--qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs83
-rw-r--r--qpid/dotnet/client-010/test/interop/TestCase.cs28
10 files changed, 128 insertions, 18 deletions
diff --git a/qpid/dotnet/client-010/client/client.suo b/qpid/dotnet/client-010/client/client.suo
index 7b9aa32631..a78207b590 100644
--- a/qpid/dotnet/client-010/client/client.suo
+++ b/qpid/dotnet/client-010/client/client.suo
Binary files differ
diff --git a/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs b/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs
index eeb08ce2ae..44aecb0933 100644
--- a/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs
+++ b/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs
@@ -341,17 +341,17 @@ namespace org.apache.qpid.transport.codec
case Code.INT32:
return (int) readUint32();
- case Code.FLOAT:
- return (float) readUint32();
-
+ case Code.FLOAT:
+ return (float)BitConverter.Int64BitsToDouble(readUint32() << 32);
+
case Code.BIN64:
case Code.UINT64:
case Code.INT64:
case Code.DATETIME:
return readUint64();
- case Code.DOUBLE:
- return (double) readUint64();
+ case Code.DOUBLE:
+ return BitConverter.Int64BitsToDouble(readUint64());
case Code.UUID:
return readUuid();
case Code.STR8:
diff --git a/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs b/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs
index f70eb17a55..c89b96462e 100644
--- a/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs
+++ b/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs
@@ -23,7 +23,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
-using org.apache.qpid.transport.codec;
using org.apache.qpid.transport.util;
namespace org.apache.qpid.transport.codec
@@ -482,7 +481,8 @@ namespace org.apache.qpid.transport.codec
put((Byte) value);
break;
case Code.CHAR:
- put((byte) value);
+ byte[] b = BitConverter.GetBytes((char) value);
+ put(b[0]);
break;
case Code.BOOLEAN:
if ((bool) value)
@@ -516,18 +516,18 @@ namespace org.apache.qpid.transport.codec
break;
case Code.FLOAT:
- writeUint32((long) value);
+ writeUint32(BitConverter.DoubleToInt64Bits((float) value) >> 32);
break;
case Code.BIN64:
case Code.UINT64:
- case Code.INT64:
+ case Code.INT64:
case Code.DATETIME:
writeUint64((long) value);
break;
case Code.DOUBLE:
- writeUint64((long) value);
+ writeUint64( BitConverter.DoubleToInt64Bits((double) value));
break;
case Code.UUID:
diff --git a/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs b/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs
index a4f2a24801..cc8971d38b 100644
--- a/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs
+++ b/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs
@@ -76,7 +76,7 @@ namespace org.apache.qpid.transport.codec
public override long readUint64()
{
- return (long) ByteEncoder.GetBigEndian((Double) reader.ReadInt64());
+ return (long) ByteEncoder.GetBigEndian(reader.ReadInt64());
}
}
} \ No newline at end of file
diff --git a/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs b/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs
index bb78aa8680..b2ccbb89ae 100644
--- a/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs
+++ b/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs
@@ -90,7 +90,7 @@ namespace org.apache.qpid.transport.codec
public override void writeUint64(long l)
{
- _writer.Write(ByteEncoder.GetBigEndian((Double) l));
+ _writer.Write(ByteEncoder.GetBigEndian(l));
}
protected override int beginSize8()
diff --git a/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs b/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs
index 75526eb432..fc5cc7127a 100644
--- a/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs
+++ b/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs
@@ -63,7 +63,7 @@ namespace org.apache.qpid.transport.util
/// </summary>
/// <param name="value">Value to encode.</param>
/// <returns>Big-endian encoded value.</returns>
- public static Double GetBigEndian(Double value)
+ public static long GetBigEndian(long value)
{
if (BitConverter.IsLittleEndian)
{
@@ -131,7 +131,7 @@ namespace org.apache.qpid.transport.util
/// </summary>
/// <param name="value">Value to encode.</param>
/// <returns>Little-endian encoded value.</returns>
- public static Double GetLittleEndian(Double value)
+ public static Double GetLittleEndian(long value)
{
if (BitConverter.IsLittleEndian)
{
@@ -187,11 +187,11 @@ namespace org.apache.qpid.transport.util
/// </summary>
/// <param name="value"><see cref="Double"/> to swap.</param>
/// <returns>Byte order swapped <see cref="Double"/> value.</returns>
- private static Double swapByteOrder(Double value)
+ private static long swapByteOrder(long value)
{
Byte[] buffer = BitConverter.GetBytes(value);
Array.Reverse(buffer, 0, buffer.Length);
- return BitConverter.ToDouble(buffer, 0);
+ return BitConverter.ToInt64(buffer, 0);
}
#endregion
}
diff --git a/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs b/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs
index 13bdc8caf1..3c08a7162f 100644
--- a/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs
+++ b/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs
@@ -24,7 +24,7 @@ using System.Threading;
namespace common.org.apache.qpid.transport.util
{
- internal class CircularBuffer<T>
+ public class CircularBuffer<T>
{
private readonly T[] buffer;
private Int32 nrp, nwp;
diff --git a/qpid/dotnet/client-010/test/Test.csproj b/qpid/dotnet/client-010/test/Test.csproj
index 841e2385a0..e46c9768cc 100644
--- a/qpid/dotnet/client-010/test/Test.csproj
+++ b/qpid/dotnet/client-010/test/Test.csproj
@@ -42,6 +42,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="interop\Admin.cs" />
+ <Compile Include="interop\ApplicationHeaders.cs" />
<Compile Include="interop\Message.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="interop\TestCase.cs" />
diff --git a/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs b/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs
new file mode 100644
index 0000000000..9e27673a49
--- /dev/null
+++ b/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs
@@ -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.
+*
+*/
+using System;
+using common.org.apache.qpid.transport.util;
+using NUnit.Framework;
+using org.apache.qpid.client;
+using org.apache.qpid.transport.util;
+
+namespace test.interop
+{
+ public class ApplicationHeaders:TestCase
+ {
+ private static readonly Logger _log = Logger.get(typeof(ApplicationHeaders));
+
+ [Test]
+ public void setHeaders()
+ {
+ _log.debug("Running: setHeaders");
+ ClientSession ssn = Client.createSession(0);
+ ssn.queueDeclare("queue1");
+ ssn.exchangeBind("queue1", "amq.direct", "queue1");
+ ssn.sync();
+ CircularBuffer<IMessage> buff = new CircularBuffer<IMessage>(10);
+ SyncListener listener = new SyncListener(ssn, buff);
+ ssn.attachMessageListener(listener, "queue1");
+ ssn.messageSubscribe("queue1");
+
+ IMessage message = new org.apache.qpid.client.Message();
+ message.DeliveryProperties.setRoutingKey("queue1");
+ const long someLong = 14444444;
+ message.ApplicationHeaders.Add("someLong", someLong);
+ const int someInt = 14;
+ message.ApplicationHeaders.Add("soneInt", someInt);
+ const float someFloat = 14.001F;
+ message.ApplicationHeaders.Add("soneFloat", someFloat);
+ const double someDouble = 14.5555555;
+ message.ApplicationHeaders.Add("someDouble", someDouble);
+ const byte someByte = 2;
+ message.ApplicationHeaders.Add("someByte", someByte);
+ const string someString = "someString";
+ message.ApplicationHeaders.Add("someString", someString);
+ const char someChar = 'a';
+ message.ApplicationHeaders.Add("someChar", someChar);
+ const Boolean someBoolean = true;
+ message.ApplicationHeaders.Add("someBoolean", someBoolean);
+
+ // transfer the message
+ ssn.messageTransfer("amq.direct", message);
+
+ // get the message and check the headers
+ IMessage messageBack = buff.Dequeue();
+ Assert.IsTrue(((string) messageBack.ApplicationHeaders["someString"]).Equals(someString));
+ Assert.IsTrue(((char)messageBack.ApplicationHeaders["someChar"]).Equals(someChar));
+ Assert.IsTrue((long)messageBack.ApplicationHeaders["someLong"] == someLong);
+ Assert.IsTrue((int)messageBack.ApplicationHeaders["soneInt"] == someInt);
+ Assert.IsTrue((double)messageBack.ApplicationHeaders["someDouble"] == someDouble);
+ Assert.IsTrue((byte) messageBack.ApplicationHeaders["someByte"] == someByte);
+ Assert.IsTrue((Boolean)messageBack.ApplicationHeaders["someBoolean"]);
+ // c# has an conversion precision issue with decimal
+ Assert.IsTrue((float) messageBack.ApplicationHeaders["soneFloat"] <= someFloat);
+ float b = (float) messageBack.ApplicationHeaders["soneFloat"];
+ Assert.IsTrue(Convert.ToInt32(b) == Convert.ToInt32(someFloat));
+ }
+ }
+}
diff --git a/qpid/dotnet/client-010/test/interop/TestCase.cs b/qpid/dotnet/client-010/test/interop/TestCase.cs
index 9f410a9e9e..16a5522726 100644
--- a/qpid/dotnet/client-010/test/interop/TestCase.cs
+++ b/qpid/dotnet/client-010/test/interop/TestCase.cs
@@ -22,10 +22,14 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Threading;
using System.Xml;
+using common.org.apache.qpid.transport.util;
using log4net.Config;
using NUnit.Framework;
using org.apache.qpid.client;
+using org.apache.qpid.transport;
+using org.apache.qpid.transport.util;
namespace test.interop
{
@@ -85,7 +89,29 @@ namespace test.interop
public Dictionary<string,string> Properties
{
get { return _properties; }
- }
+ }
+
+
+ public class SyncListener : IMessageListener
+ {
+ private static readonly Logger _log = Logger.get(typeof(SyncListener));
+ private readonly CircularBuffer<IMessage> _buffer;
+ private readonly RangeSet _range = new RangeSet();
+ private readonly ClientSession _session;
+ public SyncListener(ClientSession session, CircularBuffer<IMessage> buffer)
+ {
+ _buffer = buffer;
+ _session = session;
+ }
+
+ public void messageTransfer(IMessage m)
+ {
+ _range.clear();
+ _range.add(m.Id);
+ _session.messageAccept(_range);
+ _buffer.Enqueue(m);
+ }
+ }
}
}