summaryrefslogtreecommitdiff
path: root/qpid/dotnet/client-010/test/transport/util
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/dotnet/client-010/test/transport/util')
-rw-r--r--qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs106
-rw-r--r--qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs89
-rw-r--r--qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs103
-rw-r--r--qpid/dotnet/client-010/test/transport/util/SerialTest.cs75
-rw-r--r--qpid/dotnet/client-010/test/transport/util/UUIDTest.cs64
5 files changed, 437 insertions, 0 deletions
diff --git a/qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs b/qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs
new file mode 100644
index 0000000000..f3a05f1c3c
--- /dev/null
+++ b/qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs
@@ -0,0 +1,106 @@
+/*
+*
+* 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 org.apache.qpid.transport.util;
+
+
+namespace test.transport.util
+{
+ [TestFixture]
+
+ public class ByteEncoderTest
+ {
+ private static readonly Logger _log = Logger.Get(typeof(ByteEncoderTest));
+
+ [Test]
+ public void GetBigEndianInt32()
+ {
+ _log.Debug("Running: GetBigEndianInt32");
+ const int anInt = -12345;
+ Int32 aNewInt = ByteEncoder.GetBigEndian(anInt);
+ Assert.IsTrue( anInt == ByteEncoder.GetBigEndian(aNewInt) );
+ }
+
+ [Test]
+ public void GetBigEndianUInt16()
+ {
+ _log.Debug("Running: GetBigEndianUInt16");
+ const UInt16 anInt = 123;
+ UInt16 aNewInt = ByteEncoder.GetBigEndian(anInt);
+ Assert.IsTrue(anInt == ByteEncoder.GetBigEndian(aNewInt));
+ }
+
+ [Test]
+ public void GetBigEndianUInt32()
+ {
+ _log.Debug("Running: GetBigEndianUInt32");
+ const UInt32 anInt = 12345;
+ UInt32 aNewInt = ByteEncoder.GetBigEndian(anInt);
+ Assert.IsTrue(anInt == ByteEncoder.GetBigEndian(aNewInt));
+ }
+
+ [Test]
+ public void GetBigEndianlong()
+ {
+ _log.Debug("Running: GetBigEndianlong");
+ const long anInt = 123456660700770;
+ long aNewInt = ByteEncoder.GetBigEndian(anInt);
+ Assert.IsTrue(anInt == ByteEncoder.GetBigEndian(aNewInt));
+ }
+
+ [Test]
+ public void GetLittleEndianInt32()
+ {
+ _log.Debug("Running: GetBigEndianInt32");
+ const int anInt = -12345;
+ Int32 aNewInt = ByteEncoder.GetLittleEndian(anInt);
+ Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
+ }
+
+ [Test]
+ public void GetLittleEndianUInt16()
+ {
+ _log.Debug("Running: GetLittleEndianUInt16");
+ const UInt16 anInt = 123;
+ UInt16 aNewInt = ByteEncoder.GetLittleEndian(anInt);
+ Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
+ }
+
+ [Test]
+ public void GetLittleEndianUInt32()
+ {
+ _log.Debug("Running: GetLittleEndianUInt32");
+ const UInt32 anInt = 12345;
+ UInt32 aNewInt = ByteEncoder.GetLittleEndian(anInt);
+ Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
+ }
+
+ [Test]
+ public void GetLittleEndianlong()
+ {
+ _log.Debug("Running: GetLittleEndianlong");
+ const long anInt = 123456660700770;
+ long aNewInt = ByteEncoder.GetLittleEndian(anInt);
+ Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
+ }
+ }
+}
diff --git a/qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs b/qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs
new file mode 100644
index 0000000000..5e39569cf8
--- /dev/null
+++ b/qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs
@@ -0,0 +1,89 @@
+/*
+*
+* 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 System.Threading;
+using common.org.apache.qpid.transport.util;
+using NUnit.Framework;
+using org.apache.qpid.transport.util;
+
+namespace test.transport.util
+{
+ [TestFixture]
+
+ public class CircularBufferTest
+ {
+ private CircularBuffer<Object> _buf;
+ private static readonly Logger _log = Logger.Get(typeof(CircularBufferTest));
+
+ [Test]
+ public void BlockingEnqueue()
+ {
+ _log.Debug("Running: BlockingEnqueue");
+ const int size = 10;
+ _buf = new CircularBuffer<Object>(size);
+ // add size element anc check that the size +1 add blocks
+ for (int i = 1; i < size; i++ )
+ {
+ _buf.Enqueue(new object());
+ }
+ // check tha the buffer is now full
+ Thread t = new Thread(Go);
+ t.Start();
+ Thread.Sleep(100);
+ // the trhead t should block until an element is dequeued
+ Assert.IsTrue(t.ThreadState == ThreadState.WaitSleepJoin);
+ _buf.Dequeue();
+ // t should now be stopped
+ Thread.Sleep(100);
+ Assert.IsTrue(t.ThreadState == ThreadState.Stopped);
+ }
+
+ [Test]
+ public void Close()
+ {
+ _log.Debug("Running: BlockingEnqueue");
+ const int size = 10;
+ _buf = new CircularBuffer<Object>(size);
+ // add size element anc check that the size +1 add blocks
+ for (int i = 1; i < size; i++)
+ {
+ _buf.Enqueue(new object());
+ }
+ // check tha the buffer is now full
+ Thread t = new Thread(Go);
+ t.Start();
+ Thread.Sleep(1000);
+ // the trhead t should block until the buffer is closed
+ Assert.IsTrue(t.ThreadState == ThreadState.WaitSleepJoin);
+ _buf.Close();
+ Thread.Sleep(100);
+ // t should now be stopped
+ Assert.IsTrue(t.ThreadState == ThreadState.Stopped);
+ }
+
+ void Go()
+ {
+ _buf.Enqueue(new object());
+ }
+
+ }
+}
diff --git a/qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs b/qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs
new file mode 100644
index 0000000000..e8e011a1e9
--- /dev/null
+++ b/qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs
@@ -0,0 +1,103 @@
+/*
+*
+* 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 System.Collections.Generic;
+using System.Threading;
+using common.org.apache.qpid.transport.util;
+using NUnit.Framework;
+using org.apache.qpid.transport;
+using org.apache.qpid.transport.codec;
+using org.apache.qpid.transport.util;
+
+
+namespace test.transport.util
+{
+ [TestFixture]
+ public class ResultFutureTest
+ {
+ private static readonly Logger _log = Logger.Get(typeof (ByteEncoderTest));
+ private static ResultFuture _future;
+
+ [Test]
+ public void getFutureTimeout()
+ {
+ _log.Debug("Running: getFutureTimeout");
+ _future = new ResultFuture();
+ _future.Session = new Session(new byte[1]);
+ DateTime start = DateTime.Now;
+ Struct result = _future.Get(1000);
+ Assert.IsTrue(DateTime.Now.Subtract(start).TotalMilliseconds >= 1000);
+ Assert.IsNull(result);
+ }
+
+ [Test]
+ public void getFuture()
+ {
+ _log.Debug("Running: getFuture");
+ _future = new ResultFuture();
+ _future.Session = new Session(new byte[1]);
+ Thread t = new Thread(Go);
+ t.Start();
+ Struct result = _future.Get(2000);
+ Assert.IsNotNull(result);
+ }
+
+
+ void Go()
+ {
+ Thread.Sleep(500);
+ _future.Result = new myStruct();
+ }
+ }
+
+ public class myStruct:Struct
+ {
+ public override int GetStructType()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public override int GetSizeWidth()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public override int GetPackWidth()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public override void Read(IDecoder dec)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public override void Write(IEncoder enc)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public override Dictionary<string, object> Fields
+ {
+ get { throw new System.NotImplementedException(); }
+ }
+ }
+}
diff --git a/qpid/dotnet/client-010/test/transport/util/SerialTest.cs b/qpid/dotnet/client-010/test/transport/util/SerialTest.cs
new file mode 100644
index 0000000000..772327c3b0
--- /dev/null
+++ b/qpid/dotnet/client-010/test/transport/util/SerialTest.cs
@@ -0,0 +1,75 @@
+/*
+*
+* 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 org.apache.qpid.transport.util;
+
+namespace test.transport.util
+{
+ [TestFixture]
+ public class SerialTest
+ {
+ private static readonly Logger _log = Logger.Get(typeof (SerialTest));
+
+ [Test]
+ ///
+ /// Test the key boundaries where wraparound occurs.
+ ///
+ public void testBoundaries()
+ {
+ Assert.IsTrue(Serial.Gt(1, 0));
+ Assert.IsTrue(Serial.Lt(0, 1));
+
+ Assert.IsTrue(Serial.Gt(int.MaxValue, int.MaxValue - 1));
+ Assert.IsTrue(Serial.Lt(int.MaxValue - 1, int.MaxValue));
+ }
+
+ ///
+ /// Test the first Corollary of RFC 1982
+ /// For any sequence number s and any integer n such that addition of n
+ /// to s is well defined, (s + n) >= s. Further (s + n) == s only when
+ /// n == 0, in all other defined cases, (s + n) > s.
+ ///
+ public void testCorollary1()
+ {
+ int wrapcount = 0;
+
+ int s = 0;
+
+ for (int i = 0; i < 67108664; i++)
+ {
+ for (int n = 1; n < 4096; n += 512)
+ {
+ Assert.IsTrue(Serial.Gt(s + n, s));
+ Assert.IsTrue(Serial.Lt(s, s + n));
+ }
+
+ s += 1024;
+
+ if (s == 0)
+ {
+ wrapcount += 1;
+ }
+ }
+
+ Assert.IsTrue(wrapcount > 0);
+ }
+ }
+}
diff --git a/qpid/dotnet/client-010/test/transport/util/UUIDTest.cs b/qpid/dotnet/client-010/test/transport/util/UUIDTest.cs
new file mode 100644
index 0000000000..41104f8873
--- /dev/null
+++ b/qpid/dotnet/client-010/test/transport/util/UUIDTest.cs
@@ -0,0 +1,64 @@
+/*
+*
+* 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 org.apache.qpid.transport.util;
+
+namespace test.transport.util
+{
+ [TestFixture]
+
+ public class UUIDTest
+ {
+
+
+ [Test]
+ public void createUUID()
+ {
+ UUID uuid = UUID.RandomUuid();
+ String uuidStr = uuid.ToString();
+ Assert.IsNotNull(uuid);
+ UUID uuid2 = UUID.RandomUuid();
+ Assert.AreNotSame(uuid, uuid2);
+ }
+
+ [Test]
+ public void ToString_should_override_and_not_hide_base()
+ {
+ UUID uuid = UUID.RandomUuid();
+
+ string uuidStr = uuid.ToString();
+ string uuidConcat = "Test." + uuid;
+
+ Assert.AreEqual("Test." + uuidStr, uuidConcat);
+ }
+
+ [Test]
+ public void two_uuid_with_same_value_should_have_same_hash_code()
+ {
+ UUID uuid = UUID.RandomUuid();
+ UUID uuid2 = new UUID(uuid.MostSignificantBits, uuid.LeastSignificantBits);
+
+ Assert.AreEqual(uuid, uuid2);
+ Assert.AreEqual(uuid.GetHashCode(), uuid2.GetHashCode());
+ }
+ }
+}