+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * profiles/monotouch.make: add monotouch profile.
+
2009-07-16 Raja R Harinath <harinath@hurrynot.org>
* profiles/net_2_0_bootstrap.make (BOOTSTRAP_PROFILE): Set to
--- /dev/null
+#! -*- makefile -*-
+
+my_runtime = $(RUNTIME) $(RUNTIME_FLAGS) --security=temporary-smcs-hack
+INTERNAL_SMCS = $(my_runtime) $(topdir)/class/lib/$(PROFILE)/smcs.exe
+
+BOOTSTRAP_PROFILE = net_2_1_bootstrap
+
+BOOTSTRAP_MCS = MONO_PATH="$(topdir)/class/lib/$(BOOTSTRAP_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(my_runtime) $(topdir)/class/lib/$(BOOTSTRAP_PROFILE)/smcs.exe
+MCS = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(INTERNAL_SMCS)
+
+profile-check:
+ @:
+
+PROFILE_MCS_FLAGS = -d:NET_1_1 -d:NET_2_0 -d:NET_2_1 -d:MONOTOUCH
+FRAMEWORK_VERSION = 2.1
+NO_TEST = yes
+
+# the tuner takes care of the install
+NO_INSTALL = yes
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Makefile: set monotouch_SUBDIRS to the net_2_1 assemblies set.
+
2009-07-18 Michael Barker <mike@middlesoft.co.uk>
net_2_0_SUBDIRS := $(common_dirs) $(net_2_0_dirs) $(net_2_0_only_dirs)
net_2_1_bootstrap_SUBDIRS := corlib System Mono.CompilerServices.SymbolWriter
net_2_1_raw_SUBDIRS := $(net_2_1_dirs)
+monotouch_SUBDIRS := $(net_2_1_dirs)
net_3_5_SUBDIRS := $(net_3_5_dirs)
net_4_0_bootstrap_SUBDIRS := $(bootstrap_dirs) PEAPI
net_4_0_SUBDIRS := $(common_dirs) $(net_2_0_dirs) $(net_4_0_dirs)
-Mono.Messaging.RabbitMQ/MQUtil.cs
-Mono.Messaging.RabbitMQ/BasicMessagingTest.cs
-Mono.Messaging.RabbitMQ/AdminTest.cs
Mono.Messaging.RabbitMQ/FailuresTest.cs
Mono.Messaging.RabbitMQ/RabbitMQMessagingProviderTest.cs
-Mono.Messaging.RabbitMQ/MessageEnumeratorTest.cs
-Mono.Messaging.RabbitMQ/PeekTest.cs
-Mono.Messaging.RabbitMQ/TransactionMessagingTest.cs
-Mono.Messaging.RabbitMQ/SelectorTest.cs
-Mono.Messaging.RabbitMQ/AsyncReceiveTest.cs
-Mono.Messaging.RabbitMQ/AsyncPeekTest.cs
Mono.Messaging.RabbitMQ/BinaryMessageFormatterTest.cs
Mono.Messaging.RabbitMQ/XmlMessageFormatterTest.cs
Mono.Messaging.RabbitMQ/TestUtils.cs
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-using System.Reflection;
-using System.Threading;
-using System.Text.RegularExpressions;
-
-using NUnit.Framework;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- [TestFixture]
- public class AdminTest {
-
- [Test]
- public void CreateNonTransactionalQueue ()
- {
- string qName = @".\private$\admin-queue-1";
- Assert.IsFalse (MessageQueue.Exists (qName), "Queue should not exist");
- MessageQueue q = MessageQueue.Create (qName);
- Assert.IsFalse (q.Transactional);
- Assert.IsTrue (MessageQueue.Exists (qName), "Queue should exist");
- }
-
- [Test]
- public void CreateTransactionalQueue ()
- {
- string qName = @".\private$\admin-queue-2";
- Assert.IsFalse (MessageQueue.Exists (qName), "Queue should not exist");
- MessageQueue q = MessageQueue.Create (qName, true);
- Assert.IsTrue (q.Transactional, "Queue should be transactional");
- Assert.IsTrue (MessageQueue.Exists (qName), "Queue should exist");
- }
-
- private bool Contains(MessageQueue[] qs, String qName)
- {
- foreach (MessageQueue q in qs)
- {
- if (q.QueueName == qName)
- return true;
- }
- return false;
- }
-
- [Test]
- public void GetPublicQueues ()
- {
- string qName1 = @".\admin-queue-3";
- string qName2 = @".\admin-queue-4";
-
- MessageQueue.Create (qName1);
- MessageQueue.Create (qName2);
-
- MessageQueue[] mq = MessageQueue.GetPublicQueues ();
- Assert.IsTrue (Contains (mq, "admin-queue-3"), qName1 + " not found");
- Assert.IsTrue (Contains (mq, "admin-queue-4"), qName2 + " not found");
- }
-
- [Test]
- public void GetQueue ()
- {
- MessageQueue q1 = MQUtil.GetQueue(@".\private$\admin-queue-5", true);
- Assert.IsTrue (q1.Transactional, "Queue should be transactional");
- MessageQueue q2 = MQUtil.GetQueue(@".\private$\admin-queue-5", true);
- Assert.IsTrue (q2.Transactional, "Queue should be transactional");
- }
-
- [Test]
- [ExpectedException (typeof (MessageQueueException))]
- public void PurgeQueue ()
- {
- MessageQueue q = MQUtil.GetQueue(@".\private$\purge-queue");
- Message m1 = new Message ("foobar1", new BinaryMessageFormatter ());
- Message m2 = new Message ("foobar2", new BinaryMessageFormatter ());
- Message m3 = new Message ("foobar3", new BinaryMessageFormatter ());
- Message m4 = new Message ("foobar4", new BinaryMessageFormatter ());
-
- q.Send (m1);
- q.Send (m2);
- q.Send (m3);
- q.Send (m4);
-
- q.Receive ();
- q.Purge ();
- q.Receive (new TimeSpan (0, 0, 2));
- }
-
- [Test]
- public void DeleteQueue ()
- {
- MessageQueue q = MQUtil.GetQueue(@".\private$\delete-queue");
- Message m1 = new Message ("foobar1", new BinaryMessageFormatter ());
-
- q.Send (m1);
-
- q.Receive ();
-
- MessageQueue.Delete(@".\private$\delete-queue");
- }
- }
-}
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-using System.Reflection;
-using System.Threading;
-using System.Text.RegularExpressions;
-
-using NUnit.Framework;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- [TestFixture]
- public class AsyncPeekTest {
-
- bool eventCalled = false;
-
- private void HandleMessage (object source, PeekCompletedEventArgs args) {
- eventCalled = true;
- }
-
- [Test]
- public void BeginPeek()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-1");
- Message s = new Message (new BinaryMessageFormatter ());
- string body = "foo-" + DateTime.Now.ToString ();
- s.Body = body;
- q.Send (s);
-
- q.PeekCompleted += new PeekCompletedEventHandler (HandleMessage);
- IAsyncResult result = q.BeginPeek ();
- result.AsyncWaitHandle.WaitOne ();
- Message rMsg = q.EndPeek (result);
- Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
- Assert.IsTrue (eventCalled, "Handle Message not called");
-
- Assert.IsNotNull (q.Receive (), "Message not peeked");
- }
-
- [Test]
- public void BeginPeekWithTimeout()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-2");
- Message s = new Message (new BinaryMessageFormatter ());
- string body = "foo-" + DateTime.Now.ToString ();
- s.Body = body;
- q.Send (s);
-
- IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2));
- result.AsyncWaitHandle.WaitOne ();
- Message rMsg = q.EndPeek (result);
- Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
-
- Assert.IsNotNull (q.Receive (), "Message not peeked");
- }
-
- [Test]
- public void BeginPeekWithStateAndTimeout()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-3");
- Message s = new Message (new BinaryMessageFormatter ());
- string body = "foo-" + DateTime.Now.ToString ();
- s.Body = body;
- q.Send (s);
-
- IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2), "foo");
- result.AsyncWaitHandle.WaitOne ();
- Message rMsg = q.EndPeek (result);
- Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
- Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
-
- Assert.IsNotNull (q.Receive (), "Message not peeked");
- }
-
- private bool success = false;
-
- public void TestCallback (IAsyncResult result)
- {
- success = true;
- }
-
- [Test]
- public void BeginPeekWithStateAndTimeoutAndCallback()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-4");
- Message s = new Message (new BinaryMessageFormatter ());
- string body = "foo-" + DateTime.Now.ToString ();
- s.Body = body;
- q.Send (s);
- AsyncCallback ac = new AsyncCallback (TestCallback);
- IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2), "foo", ac);
- result.AsyncWaitHandle.WaitOne ();
- Message rMsg = q.EndPeek (result);
- Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
- Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
- Assert.IsTrue (success, "Callback not run");
-
- Assert.IsNotNull (q.Receive (), "Message not peeked");
- }
-
- [Test]
- [ExpectedException (typeof (MessageQueueException))]
- public void BeginPeekWithException()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-5");
- IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2));
- result.AsyncWaitHandle.WaitOne ();
- q.EndPeek (result);
- }
- }
-}
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-using System.Reflection;
-using System.Threading;
-using System.Text.RegularExpressions;
-
-using NUnit.Framework;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- [TestFixture]
- public class AsyncReceiveTest {
-
- private Message m;
- private string failureMessage = null;
- private string state = null;
-
- private void HandleMessage (object source, ReceiveCompletedEventArgs args) {
- try {
- MessageQueue q = (MessageQueue) source;
- m = q.EndReceive (args.AsyncResult);
- state = (string) args.AsyncResult.AsyncState;
- } catch (Exception e) {
- failureMessage = e.Message;
- }
- }
-
- [Test]
- public void BeginReceive()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-receive-1");
- Message s = new Message (new BinaryMessageFormatter ());
- string body = "foo-" + DateTime.Now.ToString ();
- s.Body = body;
- q.Send (s);
-
- q.ReceiveCompleted += new ReceiveCompletedEventHandler (HandleMessage);
- IAsyncResult result = q.BeginReceive ();
- result.AsyncWaitHandle.WaitOne ();
- Message rMsg = q.EndReceive (result);
- Assert.IsNotNull (rMsg, "No message received");
- Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
- }
-
- [Test]
- public void BeginReceiveWithTimeout()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-receive-2");
- Message s = new Message (new BinaryMessageFormatter ());
- string body = "foo-" + DateTime.Now.ToString ();
- s.Body = body;
- q.Send (s);
-
- IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2));
- result.AsyncWaitHandle.WaitOne ();
- Message rMsg = q.EndReceive (result);
- Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
- }
-
- [Test]
- public void BeginReceiveWithStateAndTimeout()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-receive-3");
- Message s = new Message (new BinaryMessageFormatter ());
- string body = "foo-" + DateTime.Now.ToString ();
- s.Body = body;
- q.Send (s);
-
- IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2), "foo");
- result.AsyncWaitHandle.WaitOne ();
- Message rMsg = q.EndReceive (result);
- Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
- Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
- }
-
- private bool success = false;
-
- public void TestCallback (IAsyncResult result)
- {
- success = true;
- }
-
- [Test]
- public void BeginReceiveWithStateAndTimeoutAndCallback()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-receive-4");
- Message s = new Message (new BinaryMessageFormatter ());
- string body = "foo-" + DateTime.Now.ToString ();
- s.Body = body;
- q.Send (s);
- AsyncCallback ac = new AsyncCallback (TestCallback);
- IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2), "foo", ac);
- result.AsyncWaitHandle.WaitOne ();
- Message rMsg = q.EndReceive (result);
- Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
- Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
- Assert.IsTrue (success, "Callback not run");
- }
-
- [Test]
- [ExpectedException (typeof (MessageQueueException))]
- public void BeginReceiveWithException()
- {
- MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-5");
- IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2));
- result.AsyncWaitHandle.WaitOne ();
- q.EndReceive (result);
- }
- }
-}
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-using System.Reflection;
-using System.Threading;
-using System.Text.RegularExpressions;
-
-using NUnit.Framework;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- [TestFixture]
- public class BasicMessageTest {
-
- [Test]
- public void SendReceiveBinaryMessage ()
- {
- String qName = @"private$\testq";
- String qPath = @".\" + qName;
- MessageQueue mq = MQUtil.GetQueue (qPath);
- Assert.AreEqual(qName, mq.QueueName, "Queue name not set properly");
- String s = "Test: " + DateTime.Now;
- Message m = new Message (s, new BinaryMessageFormatter ());
- m.CorrelationId = Guid.NewGuid () + "\\0";
- mq.MessageReadPropertyFilter.SetAll ();
-
- mq.Send (m);
-
- Message m2 = mq.Receive ();
- m2.Formatter = new BinaryMessageFormatter ();
- Assert.AreEqual (s, m2.Body);
-
- //Assert.IsTrue (DateTime.MinValue == m.ArrivedTime);
- Assert.IsNotNull(m2.Id, "Id is null");
- Assert.IsTrue (Guid.Empty.ToString () != m2.Id, "Id is Empty");
- Assert.IsTrue (DateTime.MinValue != m2.ArrivedTime, "Arrived Time is not set");
- Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
- Assert.AreEqual (m.CorrelationId, m2.CorrelationId, "CorrelationId not set properly");
- Assert.IsTrue (0 != m2.SenderVersion);
- // TODO: This is not support on a workgroup installation.
- //Assert.IsNotNull (m2.SourceMachine, "SourceMachine is null");
- Assert.AreEqual (qName, m2.DestinationQueue.QueueName, "Destination Queue not set");
-
- mq.Close ();
- }
-
- [Test]
- public void SendMessageWithLabel ()
- {
- String qName = @".\private$\testq";
- String label = "mylabel";
- MessageQueue mq = MQUtil.GetQueue (qName);
- Assert.AreEqual (@"private$\testq", mq.QueueName, "Queue name not set properly");
- String s = "Test: " + DateTime.Now;
- Message m = new Message (s, new BinaryMessageFormatter ());
- m.CorrelationId = Guid.NewGuid () + "\\0" ;
-
- mq.Send (m, label);
-
- Message m2 = mq.Receive ();
- m2.Formatter = new BinaryMessageFormatter ();
- Assert.AreEqual (s, m2.Body, "Message not passed correctly");
- Assert.AreEqual (label, m2.Label, "Label not passed correctly");
- }
-
-
- [Test]
- public void CheckDefaults ()
- {
- Message m = new Message ("Test", new BinaryMessageFormatter ());
- Assert.AreEqual (true, m.AttachSenderId, "AttachSenderId has incorrect default");
- Assert.AreEqual (Guid.Empty.ToString () + "\\0", m.Id, "Id has incorrect default");
- Assert.AreEqual ("Microsoft Base Cryptographic Provider, Ver. 1.0",
- m.AuthenticationProviderName,
- "AuthenticationProviderName has incorrect default");
- Assert.AreEqual (0, m.Extension.Length, "Extension has incorrect default");
- Assert.AreEqual ("", m.Label, "Label has incorrect default");
- Assert.IsFalse (m.Recoverable, "Recoverable has incorrect default");
- Assert.IsFalse (m.IsFirstInTransaction, "IsFirstInTransaction has incorrect default");
- Assert.IsFalse (m.IsLastInTransaction, "IsLastInTransaction has incorrect default");
- Assert.AreEqual ("", m.TransactionId, "TransactionId has incorrect default");
- Assert.AreEqual (MessagePriority.Normal, m.Priority, "MessagePriority has incorrect default");
- }
-
- private static void CheckInvalidOperation (Message m, String property)
- {
- PropertyInfo pi = m.GetType ().GetProperty (property);
- try {
- Assert.IsNotNull (pi, "Property not defined: " + property);
- object o = pi.GetValue (m, null);
- Assert.Fail (property + ": " + o);
- } catch (InvalidOperationException) {
- } catch (TargetInvocationException e) {
- Assert.AreEqual (typeof (InvalidOperationException),
- e.InnerException.GetType ());
- }
- }
-
- [Test]
- public void CheckInvalidPropertyOperations ()
- {
- Message m = new Message ("Test", new BinaryMessageFormatter ());
- CheckInvalidOperation (m, "Acknowledgment");
- CheckInvalidOperation (m, "ArrivedTime");
- CheckInvalidOperation (m, "Authenticated");
- CheckInvalidOperation (m, "DestinationQueue");
- //CheckInvalidOperation (m, "Id");
- //CheckInvalidOperation (m, "IsFirstInTransaction");
- //CheckInvalidOperation (m, "IsLastInTransaction");
- // TODO: Support 2.0 features.
- //CheckInvalidOperation (m, "LookupId");
- CheckInvalidOperation (m, "MessageType");
- CheckInvalidOperation (m, "SenderId");
- CheckInvalidOperation (m, "SenderVersion");
- CheckInvalidOperation (m, "SentTime");
- CheckInvalidOperation (m, "SourceMachine");
- //CheckInvalidOperation (m, "TransactionId");
- }
-
- private static void CheckArgumentInvalid(Message m, String property, Type exceptionType)
- {
- PropertyInfo pi = m.GetType().GetProperty(property);
- try {
- Assert.IsNotNull(pi, "Property not defined: " + property);
- pi.SetValue(m, null, null);
- Assert.Fail(property);
- } catch (InvalidOperationException) {
- } catch (TargetInvocationException e) {
- Assert.AreEqual(exceptionType,
- e.InnerException.GetType(),
- property);
- }
- }
-
- [Test]
- public void CheckArgumentInvalidForProperties ()
- {
- Message m = new Message ("Stuff");
- CheckArgumentInvalid (m, "DestinationSymmetricKey", typeof (ArgumentNullException));
- CheckArgumentInvalid (m, "DigitalSignature", typeof(ArgumentNullException));
- CheckArgumentInvalid (m, "Extension", typeof(ArgumentNullException));
- }
-
- [Test]
- public void SendReceiveBinaryMessageWithAllPropertiesSet ()
- {
- String qName = @"private$\testq";
- String qPath = @".\" + qName;
- MessageQueue mq = MQUtil.GetQueue (qPath);
- mq.MessageReadPropertyFilter.SetAll ();
- Assert.AreEqual(qName, mq.QueueName, "Queue name not set properly");
-
- MessageQueue adminQ = MQUtil.GetQueue (@".\private$\myadmin");
- MessageQueue responseQ = MQUtil.GetQueue (@".\private$\myresponse");
- Guid connectorType = Guid.NewGuid ();
- String s = "Test: " + DateTime.Now;
-
- Message m = new Message (s, new BinaryMessageFormatter ());
- m.CorrelationId = Guid.NewGuid () + "\\0";
- m.AcknowledgeType = AcknowledgeTypes.PositiveArrival;
- m.AdministrationQueue = adminQ;
- m.AppSpecific = 5;
- //m.AuthenticationProviderName = "Test Provider Name";
- //m.AuthenticationProviderType = CryptographicProviderType.None;
- //m.ConnectorType = connectorType;
- //m.DestinationSymmetricKey = new byte[] { 0x0A, 0x0B, 0x0C };
- //m.DigitalSignature = new byte[] { 0x0C, 0x0D, 0x0E };
- //m.EncryptionAlgorithm = EncryptionAlgorithm.Rc4;
- m.Extension = new byte[] { 0x01, 0x02, 0x03 };
- //m.HashAlgorithm = HashAlgorithm.Sha;
- m.Label = "MyLabel";
- m.Priority = MessagePriority.AboveNormal;
- m.Recoverable = true;
- m.ResponseQueue = responseQ;
- m.SenderCertificate = new byte[] { 0x04, 0x05, 0x06 };
- m.TimeToBeReceived = new TimeSpan(0, 0, 10);
- m.TimeToReachQueue = new TimeSpan(0, 0, 5);
- //m.UseAuthentication = true;
- m.UseDeadLetterQueue = true;
- //m.UseEncryption = true;
-
- mq.Send (m);
-
- Message m2 = mq.Receive ();
-
- m2.Formatter = new BinaryMessageFormatter ();
- Assert.AreEqual (s, m2.Body);
-
- Assert.AreEqual (AcknowledgeTypes.PositiveArrival, m2.AcknowledgeType,
- "AcknowledgeType not passed correctly");
- Assert.AreEqual (adminQ.QueueName, m2.AdministrationQueue.QueueName,
- "AdministrationQueue not passed correctly");
- Assert.AreEqual (5, m2.AppSpecific, "AppSpecific not passed correctly");
- //Assert.AreEqual (m.AuthenticationProviderName, m2.AuthenticationProviderName,
- // "AuthenticationProviderName not passed correctly");
- //Assert.AreEqual (m.AuthenticationProviderType, m2.AuthenticationProviderType,
- // "AuthenticationProviderType not passed correctly");
- //Assert.AreEqual (connectorType, m2.ConnectorType,
- // "ConnectorType not passed correctly");
- Assert.AreEqual (m.CorrelationId, m2.CorrelationId,
- "CorrelationId not passed correctly");
- //AreEqual (m.DestinationSymmetricKey, m2.DestinationSymmetricKey,
- // "DestinationSymmetricKey not passed correctly");
- //AreEqual (m.DigitalSignature, m2.DigitalSignature,
- // "DigitalSignature not passed properly");
- //Assert.AreEqual (EncryptionAlgorithm.Rc4, m2.EncryptionAlgorithm,
- // "EncryptionAlgorithm not passed properly");
- AreEqual (m.Extension, m2.Extension, "Extension not passed properly");
- //Assert.AreEqual (m.HashAlgorithm, m2.HashAlgorithm,
- // "HashAlgorithm not passed properly");
- Assert.AreEqual (m.Label, m2.Label, "Label not passed correctly");
- Assert.AreEqual (MessagePriority.AboveNormal, m2.Priority,
- "Priority not passed properly");
- Assert.AreEqual (true, m2.Recoverable, "Recoverable not passed properly");
- Assert.AreEqual (responseQ.QueueName, m2.ResponseQueue.QueueName,
- "ResponseQueue not passed properly");
- AreEqual (m.SenderCertificate, m2.SenderCertificate,
- "SenderCertificate not passed properly");
- Assert.AreEqual (m.TimeToBeReceived, m2.TimeToBeReceived,
- "TimeToBeReceived not passed properly");
- Assert.AreEqual (m.TimeToReachQueue, m2.TimeToReachQueue,
- "TimeToReachQueue not passed properly");
- //Assert.IsTrue (m2.UseAuthentication,
- // "UseAuthentication not passed properly");
- Assert.IsTrue (m2.UseDeadLetterQueue,
- "UseDeadLetterQueue not passed properly");
- //Assert.IsTrue (m2.UseEncryption, "UseEncryption not pass properly");
- //Assert.AreEqual ();
-
- Assert.IsNotNull (m2.Id, "Id is null");
- Assert.IsTrue (Guid.Empty.ToString () != m2.Id, "Id is Empty");
- Assert.IsTrue (DateTime.MinValue != m2.ArrivedTime, "Arrived Time is not set");
- Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
- Assert.IsTrue (0 != m2.SenderVersion);
-
- //Assert.IsNotNull (m2.SourceMachine, "SourceMachine is null");
-
- }
-
- private static void AreEqual(byte[] expected, byte[] actual, string message)
- {
- Assert.AreEqual (expected.Length, actual.Length, message);
- for (int i = 0; i < expected.Length; i++)
- Assert.AreEqual (expected[i], actual[i], message);
- }
-
- //[Test]
- // No supported by Rabbit
- public void SendPriorityMessages ()
- {
- MessageQueue mq = MQUtil.GetQueue ("testpriority");
- Message sent1 = new Message ("Highest", new BinaryMessageFormatter ());
- sent1.Priority = MessagePriority.Highest;
- Message sent2 = new Message ("Lowest", new BinaryMessageFormatter ());
- sent2.Priority = MessagePriority.Lowest;
-
- mq.Send (sent1);
- mq.Send (sent2);
-
- Message received1 = mq.Receive ();
- Message received2 = mq.Receive ();
-
- Assert.AreEqual (MessagePriority.Highest, received2.Priority,
- "Priority delivery incorrect");
- Assert.AreEqual (MessagePriority.Lowest, received1.Priority,
- "Priority delivery incorrect");
- }
-
- [Test]
- public void SendReceiveXmlMessage ()
- {
- MessageQueue mq = MQUtil.GetQueue (@".\private$\testq");
- String s = "Test: " + DateTime.Now;
- Message m = new Message (s, new XmlMessageFormatter (new Type[] { typeof (string) }));
- mq.MessageReadPropertyFilter.SetAll();
-
- mq.Send (m);
- Message m2 = mq.Receive ();
- m2.Formatter = new XmlMessageFormatter (new Type[] { typeof (string) });
- Assert.AreEqual (s, m2.Body);
-
- Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
- Assert.IsNotNull (m2.ArrivedTime, "Acknowledgment");
- Assert.IsNotNull (m2.Id, "Id");
- }
-
- [Test]
- public void SendBinaryText ()
- {
- string path = @".\private$\MyQ";
- string body = "This is a test";
-
- MessageQueue q = MQUtil.GetQueue (path);
-
- q.Formatter = new BinaryMessageFormatter ();
-
- q.Send (body);
-
- Message m2 = q.Receive ();
-
- Assert.IsNotNull (m2.Formatter, "Formatter is null");
- Assert.AreEqual (typeof (BinaryMessageFormatter), m2.Formatter.GetType ());
- Assert.AreEqual (body, m2.Body);
- }
-
- [Test]
- public void SendDefaultText ()
- {
- string path = @".\private$\MyQ";
- string body = "This is a test";
-
- MessageQueue q = MQUtil.GetQueue (path, new XmlMessageFormatter ());
-
- q.Send (body);
-
- Message m2 = q.Receive ();
- XmlMessageFormatter xmlf = (XmlMessageFormatter) q.Formatter;
- //Assert.AreEqual (typeof (string), xmlf.TargetTypes[0]);
- Assert.AreEqual (typeof (XmlMessageFormatter), m2.Formatter.GetType ());
- Assert.AreEqual (body, m2.Body);
- Assert.AreEqual (0, m2.BodyType);
- }
-
- [Test]
- public void SendBinaryObject ()
- {
- string path = @".\private$\MyQ";
- Thingy body = new Thingy ();
- body.MyProperty1 = 42;
- body.MyProperty2 = "Something";
- body.MyProperty3 = "Something else";
-
- MessageQueue q = MQUtil.GetQueue (path);
-
- q.Formatter = new BinaryMessageFormatter ();
-
- q.Send (body);
-
- Message m2 = q.Receive ();
- Thingy body2 = (Thingy) m2.Body;
-
- Assert.AreEqual (typeof (BinaryMessageFormatter), m2.Formatter.GetType ());
- Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
- Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
- Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
- Assert.AreEqual (768, m2.BodyType);
- }
-
- [Test]
- public void SendDefaultObject ()
- {
- string path = @".\private$\MyQ";
- Thingy body = new Thingy();
- body.MyProperty1 = 42;
- body.MyProperty2 = "Something";
- body.MyProperty3 = "Something else";
-
- MessageQueue q = MQUtil.GetQueue (path, new XmlMessageFormatter ());
-
- q.Send (body);
-
- MessageQueue q2 = MQUtil.GetQueue (path);
- q2.Formatter = new XmlMessageFormatter (new Type[] { typeof(Thingy) });
-
- Message m2 = q2.Receive ();
- Thingy body2 = (Thingy) m2.Body;
-
- Assert.AreEqual (typeof (XmlMessageFormatter), m2.Formatter.GetType ());
- Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
- Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
- Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
- }
-
- [Test]
- public void SendBinaryMessage ()
- {
- string path = @".\private$\MyQ";
- Thingy body = new Thingy ();
- body.MyProperty1 = 42;
- body.MyProperty2 = "Something";
- body.MyProperty3 = "Something else";
- Message m1 = new Message (body);
- m1.Formatter = new BinaryMessageFormatter ();
-
- MessageQueue q = MQUtil.GetQueue (path);
-
- q.Send (m1);
-
- Message m2 = q.Receive ();
- m2.Formatter = new BinaryMessageFormatter ();
- Assert.IsNotNull (m2.Formatter);
- Assert.AreEqual (typeof (BinaryMessageFormatter), m2.Formatter.GetType ());
- Thingy body2 = (Thingy) m2.Formatter.Read (m2);
-
- Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
- Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
- Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
- }
-
- [Test]
- public void SendDefaultMessage ()
- {
- string path = @".\private$\MyQ";
- Thingy body = new Thingy ();
- body.MyProperty1 = 42;
- body.MyProperty2 = "Something";
- body.MyProperty3 = "Something else";
- Message m1 = new Message (body);
- Assert.IsNull (m1.Formatter);
-
- MessageQueue q = MQUtil.GetQueue (path, new XmlMessageFormatter ());
-
- q.Send (m1);
-
- Message m2 = q.Receive ();
- m2.Formatter = new XmlMessageFormatter (new Type[] { typeof (Thingy) });
- Assert.IsNotNull (m2.Formatter);
- Assert.AreEqual (typeof (XmlMessageFormatter), m2.Formatter.GetType ());
- Thingy body2 = (Thingy) m2.Formatter.Read (m2);
-
- Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
- Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
- Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
- }
- }
-
- [Serializable]
- public class Thingy
- {
- private int myVar1;
-
- public int MyProperty1
- {
- get { return myVar1; }
- set { myVar1 = value; }
- }
-
- private string myVar2;
-
- public string MyProperty2
- {
- get { return myVar2; }
- set { myVar2 = value; }
- }
-
- private string myVar3;
-
- public string MyProperty3
- {
- get { return myVar3; }
- set { myVar3 = value; }
- }
- }
-}
+2009-07-19 Michael Barker <mike@middlesoft.co.uk>
+
+ * AdminTest.cs: Moved to System.Messaging
+ * AsyncPeekTest.cs: Moved to System.Messaging
+ * AsyncReceiveTest.cs: Moved to System.Messaging
+ * BasicMessagingTest.cs: Moved to System.Messaging
+ * MessageEnumeratorTest.cs: Moved to System.Messaging
+ * MQUtil.cs: Moved to System.Messaging
+ * PeekTest.cs: Moved to System.Messaging
+ * SelectorTest.cs: Moved to System.Messaging
+
+
2009-07-11 Michael Barker <mike@middlesoft.co.uk>
* MessageBaseTest.cs: Moved from Mono.Messaging.Test
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- public class MQUtil
- {
- public static MessageQueue GetQueue (string path)
- {
- return GetQueue (path, false);
- }
-
- public static MessageQueue GetQueue (string path, bool isTransactional)
- {
- return GetQueue (path, isTransactional,
- new BinaryMessageFormatter ());
- }
-
- public static MessageQueue GetQueue (string path, IMessageFormatter formatter)
- {
- return GetQueue (path, false, formatter);
- }
-
- public static MessageQueue GetQueue (string path, bool isTransactional,
- IMessageFormatter formatter)
- {
- MessageQueue q;
- if (MessageQueue.Exists (path)) {
- q = new MessageQueue (path);
- } else {
- q = MessageQueue.Create (path, isTransactional);
- }
- q.Formatter = formatter;
- return q;
- }
- }
-}
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-
-//using Mono.Messaging;
-//using Mono.Messaging.RabbitMQ;
-
-using NUnit.Framework;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- [TestFixture]
- public class MessageEnumeratorTest {
-
- private readonly String qName = @".\private$\testq2";
-
- private void SendMessage (string s) {
- MessageQueue mq = MQUtil.GetQueue (qName);
- Message m = new Message (s, new BinaryMessageFormatter ());
- m.CorrelationId = Guid.NewGuid () + "\\0";
- mq.Send (m);
- }
-
- [Test]
- public void RemoveMessage ()
- {
- SendMessage ("message 1");
- SendMessage ("message 2");
- SendMessage ("message 3");
- SendMessage ("message 4");
-
- MessageQueue mq0 = MQUtil.GetQueue (qName);
- MessageEnumerator me0 = mq0.GetMessageEnumerator ();
-
- me0.MoveNext ();
- me0.MoveNext ();
- me0.MoveNext ();
-
- Message m0 = me0.RemoveCurrent ();
-
- me0.MoveNext ();
-
- me0.Dispose ();
- mq0.Dispose ();
-
- MessageQueue mq1 = MQUtil.GetQueue (qName);
- MessageEnumerator me1 = mq1.GetMessageEnumerator ();
-
- me1.MoveNext();
- me1.MoveNext();
- me1.MoveNext();
-
- Message m1 = me1.Current;
- m1.Formatter = new BinaryMessageFormatter ();
- Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
-
- mq1.Purge ();
- MessageQueue.Delete (qName);
- }
-
- [Test]
- public void RemoveMessageWithTimeout ()
- {
- SendMessage ("message 1");
- SendMessage ("message 2");
- SendMessage ("message 3");
- SendMessage ("message 4");
-
- MessageQueue mq0 = MQUtil.GetQueue (qName);
- MessageEnumerator me0 = mq0.GetMessageEnumerator ();
-
- TimeSpan ts = new TimeSpan (0, 0, 2);
-
- me0.MoveNext (ts);
- me0.MoveNext (ts);
- me0.MoveNext (ts);
-
- Message m0 = me0.RemoveCurrent (ts);
-
- me0.MoveNext (ts);
-
- me0.Dispose ();
- mq0.Dispose ();
-
- MessageQueue mq1 = MQUtil.GetQueue (qName);
- MessageEnumerator me1 = mq1.GetMessageEnumerator ();
-
- me1.MoveNext (ts);
- me1.MoveNext (ts);
- me1.MoveNext (ts);
-
- Message m1 = me1.Current;
- m1.Formatter = new BinaryMessageFormatter ();
- Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
-
- mq1.Purge ();
- MessageQueue.Delete (qName);
- }
-
- //[Test]
- // Not supported with AMQP
- public void RemoveMessageWithTx ()
- {
- MessageQueue q = MQUtil.GetQueue ("testq3");
-
- q.Formatter = new BinaryMessageFormatter ();
- q.Send ("foo1");
- q.Send ("foo2");
-
- MessageEnumerator me1 = q.GetMessageEnumerator ();
- MessageQueueTransaction tx = new MessageQueueTransaction ();
- me1.MoveNext ();
- Message m1 = me1.Current;
- me1.RemoveCurrent (tx);
- tx.Commit ();
- me1.Close ();
-
- MessageEnumerator me2 = q.GetMessageEnumerator ();
- Assert.IsTrue (me1.MoveNext ());
- me2.RemoveCurrent ();
- Assert.IsFalse (me2.MoveNext ());
- }
- }
-}
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-
-using NUnit.Framework;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- [TestFixture]
- public class PeekTest {
-
- [Test]
- public void PeekMessage ()
- {
- String body = "foo-" + DateTime.Now.ToString ();
- Message s1 = new Message(body, new BinaryMessageFormatter());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\peek-queue-1");
- mq.Send (s1);
-
- Message r1 = mq.Peek ();
- Assert.AreEqual (body, r1.Body);
-
- Message r2 = mq.Receive ();
- Assert.AreEqual (body, r2.Body);
- }
-
- [Test]
- public void PeekMessageWithTimeout ()
- {
- String body = "foo-" + DateTime.Now.ToString();
- Message s1 = new Message(body, new BinaryMessageFormatter());
- MessageQueue mq = MQUtil.GetQueue(@".\private$\peek-queue-2");
- mq.Send (s1);
-
- Message r1 = mq.Peek (new TimeSpan (0, 0, 2));
- Assert.AreEqual (body, r1.Body);
-
- Message r2 = mq.Receive ();
- Assert.AreEqual (body, r2.Body);
- }
-
- [Test]
- [ExpectedException (typeof (MessageQueueException))]
- public void PeekNoMessageWithTimeout ()
- {
- MessageQueue mq = MQUtil.GetQueue(@".\private$\peek-queue-3");
- Message r1 = mq.Peek (new TimeSpan (0, 0, 2));
- }
-
- [Test]
- public void PeekById ()
- {
- String body = "Foo-" + DateTime.Now.ToString ();
- Message s1 = new Message (body, new BinaryMessageFormatter());
- MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-4");
- q.Send (s1);
-
- String id = s1.Id;
- try {
- Message r1 = q.PeekById (id);
- Assert.AreEqual (body, r1.Body, "Unable to PeekById correctly");
- } finally {
- q.Purge ();
- }
- }
-
- [Test]
- public void PeekByIdWithTimeout ()
- {
- String body = "Foo-" + DateTime.Now.ToString ();
- Message s1 = new Message (body, new BinaryMessageFormatter());
- MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-5");
- q.Send (s1);
-
- String id = s1.Id;
- try {
- Message r1 = q.PeekById (id, new TimeSpan (0, 0, 2));
- Assert.AreEqual (body, r1.Body, "Unable to PeekById correctly");
- } finally {
- q.Purge ();
- }
- }
-
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void PeekByIdNotFound ()
- {
- String body = "Foo-" + DateTime.Now.ToString ();
- Message s1 = new Message (body, new BinaryMessageFormatter());
- MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-6");
- q.Send (s1);
-
- String id = "fail!";
-
- try {
- Message r1 = q.PeekById (id);
- } finally {
- q.Purge ();
- }
- }
-
- [Test]
- public void PeekByCorrelationId ()
- {
- String correlationId = Guid.NewGuid () + "\\0";
- String body = "Foo-" + DateTime.Now.ToString ();
- Message s1 = new Message (body, new BinaryMessageFormatter());
- s1.CorrelationId = correlationId;
- MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-7");
- q.Formatter = new BinaryMessageFormatter ();
- q.Send (s1);
-
- try {
- Message r1 = q.PeekByCorrelationId (correlationId);
- Assert.AreEqual (body, r1.Body, "Unable to PeekByCorrelationId correctly");
- } finally {
- q.Purge ();
- }
- }
-
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void PeekByCorrelationIdNotFound ()
- {
- String body = "Foo-" + DateTime.Now.ToString ();
- Message s1 = new Message (body);
- String correlationId = Guid.NewGuid() + "\\0";
- MessageQueue q = MQUtil.GetQueue(@".\private$\peek-queue-8");
- q.Formatter = new BinaryMessageFormatter ();
- q.Send (s1);
-
- try {
- Message r1 = q.PeekByCorrelationId ("fail!");
- } finally {
- q.Purge ();
- }
- }
-
- [Test]
- public void PeekByCorrelationIdWithTimeout ()
- {
- String correlationId = Guid.NewGuid () + "\\0";
- String body = "Foo-" + DateTime.Now.ToString ();
- Message s1 = new Message (body, new BinaryMessageFormatter());
- s1.CorrelationId = correlationId;
- MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-9");
- q.Formatter = new BinaryMessageFormatter ();
- q.Send (s1);
-
- try {
- Message r1 = q.PeekByCorrelationId (correlationId, new TimeSpan (0, 0, 2));
- Assert.AreEqual (body, r1.Body, "Unable to PeekByCorrelationId correctly");
- } finally {
- q.Purge ();
- }
- }
- }
-}
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-
-using NUnit.Framework;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- [TestFixture]
- public class SelectorTest
- {
-
- [Test]
- public void SelectById ()
- {
- String body = "Foo-" + DateTime.Now.ToString ();
- Message s1 = new Message (body, new BinaryMessageFormatter());
- MessageQueue q = MQUtil.GetQueue (@".\private$\selector-queue-1");
- q.Send (s1);
-
- String id = s1.Id;
-
- Message r1 = q.ReceiveById (id);
-
- Assert.AreEqual (body, r1.Body, "Unable to ReceiveById correctly");
- }
-
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void SelectByIdNotFound ()
- {
- String body = "Foo-" + DateTime.Now.ToString();
- Message s1 = new Message(body, new BinaryMessageFormatter());
- MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-2");
- q.Send (s1);
-
- String id = "fail!";
-
- try {
- Message r1 = q.ReceiveById (id);
- } finally {
- q.Purge ();
- }
- }
-
- [Test]
- public void SelectByCorrelationId ()
- {
- string correlationId = Guid.NewGuid () + "\\0";
- String body = "Foo-" + DateTime.Now.ToString();
- Message s1 = new Message(body, new BinaryMessageFormatter());
- s1.CorrelationId = correlationId;
- MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-3");
- q.Send (s1);
-
- Message r1 = q.ReceiveByCorrelationId (correlationId);
-
- Assert.AreEqual (body, r1.Body, "Unable to ReceiveByCorrelationId correctly");
- }
-
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void SelectByCorrelationIdNotFound ()
- {
- string correlationId = Guid.NewGuid() + "\\0";
- String body = "Foo-" + DateTime.Now.ToString();
- Message s1 = new Message(body, new BinaryMessageFormatter());
- s1.CorrelationId = correlationId;
- MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-4");
- q.Send (s1);
-
- try {
- Message r1 = q.ReceiveByCorrelationId ("fail!");
- } finally {
- q.Purge ();
- }
- }
-
- [Test]
- public void SelectByIdWithTimeout ()
- {
- String body = "Foo-" + DateTime.Now.ToString();
- Message s1 = new Message(body, new BinaryMessageFormatter());
- MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-5");
- q.Send (s1);
-
- String id = s1.Id;
-
- Message r1 = q.ReceiveById (id, new TimeSpan (0, 0, 2));
-
- Assert.AreEqual (body, r1.Body, "Unable to ReceiveById correctly");
- }
-
- [Test]
- public void SelectByCorrelationIdWithTimeout ()
- {
- string correlationId = Guid.NewGuid() + "\\0";
- String body = "Foo-" + DateTime.Now.ToString();
- Message s1 = new Message(body, new BinaryMessageFormatter());
- s1.CorrelationId = correlationId;
- MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-3");
- q.Send (s1);
-
- Message r1 = q.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2));
-
- Assert.AreEqual (body, r1.Body, "Unable to ReceiveByCorrelationId correctly");
- }
- }
-}
+++ /dev/null
-//
-// Test.Mono.Messaging.RabbitMQ
-//
-// Authors:
-// Michael Barker (mike@middlesoft.co.uk)
-//
-// (C) 2008 Michael Barker
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Messaging;
-using System.Reflection;
-using System.Threading;
-using System.Text.RegularExpressions;
-
-using NUnit.Framework;
-
-namespace MonoTests.Mono.Messaging.RabbitMQ
-{
- [TestFixture]
- public class TransactionMessageTest {
-
- [Test]
- public void Send2WithTransaction ()
- {
- Message sent1 = new Message ("Message 1", new BinaryMessageFormatter ());
- Message sent2 = new Message ("Message 2", new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-1", true);
- mq.MessageReadPropertyFilter.SetAll ();
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- mq.Send (sent1, tx);
- mq.Send (sent2, tx);
-
- tx.Commit ();
-
- Message received1 = mq.Receive ();
- Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
- Message received2 = mq.Receive ();
- Assert.IsNotNull (received2.TransactionId, "TransactionId not set");
-
- Assert.AreEqual (received1.TransactionId, received2.TransactionId, "Messages have differing TransactionIds");
- Assert.IsTrue (received1.TransactionId.Length > 1);
- Assert.AreEqual (sent1.Body, received1.Body, "Message 1 not delivered correctly");
- Assert.AreEqual (sent2.Body, received2.Body, "Message 2 not delivered correctly");
- }
- }
-
- [Test]
- public void Send2WithLabelWithTransaction ()
- {
- String label1 = "label1";
- String label2 = "label2";
- Message sent1 = new Message ("Message 1", new BinaryMessageFormatter ());
- Message sent2 = new Message ("Message 2", new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-2", true);
- mq.MessageReadPropertyFilter.SetAll ();
- Assert.IsTrue(mq.Transactional, "Message Queue should be transactional");
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- mq.Send (sent1, label1, tx);
- mq.Send (sent2, label2, tx);
-
- tx.Commit ();
-
- Message received1 = mq.Receive ();
- Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
- Message received2 = mq.Receive ();
- Assert.IsNotNull (received2.TransactionId, "TransactionId not set");
-
- Assert.AreEqual (received1.TransactionId, received2.TransactionId, "Messages have differing TransactionIds");
- Assert.IsTrue (received1.TransactionId.Length > 1);
- Assert.AreEqual (sent1.Body, received1.Body, "Message 1 not delivered correctly");
- Assert.AreEqual (sent2.Body, received2.Body, "Message 2 not delivered correctly");
- Assert.AreEqual (label1, received1.Label, "Label 1 not passed correctly");
- Assert.AreEqual (label2, received2.Label, "Label 2 not passed correctly");
- }
- }
-
- [Test]
- [ExpectedException (typeof (MessageQueueException))]
- public void Send2WithTransactionAbort ()
- {
- Message sent1 = new Message ("Message 1", new BinaryMessageFormatter ());
- Message sent2 = new Message ("Message 2", new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-1", true);
- mq.MessageReadPropertyFilter.SetAll ();
- Assert.IsTrue(mq.Transactional, "Message Queue should be transactional");
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- mq.Send (sent1, tx);
- mq.Send (sent2, tx);
-
- tx.Abort ();
- mq.Receive (new TimeSpan (0, 0, 2));
- }
- }
-
- [Test]
- public void ReceiveWithTransaction ()
- {
- String body = "Message 4";
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-4", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.Receive (tx);
-
- tx.Commit ();
-
- Assert.AreEqual (body, received1.Body);
- }
- }
-
- [Test]
- public void ReceiveWithTransactionAbort ()
- {
- String body = "foo-" + DateTime.Now.ToString ();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-5", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.Receive (tx);
-
- tx.Abort ();
- }
-
- Message received2 = mq.Receive ();
- Assert.AreEqual (body, received2.Body);
- }
-
- [Test]
- public void ReceiveWithTransactionType ()
- {
- String body = "foo-" + DateTime.Now.ToString ();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-6", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
-
- Message received1 = mq.Receive (MessageQueueTransactionType.Single);
-
- Assert.AreEqual (body, received1.Body);
- }
-
- [Test]
- public void SendWithTransactionType ()
- {
- Message sent1 = new Message ("Message 1");
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-7", true);
- mq.MessageReadPropertyFilter.SetAll();
- mq.Send (sent1, MessageQueueTransactionType.Single);
-
- Message received1 = mq.Receive ();
- Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
- }
-
- [Test]
- public void SendWithTransactionTypeAndLabel ()
- {
- Message sent1 = new Message ("Message 1");
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-8", true);
- mq.MessageReadPropertyFilter.SetAll();
- String label = "mylabel";
-
- mq.Send (sent1, label, MessageQueueTransactionType.Single);
-
- Message received1 = mq.Receive ();
- Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
- Assert.AreEqual (label, received1.Label, "Label not set");
- }
-
- [Test]
- public void ReceiveByIdWithTransaction ()
- {
- String body = "Message 4";
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-9", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.ReceiveById (id, tx);
-
- tx.Commit ();
-
- Assert.AreEqual (body, received1.Body);
- }
- }
-
- [Test]
- public void ReceiveByIdWithTransactionAbort ()
- {
- String body = "foo-" + DateTime.Now.ToString ();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-10", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.ReceiveById (id, tx);
-
- tx.Abort ();
- }
-
- Message received2 = mq.Receive ();
- Assert.AreEqual (body, received2.Body);
- }
-
- [Test]
- public void ReceiveByIdWithTransactionType ()
- {
- String body = "Message 4";
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-11", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- Message received1 = mq.ReceiveById (id, MessageQueueTransactionType.Single);
- Assert.AreEqual (body, received1.Body);
- }
-
- [Test]
- public void ReceiveByCorrelationIdWithTransaction ()
- {
- string correlationId = Guid.NewGuid() + "\\0";
- String body = "Message 4";
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- sent1.CorrelationId = correlationId;
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-12", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.ReceiveByCorrelationId(correlationId, tx);
-
- tx.Commit ();
-
- Assert.AreEqual (body, received1.Body);
- }
- }
-
- [Test]
- public void ReceiveByCorrelationIdWithTransactionAbort ()
- {
- string correlationId = Guid.NewGuid() + "\\0";
- String body = "foo-" + DateTime.Now.ToString();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- sent1.CorrelationId = correlationId;
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-13", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.ReceiveByCorrelationId (correlationId, tx);
-
- tx.Abort ();
- }
-
- Message received2 = mq.Receive ();
- Assert.AreEqual (body, received2.Body);
- }
-
- [Test]
- public void ReceiveByCorrelationIdWithTransactionType ()
- {
- string correlationId = Guid.NewGuid() + "\\0";
- String body = "Message 10";
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- sent1.CorrelationId = correlationId;
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-14", true);
- mq.Formatter = new BinaryMessageFormatter ();
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- Message received1 = mq.ReceiveByCorrelationId (correlationId, MessageQueueTransactionType.Single);
- Assert.AreEqual (body, received1.Body);
- }
-
- [Test]
- public void ReceiveWithTransactionAndTimeout ()
- {
- String body = "Message 11";
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-15", true);
- mq.Formatter = new BinaryMessageFormatter ();
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.Receive (new TimeSpan (0, 0, 2), tx);
-
- tx.Commit ();
-
- Assert.AreEqual (body, received1.Body);
- }
- }
-
- [Test]
- public void ReceiveWithTransactionAndTimeoutAndAbort ()
- {
- String body = "foo-" + DateTime.Now.ToString ();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-16", true);
- mq.Formatter = new BinaryMessageFormatter ();
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.Receive (new TimeSpan (0, 0, 2), tx);
-
- tx.Abort ();
- }
-
- Message received2 = mq.Receive ();
- Assert.AreEqual (body, received2.Body);
- }
-
- [Test]
- public void ReceiveWithTransactionTypeAndTimeout ()
- {
- String body = "foo-" + DateTime.Now.ToString ();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-17", true);
- mq.Formatter = new BinaryMessageFormatter ();
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
-
- Message received1 = mq.Receive (new TimeSpan (0, 0, 5), MessageQueueTransactionType.Single);
-
- Assert.AreEqual (body, received1.Body);
- }
-
- [Test]
- [ExpectedException (typeof (MessageQueueException))]
- public void ReceiveWithTransactionTypeAndTimeoutFailure ()
- {
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-18", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- Message received1 = mq.Receive (new TimeSpan (0, 0, 2), MessageQueueTransactionType.Single);
- }
-
- [Test]
- public void ReceiveByIdWithTransactionAndTimeout ()
- {
- String body = "foo-" + DateTime.Now.ToString ();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-19", true);
- mq.Formatter = new BinaryMessageFormatter ();
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.ReceiveById (id, new TimeSpan (0, 0, 2), tx);
-
- tx.Commit ();
-
- Assert.AreEqual (body, received1.Body);
- }
- }
-
- [Test]
- public void ReceiveByIdWithTransactionTypeAndTimeout ()
- {
- String body = "foo-" + DateTime.Now.ToString ();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-20", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- Message received1 = mq.ReceiveById (id, new TimeSpan (0, 0, 2), MessageQueueTransactionType.Single);
- Assert.AreEqual (body, received1.Body);
- }
-
- [Test]
- public void ReceiveByCorrelationIdWithTransactionAndTimeout ()
- {
- string correlationId = Guid.NewGuid () + "\\0";
- String body = "foo-" + DateTime.Now.ToString ();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- sent1.CorrelationId = correlationId;
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-21", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
- tx.Begin ();
-
- Message received1 = mq.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2), tx);
- tx.Commit ();
- Assert.AreEqual (body, received1.Body);
- }
- }
-
- [Test]
- public void ReceiveByCorrelationIdWithTransactionTypeAndTimeout ()
- {
- string correlationId = Guid.NewGuid() + "\\0";
- String body = "foo-" + DateTime.Now.ToString();
- Message sent1 = new Message (body, new BinaryMessageFormatter ());
- sent1.CorrelationId = correlationId;
- MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-22", true);
- Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
- mq.Send (sent1, MessageQueueTransactionType.Single);
- string id = sent1.Id;
-
- Message received1 = mq.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2), MessageQueueTransactionType.Single);
- Assert.AreEqual (body, received1.Body);
- }
- }
-}
LIBRARY = Mono.Messaging.dll
-ifdef NET_1_0
-LIB_MCS_FLAGS = /r:System.dll
-else NET_1_1
+ifeq (1, $(FRAMEWORK_VERSION_MAJOR))
LIB_MCS_FLAGS = /r:System.dll
else
LIB_MCS_FLAGS = /r:System.dll /r:System.Configuration
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Makefile: filter the valid profile on the framework version,
+ to make it easier to have custom variants.
+
2009-07-02 Marek Safar <marek.safar@gmail.com>
* net_4_0_System.Core.dll.sources: New file.
TEST_MCS_FLAGS = $(LIB_MCS_FLAGS)
# This is a .NET 2.0+ only assembly
-VALID_PROFILE := $(filter net_2_0 net_2_1_raw net_4_0, $(PROFILE))
+VALID_PROFILE := $(filter 2.0 2.1 4.0, $(FRAMEWORK_VERSION))
ifndef VALID_PROFILE
LIBRARY_NAME = dummy-System.Core.dll
NO_INSTALL = yes
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Lookup.cs: avoid a double dictionary lookup on the indexer.
+
+2009-07-19 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+ * Lookup.cs: when there are no matching elements, return an empty
+ enumerable. Fixes bug #523386.
+
2009-05-18 Jb Evain <jbevain@novell.com>
* Enumerable.cs (Max, Min): fix generic versions.
}
public IEnumerable<TElement> this [TKey key] {
- get { return groups [key]; }
+ get {
+ IGrouping<TKey, TElement> group;
+ if (groups.TryGetValue (key, out group))
+ return group;
+
+ return new TElement [0];
+ }
}
internal Lookup (Dictionary<TKey, List<TElement>> lookup)
Assert.AreEqual (0x00ff00, lookup ["GrEeN"].First ());
Assert.AreEqual (0x0000ff, lookup ["Blue"].First ());
}
+
+ [Test]
+ public void EmptyResult ()
+ {
+ var lookup = GetColors ().ToLookup (
+ c => c.Name,
+ c => c.Value,
+ StringComparer.OrdinalIgnoreCase);
+
+ var l = lookup ["notexist"];
+ Assert.IsNotNull (l);
+ int [] values = (int []) l;
+ Assert.AreEqual (values.Length, 0);
+ }
}
}
+System.Messaging/AdminTest.cs
+System.Messaging/AsyncPeekTest.cs
+System.Messaging/AsyncReceiveTest.cs
+System.Messaging/BasicMessagingTest.cs
+System.Messaging/MessageEnumeratorTest.cs
System.Messaging/MessageQueuePermissionAttributeTest.cs
+System.Messaging/MQUtil.cs
+System.Messaging/PeekTest.cs
+System.Messaging/SelectorTest.cs
+System.Messaging/TransactionMessagingTest.cs
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+using System.Reflection;
+using System.Threading;
+using System.Text.RegularExpressions;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ [TestFixture]
+ public class AdminTest {
+
+ [Test]
+ public void CreateNonTransactionalQueue ()
+ {
+ string qName = @".\private$\admin-queue-1";
+ Assert.IsFalse (MessageQueue.Exists (qName), "Queue should not exist");
+ MessageQueue q = MessageQueue.Create (qName);
+ Assert.IsFalse (q.Transactional);
+ Assert.IsTrue (MessageQueue.Exists (qName), "Queue should exist");
+ }
+
+ [Test]
+ public void CreateTransactionalQueue ()
+ {
+ string qName = @".\private$\admin-queue-2";
+ Assert.IsFalse (MessageQueue.Exists (qName), "Queue should not exist");
+ MessageQueue q = MessageQueue.Create (qName, true);
+ Assert.IsTrue (q.Transactional, "Queue should be transactional");
+ Assert.IsTrue (MessageQueue.Exists (qName), "Queue should exist");
+ }
+
+ private bool Contains(MessageQueue[] qs, String qName)
+ {
+ foreach (MessageQueue q in qs)
+ {
+ if (q.QueueName == qName)
+ return true;
+ }
+ return false;
+ }
+
+ [Test]
+ public void GetPublicQueues ()
+ {
+ string qName1 = @".\admin-queue-3";
+ string qName2 = @".\admin-queue-4";
+
+ MessageQueue.Create (qName1);
+ MessageQueue.Create (qName2);
+
+ MessageQueue[] mq = MessageQueue.GetPublicQueues ();
+ Assert.IsTrue (Contains (mq, "admin-queue-3"), qName1 + " not found");
+ Assert.IsTrue (Contains (mq, "admin-queue-4"), qName2 + " not found");
+ }
+
+ [Test]
+ public void GetQueue ()
+ {
+ MessageQueue q1 = MQUtil.GetQueue(@".\private$\admin-queue-5", true);
+ Assert.IsTrue (q1.Transactional, "Queue should be transactional");
+ MessageQueue q2 = MQUtil.GetQueue(@".\private$\admin-queue-5", true);
+ Assert.IsTrue (q2.Transactional, "Queue should be transactional");
+ }
+
+ [Test]
+ [ExpectedException (typeof (MessageQueueException))]
+ public void PurgeQueue ()
+ {
+ MessageQueue q = MQUtil.GetQueue(@".\private$\purge-queue");
+ Message m1 = new Message ("foobar1", new BinaryMessageFormatter ());
+ Message m2 = new Message ("foobar2", new BinaryMessageFormatter ());
+ Message m3 = new Message ("foobar3", new BinaryMessageFormatter ());
+ Message m4 = new Message ("foobar4", new BinaryMessageFormatter ());
+
+ q.Send (m1);
+ q.Send (m2);
+ q.Send (m3);
+ q.Send (m4);
+
+ q.Receive ();
+ q.Purge ();
+ q.Receive (new TimeSpan (0, 0, 2));
+ }
+
+ [Test]
+ public void DeleteQueue ()
+ {
+ MessageQueue q = MQUtil.GetQueue(@".\private$\delete-queue");
+ Message m1 = new Message ("foobar1", new BinaryMessageFormatter ());
+
+ q.Send (m1);
+
+ q.Receive ();
+
+ MessageQueue.Delete(@".\private$\delete-queue");
+ }
+ }
+}
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+using System.Reflection;
+using System.Threading;
+using System.Text.RegularExpressions;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ [TestFixture]
+ public class AsyncPeekTest {
+
+ bool eventCalled = false;
+
+ private void HandleMessage (object source, PeekCompletedEventArgs args) {
+ eventCalled = true;
+ }
+
+ [Test]
+ public void BeginPeek()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-1");
+ Message s = new Message (new BinaryMessageFormatter ());
+ string body = "foo-" + DateTime.Now.ToString ();
+ s.Body = body;
+ q.Send (s);
+
+ q.PeekCompleted += new PeekCompletedEventHandler (HandleMessage);
+ IAsyncResult result = q.BeginPeek ();
+ result.AsyncWaitHandle.WaitOne ();
+ Message rMsg = q.EndPeek (result);
+ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
+ Assert.IsTrue (eventCalled, "Handle Message not called");
+
+ Assert.IsNotNull (q.Receive (), "Message not peeked");
+ }
+
+ [Test]
+ public void BeginPeekWithTimeout()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-2");
+ Message s = new Message (new BinaryMessageFormatter ());
+ string body = "foo-" + DateTime.Now.ToString ();
+ s.Body = body;
+ q.Send (s);
+
+ IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2));
+ result.AsyncWaitHandle.WaitOne ();
+ Message rMsg = q.EndPeek (result);
+ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
+
+ Assert.IsNotNull (q.Receive (), "Message not peeked");
+ }
+
+ [Test]
+ public void BeginPeekWithStateAndTimeout()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-3");
+ Message s = new Message (new BinaryMessageFormatter ());
+ string body = "foo-" + DateTime.Now.ToString ();
+ s.Body = body;
+ q.Send (s);
+
+ IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2), "foo");
+ result.AsyncWaitHandle.WaitOne ();
+ Message rMsg = q.EndPeek (result);
+ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
+ Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
+
+ Assert.IsNotNull (q.Receive (), "Message not peeked");
+ }
+
+ private bool success = false;
+
+ public void TestCallback (IAsyncResult result)
+ {
+ success = true;
+ }
+
+ [Test]
+ public void BeginPeekWithStateAndTimeoutAndCallback()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-4");
+ Message s = new Message (new BinaryMessageFormatter ());
+ string body = "foo-" + DateTime.Now.ToString ();
+ s.Body = body;
+ q.Send (s);
+ AsyncCallback ac = new AsyncCallback (TestCallback);
+ IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2), "foo", ac);
+ result.AsyncWaitHandle.WaitOne ();
+ Message rMsg = q.EndPeek (result);
+ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
+ Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
+ Assert.IsTrue (success, "Callback not run");
+
+ Assert.IsNotNull (q.Receive (), "Message not peeked");
+ }
+
+ [Test]
+ [ExpectedException (typeof (MessageQueueException))]
+ public void BeginPeekWithException()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-5");
+ IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2));
+ result.AsyncWaitHandle.WaitOne ();
+ q.EndPeek (result);
+ }
+ }
+}
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+using System.Reflection;
+using System.Threading;
+using System.Text.RegularExpressions;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ [TestFixture]
+ public class AsyncReceiveTest {
+
+ private Message m;
+ private string failureMessage = null;
+ private string state = null;
+
+ private void HandleMessage (object source, ReceiveCompletedEventArgs args) {
+ try {
+ MessageQueue q = (MessageQueue) source;
+ m = q.EndReceive (args.AsyncResult);
+ state = (string) args.AsyncResult.AsyncState;
+ } catch (Exception e) {
+ failureMessage = e.Message;
+ }
+ }
+
+ [Test]
+ public void BeginReceive()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-receive-1");
+ Message s = new Message (new BinaryMessageFormatter ());
+ string body = "foo-" + DateTime.Now.ToString ();
+ s.Body = body;
+ q.Send (s);
+
+ q.ReceiveCompleted += new ReceiveCompletedEventHandler (HandleMessage);
+ IAsyncResult result = q.BeginReceive ();
+ result.AsyncWaitHandle.WaitOne ();
+ Message rMsg = q.EndReceive (result);
+ Assert.IsNotNull (rMsg, "No message received");
+ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
+ }
+
+ [Test]
+ public void BeginReceiveWithTimeout()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-receive-2");
+ Message s = new Message (new BinaryMessageFormatter ());
+ string body = "foo-" + DateTime.Now.ToString ();
+ s.Body = body;
+ q.Send (s);
+
+ IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2));
+ result.AsyncWaitHandle.WaitOne ();
+ Message rMsg = q.EndReceive (result);
+ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
+ }
+
+ [Test]
+ public void BeginReceiveWithStateAndTimeout()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-receive-3");
+ Message s = new Message (new BinaryMessageFormatter ());
+ string body = "foo-" + DateTime.Now.ToString ();
+ s.Body = body;
+ q.Send (s);
+
+ IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2), "foo");
+ result.AsyncWaitHandle.WaitOne ();
+ Message rMsg = q.EndReceive (result);
+ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
+ Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
+ }
+
+ private bool success = false;
+
+ public void TestCallback (IAsyncResult result)
+ {
+ success = true;
+ }
+
+ [Test]
+ public void BeginReceiveWithStateAndTimeoutAndCallback()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-receive-4");
+ Message s = new Message (new BinaryMessageFormatter ());
+ string body = "foo-" + DateTime.Now.ToString ();
+ s.Body = body;
+ q.Send (s);
+ AsyncCallback ac = new AsyncCallback (TestCallback);
+ IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2), "foo", ac);
+ result.AsyncWaitHandle.WaitOne ();
+ Message rMsg = q.EndReceive (result);
+ Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
+ Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
+ Assert.IsTrue (success, "Callback not run");
+ }
+
+ [Test]
+ [ExpectedException (typeof (MessageQueueException))]
+ public void BeginReceiveWithException()
+ {
+ MessageQueue q = MQUtil.GetQueue (@".\private$\async-peek-5");
+ IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2));
+ result.AsyncWaitHandle.WaitOne ();
+ q.EndReceive (result);
+ }
+ }
+}
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+using System.Reflection;
+using System.Threading;
+using System.Text.RegularExpressions;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ [TestFixture]
+ public class BasicMessageTest {
+
+ [Test]
+ public void SendReceiveBinaryMessage ()
+ {
+ String qName = @"private$\testq";
+ String qPath = @".\" + qName;
+ MessageQueue mq = MQUtil.GetQueue (qPath);
+ Assert.AreEqual(qName, mq.QueueName, "Queue name not set properly");
+ String s = "Test: " + DateTime.Now;
+ Message m = new Message (s, new BinaryMessageFormatter ());
+ m.CorrelationId = Guid.NewGuid () + "\\0";
+ mq.MessageReadPropertyFilter.SetAll ();
+
+ mq.Send (m);
+
+ Message m2 = mq.Receive ();
+ m2.Formatter = new BinaryMessageFormatter ();
+ Assert.AreEqual (s, m2.Body);
+
+ //Assert.IsTrue (DateTime.MinValue == m.ArrivedTime);
+ Assert.IsNotNull(m2.Id, "Id is null");
+ Assert.IsTrue (Guid.Empty.ToString () != m2.Id, "Id is Empty");
+ Assert.IsTrue (DateTime.MinValue != m2.ArrivedTime, "Arrived Time is not set");
+ Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
+ Assert.AreEqual (m.CorrelationId, m2.CorrelationId, "CorrelationId not set properly");
+ Assert.IsTrue (0 != m2.SenderVersion);
+ // TODO: This is not support on a workgroup installation.
+ //Assert.IsNotNull (m2.SourceMachine, "SourceMachine is null");
+ Assert.AreEqual (qName, m2.DestinationQueue.QueueName, "Destination Queue not set");
+
+ mq.Close ();
+ }
+
+ [Test]
+ public void SendMessageWithLabel ()
+ {
+ String qName = @".\private$\testq";
+ String label = "mylabel";
+ MessageQueue mq = MQUtil.GetQueue (qName);
+ Assert.AreEqual (@"private$\testq", mq.QueueName, "Queue name not set properly");
+ String s = "Test: " + DateTime.Now;
+ Message m = new Message (s, new BinaryMessageFormatter ());
+ m.CorrelationId = Guid.NewGuid () + "\\0" ;
+
+ mq.Send (m, label);
+
+ Message m2 = mq.Receive ();
+ m2.Formatter = new BinaryMessageFormatter ();
+ Assert.AreEqual (s, m2.Body, "Message not passed correctly");
+ Assert.AreEqual (label, m2.Label, "Label not passed correctly");
+ }
+
+
+ [Test]
+ public void CheckDefaults ()
+ {
+ Message m = new Message ("Test", new BinaryMessageFormatter ());
+ Assert.AreEqual (true, m.AttachSenderId, "AttachSenderId has incorrect default");
+ Assert.AreEqual (Guid.Empty.ToString () + "\\0", m.Id, "Id has incorrect default");
+ Assert.AreEqual ("Microsoft Base Cryptographic Provider, Ver. 1.0",
+ m.AuthenticationProviderName,
+ "AuthenticationProviderName has incorrect default");
+ Assert.AreEqual (0, m.Extension.Length, "Extension has incorrect default");
+ Assert.AreEqual ("", m.Label, "Label has incorrect default");
+ Assert.IsFalse (m.Recoverable, "Recoverable has incorrect default");
+ Assert.IsFalse (m.IsFirstInTransaction, "IsFirstInTransaction has incorrect default");
+ Assert.IsFalse (m.IsLastInTransaction, "IsLastInTransaction has incorrect default");
+ Assert.AreEqual ("", m.TransactionId, "TransactionId has incorrect default");
+ Assert.AreEqual (MessagePriority.Normal, m.Priority, "MessagePriority has incorrect default");
+ }
+
+ private static void CheckInvalidOperation (Message m, String property)
+ {
+ PropertyInfo pi = m.GetType ().GetProperty (property);
+ try {
+ Assert.IsNotNull (pi, "Property not defined: " + property);
+ object o = pi.GetValue (m, null);
+ Assert.Fail (property + ": " + o);
+ } catch (InvalidOperationException) {
+ } catch (TargetInvocationException e) {
+ Assert.AreEqual (typeof (InvalidOperationException),
+ e.InnerException.GetType ());
+ }
+ }
+
+ [Test]
+ public void CheckInvalidPropertyOperations ()
+ {
+ Message m = new Message ("Test", new BinaryMessageFormatter ());
+ CheckInvalidOperation (m, "Acknowledgment");
+ CheckInvalidOperation (m, "ArrivedTime");
+ CheckInvalidOperation (m, "Authenticated");
+ CheckInvalidOperation (m, "DestinationQueue");
+ //CheckInvalidOperation (m, "Id");
+ //CheckInvalidOperation (m, "IsFirstInTransaction");
+ //CheckInvalidOperation (m, "IsLastInTransaction");
+ // TODO: Support 2.0 features.
+ //CheckInvalidOperation (m, "LookupId");
+ CheckInvalidOperation (m, "MessageType");
+ CheckInvalidOperation (m, "SenderId");
+ CheckInvalidOperation (m, "SenderVersion");
+ CheckInvalidOperation (m, "SentTime");
+ CheckInvalidOperation (m, "SourceMachine");
+ //CheckInvalidOperation (m, "TransactionId");
+ }
+
+ private static void CheckArgumentInvalid(Message m, String property, Type exceptionType)
+ {
+ PropertyInfo pi = m.GetType().GetProperty(property);
+ try {
+ Assert.IsNotNull(pi, "Property not defined: " + property);
+ pi.SetValue(m, null, null);
+ Assert.Fail(property);
+ } catch (InvalidOperationException) {
+ } catch (TargetInvocationException e) {
+ Assert.AreEqual(exceptionType,
+ e.InnerException.GetType(),
+ property);
+ }
+ }
+
+ [Test]
+ public void CheckArgumentInvalidForProperties ()
+ {
+ Message m = new Message ("Stuff");
+ CheckArgumentInvalid (m, "DestinationSymmetricKey", typeof (ArgumentNullException));
+ CheckArgumentInvalid (m, "DigitalSignature", typeof(ArgumentNullException));
+ CheckArgumentInvalid (m, "Extension", typeof(ArgumentNullException));
+ }
+
+ [Test]
+ public void SendReceiveBinaryMessageWithAllPropertiesSet ()
+ {
+ String qName = @"private$\testq";
+ String qPath = @".\" + qName;
+ MessageQueue mq = MQUtil.GetQueue (qPath);
+ mq.MessageReadPropertyFilter.SetAll ();
+ Assert.AreEqual(qName, mq.QueueName, "Queue name not set properly");
+
+ MessageQueue adminQ = MQUtil.GetQueue (@".\private$\myadmin");
+ MessageQueue responseQ = MQUtil.GetQueue (@".\private$\myresponse");
+ Guid connectorType = Guid.NewGuid ();
+ String s = "Test: " + DateTime.Now;
+
+ Message m = new Message (s, new BinaryMessageFormatter ());
+ m.CorrelationId = Guid.NewGuid () + "\\0";
+ m.AcknowledgeType = AcknowledgeTypes.PositiveArrival;
+ m.AdministrationQueue = adminQ;
+ m.AppSpecific = 5;
+ //m.AuthenticationProviderName = "Test Provider Name";
+ //m.AuthenticationProviderType = CryptographicProviderType.None;
+ //m.ConnectorType = connectorType;
+ //m.DestinationSymmetricKey = new byte[] { 0x0A, 0x0B, 0x0C };
+ //m.DigitalSignature = new byte[] { 0x0C, 0x0D, 0x0E };
+ //m.EncryptionAlgorithm = EncryptionAlgorithm.Rc4;
+ m.Extension = new byte[] { 0x01, 0x02, 0x03 };
+ //m.HashAlgorithm = HashAlgorithm.Sha;
+ m.Label = "MyLabel";
+ m.Priority = MessagePriority.AboveNormal;
+ m.Recoverable = true;
+ m.ResponseQueue = responseQ;
+ m.SenderCertificate = new byte[] { 0x04, 0x05, 0x06 };
+ m.TimeToBeReceived = new TimeSpan(0, 0, 10);
+ m.TimeToReachQueue = new TimeSpan(0, 0, 5);
+ //m.UseAuthentication = true;
+ m.UseDeadLetterQueue = true;
+ //m.UseEncryption = true;
+
+ mq.Send (m);
+
+ Message m2 = mq.Receive ();
+
+ m2.Formatter = new BinaryMessageFormatter ();
+ Assert.AreEqual (s, m2.Body);
+
+ Assert.AreEqual (AcknowledgeTypes.PositiveArrival, m2.AcknowledgeType,
+ "AcknowledgeType not passed correctly");
+ Assert.AreEqual (adminQ.QueueName, m2.AdministrationQueue.QueueName,
+ "AdministrationQueue not passed correctly");
+ Assert.AreEqual (5, m2.AppSpecific, "AppSpecific not passed correctly");
+ //Assert.AreEqual (m.AuthenticationProviderName, m2.AuthenticationProviderName,
+ // "AuthenticationProviderName not passed correctly");
+ //Assert.AreEqual (m.AuthenticationProviderType, m2.AuthenticationProviderType,
+ // "AuthenticationProviderType not passed correctly");
+ //Assert.AreEqual (connectorType, m2.ConnectorType,
+ // "ConnectorType not passed correctly");
+ Assert.AreEqual (m.CorrelationId, m2.CorrelationId,
+ "CorrelationId not passed correctly");
+ //AreEqual (m.DestinationSymmetricKey, m2.DestinationSymmetricKey,
+ // "DestinationSymmetricKey not passed correctly");
+ //AreEqual (m.DigitalSignature, m2.DigitalSignature,
+ // "DigitalSignature not passed properly");
+ //Assert.AreEqual (EncryptionAlgorithm.Rc4, m2.EncryptionAlgorithm,
+ // "EncryptionAlgorithm not passed properly");
+ AreEqual (m.Extension, m2.Extension, "Extension not passed properly");
+ //Assert.AreEqual (m.HashAlgorithm, m2.HashAlgorithm,
+ // "HashAlgorithm not passed properly");
+ Assert.AreEqual (m.Label, m2.Label, "Label not passed correctly");
+ Assert.AreEqual (MessagePriority.AboveNormal, m2.Priority,
+ "Priority not passed properly");
+ Assert.AreEqual (true, m2.Recoverable, "Recoverable not passed properly");
+ Assert.AreEqual (responseQ.QueueName, m2.ResponseQueue.QueueName,
+ "ResponseQueue not passed properly");
+ AreEqual (m.SenderCertificate, m2.SenderCertificate,
+ "SenderCertificate not passed properly");
+ Assert.AreEqual (m.TimeToBeReceived, m2.TimeToBeReceived,
+ "TimeToBeReceived not passed properly");
+ Assert.AreEqual (m.TimeToReachQueue, m2.TimeToReachQueue,
+ "TimeToReachQueue not passed properly");
+ //Assert.IsTrue (m2.UseAuthentication,
+ // "UseAuthentication not passed properly");
+ Assert.IsTrue (m2.UseDeadLetterQueue,
+ "UseDeadLetterQueue not passed properly");
+ //Assert.IsTrue (m2.UseEncryption, "UseEncryption not pass properly");
+ //Assert.AreEqual ();
+
+ Assert.IsNotNull (m2.Id, "Id is null");
+ Assert.IsTrue (Guid.Empty.ToString () != m2.Id, "Id is Empty");
+ Assert.IsTrue (DateTime.MinValue != m2.ArrivedTime, "Arrived Time is not set");
+ Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
+ Assert.IsTrue (0 != m2.SenderVersion);
+
+ //Assert.IsNotNull (m2.SourceMachine, "SourceMachine is null");
+
+ }
+
+ private static void AreEqual(byte[] expected, byte[] actual, string message)
+ {
+ Assert.AreEqual (expected.Length, actual.Length, message);
+ for (int i = 0; i < expected.Length; i++)
+ Assert.AreEqual (expected[i], actual[i], message);
+ }
+
+ //[Test]
+ // No supported by Rabbit
+ public void SendPriorityMessages ()
+ {
+ MessageQueue mq = MQUtil.GetQueue ("testpriority");
+ Message sent1 = new Message ("Highest", new BinaryMessageFormatter ());
+ sent1.Priority = MessagePriority.Highest;
+ Message sent2 = new Message ("Lowest", new BinaryMessageFormatter ());
+ sent2.Priority = MessagePriority.Lowest;
+
+ mq.Send (sent1);
+ mq.Send (sent2);
+
+ Message received1 = mq.Receive ();
+ Message received2 = mq.Receive ();
+
+ Assert.AreEqual (MessagePriority.Highest, received2.Priority,
+ "Priority delivery incorrect");
+ Assert.AreEqual (MessagePriority.Lowest, received1.Priority,
+ "Priority delivery incorrect");
+ }
+
+ [Test]
+ public void SendReceiveXmlMessage ()
+ {
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\testq");
+ String s = "Test: " + DateTime.Now;
+ Message m = new Message (s, new XmlMessageFormatter (new Type[] { typeof (string) }));
+ mq.MessageReadPropertyFilter.SetAll();
+
+ mq.Send (m);
+ Message m2 = mq.Receive ();
+ m2.Formatter = new XmlMessageFormatter (new Type[] { typeof (string) });
+ Assert.AreEqual (s, m2.Body);
+
+ Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
+ Assert.IsNotNull (m2.ArrivedTime, "Acknowledgment");
+ Assert.IsNotNull (m2.Id, "Id");
+ }
+
+ [Test]
+ public void SendBinaryText ()
+ {
+ string path = @".\private$\MyQ";
+ string body = "This is a test";
+
+ MessageQueue q = MQUtil.GetQueue (path);
+
+ q.Formatter = new BinaryMessageFormatter ();
+
+ q.Send (body);
+
+ Message m2 = q.Receive ();
+
+ Assert.IsNotNull (m2.Formatter, "Formatter is null");
+ Assert.AreEqual (typeof (BinaryMessageFormatter), m2.Formatter.GetType ());
+ Assert.AreEqual (body, m2.Body);
+ }
+
+ [Test]
+ public void SendDefaultText ()
+ {
+ string path = @".\private$\MyQ";
+ string body = "This is a test";
+
+ MessageQueue q = MQUtil.GetQueue (path, new XmlMessageFormatter ());
+
+ q.Send (body);
+
+ Message m2 = q.Receive ();
+ XmlMessageFormatter xmlf = (XmlMessageFormatter) q.Formatter;
+ //Assert.AreEqual (typeof (string), xmlf.TargetTypes[0]);
+ Assert.AreEqual (typeof (XmlMessageFormatter), m2.Formatter.GetType ());
+ Assert.AreEqual (body, m2.Body);
+ Assert.AreEqual (0, m2.BodyType);
+ }
+
+ [Test]
+ public void SendBinaryObject ()
+ {
+ string path = @".\private$\MyQ";
+ Thingy body = new Thingy ();
+ body.MyProperty1 = 42;
+ body.MyProperty2 = "Something";
+ body.MyProperty3 = "Something else";
+
+ MessageQueue q = MQUtil.GetQueue (path);
+
+ q.Formatter = new BinaryMessageFormatter ();
+
+ q.Send (body);
+
+ Message m2 = q.Receive ();
+ Thingy body2 = (Thingy) m2.Body;
+
+ Assert.AreEqual (typeof (BinaryMessageFormatter), m2.Formatter.GetType ());
+ Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
+ Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
+ Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
+ Assert.AreEqual (768, m2.BodyType);
+ }
+
+ [Test]
+ public void SendDefaultObject ()
+ {
+ string path = @".\private$\MyQ";
+ Thingy body = new Thingy();
+ body.MyProperty1 = 42;
+ body.MyProperty2 = "Something";
+ body.MyProperty3 = "Something else";
+
+ MessageQueue q = MQUtil.GetQueue (path, new XmlMessageFormatter ());
+
+ q.Send (body);
+
+ MessageQueue q2 = MQUtil.GetQueue (path);
+ q2.Formatter = new XmlMessageFormatter (new Type[] { typeof(Thingy) });
+
+ Message m2 = q2.Receive ();
+ Thingy body2 = (Thingy) m2.Body;
+
+ Assert.AreEqual (typeof (XmlMessageFormatter), m2.Formatter.GetType ());
+ Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
+ Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
+ Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
+ }
+
+ [Test]
+ public void SendBinaryMessage ()
+ {
+ string path = @".\private$\MyQ";
+ Thingy body = new Thingy ();
+ body.MyProperty1 = 42;
+ body.MyProperty2 = "Something";
+ body.MyProperty3 = "Something else";
+ Message m1 = new Message (body);
+ m1.Formatter = new BinaryMessageFormatter ();
+
+ MessageQueue q = MQUtil.GetQueue (path);
+
+ q.Send (m1);
+
+ Message m2 = q.Receive ();
+ m2.Formatter = new BinaryMessageFormatter ();
+ Assert.IsNotNull (m2.Formatter);
+ Assert.AreEqual (typeof (BinaryMessageFormatter), m2.Formatter.GetType ());
+ Thingy body2 = (Thingy) m2.Formatter.Read (m2);
+
+ Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
+ Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
+ Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
+ }
+
+ [Test]
+ public void SendDefaultMessage ()
+ {
+ string path = @".\private$\MyQ";
+ Thingy body = new Thingy ();
+ body.MyProperty1 = 42;
+ body.MyProperty2 = "Something";
+ body.MyProperty3 = "Something else";
+ Message m1 = new Message (body);
+ Assert.IsNull (m1.Formatter);
+
+ MessageQueue q = MQUtil.GetQueue (path, new XmlMessageFormatter ());
+
+ q.Send (m1);
+
+ Message m2 = q.Receive ();
+ m2.Formatter = new XmlMessageFormatter (new Type[] { typeof (Thingy) });
+ Assert.IsNotNull (m2.Formatter);
+ Assert.AreEqual (typeof (XmlMessageFormatter), m2.Formatter.GetType ());
+ Thingy body2 = (Thingy) m2.Formatter.Read (m2);
+
+ Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
+ Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
+ Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
+ }
+ }
+
+ [Serializable]
+ public class Thingy
+ {
+ private int myVar1;
+
+ public int MyProperty1
+ {
+ get { return myVar1; }
+ set { myVar1 = value; }
+ }
+
+ private string myVar2;
+
+ public string MyProperty2
+ {
+ get { return myVar2; }
+ set { myVar2 = value; }
+ }
+
+ private string myVar3;
+
+ public string MyProperty3
+ {
+ get { return myVar3; }
+ set { myVar3 = value; }
+ }
+ }
+}
+2009-07-19 Michael Barker <mike@middlesoft.co.uk>
+
+ * AdminTest.cs: Moved to System.Messaging
+ * AsyncPeekTest.cs: Moved to System.Messaging
+ * AsyncReceiveTest.cs: Moved to System.Messaging
+ * BasicMessagingTest.cs: Moved to System.Messaging
+ * MessageEnumeratorTest.cs: Moved to System.Messaging
+ * MQUtil.cs: Moved to System.Messaging
+ * PeekTest.cs: Moved to System.Messaging
+ * SelectorTest.cs: Moved to System.Messaging
+
2009-01-05 Michael Barker <mike@middlesoft.co.uk>
* BinaryMessageFormatter.cs, XMLMessageFormatterTest.cs, TestUtils.cs,
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ public class MQUtil
+ {
+ public static MessageQueue GetQueue (string path)
+ {
+ return GetQueue (path, false);
+ }
+
+ public static MessageQueue GetQueue (string path, bool isTransactional)
+ {
+ return GetQueue (path, isTransactional,
+ new BinaryMessageFormatter ());
+ }
+
+ public static MessageQueue GetQueue (string path, IMessageFormatter formatter)
+ {
+ return GetQueue (path, false, formatter);
+ }
+
+ public static MessageQueue GetQueue (string path, bool isTransactional,
+ IMessageFormatter formatter)
+ {
+ MessageQueue q;
+ if (MessageQueue.Exists (path)) {
+ q = new MessageQueue (path);
+ } else {
+ q = MessageQueue.Create (path, isTransactional);
+ }
+ q.Formatter = formatter;
+ return q;
+ }
+ }
+}
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+
+//using Mono.Messaging;
+//using Mono.Messaging.RabbitMQ;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ [TestFixture]
+ public class MessageEnumeratorTest {
+
+ private readonly String qName = @".\private$\testq2";
+
+ private void SendMessage (string s) {
+ MessageQueue mq = MQUtil.GetQueue (qName);
+ Message m = new Message (s, new BinaryMessageFormatter ());
+ m.CorrelationId = Guid.NewGuid () + "\\0";
+ mq.Send (m);
+ }
+
+ [Test]
+ public void RemoveMessage ()
+ {
+ SendMessage ("message 1");
+ SendMessage ("message 2");
+ SendMessage ("message 3");
+ SendMessage ("message 4");
+
+ MessageQueue mq0 = MQUtil.GetQueue (qName);
+ MessageEnumerator me0 = mq0.GetMessageEnumerator ();
+
+ me0.MoveNext ();
+ me0.MoveNext ();
+ me0.MoveNext ();
+
+ Message m0 = me0.RemoveCurrent ();
+
+ me0.MoveNext ();
+
+ me0.Dispose ();
+ mq0.Dispose ();
+
+ MessageQueue mq1 = MQUtil.GetQueue (qName);
+ MessageEnumerator me1 = mq1.GetMessageEnumerator ();
+
+ me1.MoveNext();
+ me1.MoveNext();
+ me1.MoveNext();
+
+ Message m1 = me1.Current;
+ m1.Formatter = new BinaryMessageFormatter ();
+ Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
+
+ mq1.Purge ();
+ MessageQueue.Delete (qName);
+ }
+
+ [Test]
+ public void RemoveMessageWithTimeout ()
+ {
+ SendMessage ("message 1");
+ SendMessage ("message 2");
+ SendMessage ("message 3");
+ SendMessage ("message 4");
+
+ MessageQueue mq0 = MQUtil.GetQueue (qName);
+ MessageEnumerator me0 = mq0.GetMessageEnumerator ();
+
+ TimeSpan ts = new TimeSpan (0, 0, 2);
+
+ me0.MoveNext (ts);
+ me0.MoveNext (ts);
+ me0.MoveNext (ts);
+
+ Message m0 = me0.RemoveCurrent (ts);
+
+ me0.MoveNext (ts);
+
+ me0.Dispose ();
+ mq0.Dispose ();
+
+ MessageQueue mq1 = MQUtil.GetQueue (qName);
+ MessageEnumerator me1 = mq1.GetMessageEnumerator ();
+
+ me1.MoveNext (ts);
+ me1.MoveNext (ts);
+ me1.MoveNext (ts);
+
+ Message m1 = me1.Current;
+ m1.Formatter = new BinaryMessageFormatter ();
+ Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
+
+ mq1.Purge ();
+ MessageQueue.Delete (qName);
+ }
+
+ //[Test]
+ // Not supported with AMQP
+ public void RemoveMessageWithTx ()
+ {
+ MessageQueue q = MQUtil.GetQueue ("testq3");
+
+ q.Formatter = new BinaryMessageFormatter ();
+ q.Send ("foo1");
+ q.Send ("foo2");
+
+ MessageEnumerator me1 = q.GetMessageEnumerator ();
+ MessageQueueTransaction tx = new MessageQueueTransaction ();
+ me1.MoveNext ();
+ Message m1 = me1.Current;
+ me1.RemoveCurrent (tx);
+ tx.Commit ();
+ me1.Close ();
+
+ MessageEnumerator me2 = q.GetMessageEnumerator ();
+ Assert.IsTrue (me1.MoveNext ());
+ me2.RemoveCurrent ();
+ Assert.IsFalse (me2.MoveNext ());
+ }
+ }
+}
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ [TestFixture]
+ public class PeekTest {
+
+ [Test]
+ public void PeekMessage ()
+ {
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message s1 = new Message(body, new BinaryMessageFormatter());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\peek-queue-1");
+ mq.Send (s1);
+
+ Message r1 = mq.Peek ();
+ Assert.AreEqual (body, r1.Body);
+
+ Message r2 = mq.Receive ();
+ Assert.AreEqual (body, r2.Body);
+ }
+
+ [Test]
+ public void PeekMessageWithTimeout ()
+ {
+ String body = "foo-" + DateTime.Now.ToString();
+ Message s1 = new Message(body, new BinaryMessageFormatter());
+ MessageQueue mq = MQUtil.GetQueue(@".\private$\peek-queue-2");
+ mq.Send (s1);
+
+ Message r1 = mq.Peek (new TimeSpan (0, 0, 2));
+ Assert.AreEqual (body, r1.Body);
+
+ Message r2 = mq.Receive ();
+ Assert.AreEqual (body, r2.Body);
+ }
+
+ [Test]
+ [ExpectedException (typeof (MessageQueueException))]
+ public void PeekNoMessageWithTimeout ()
+ {
+ MessageQueue mq = MQUtil.GetQueue(@".\private$\peek-queue-3");
+ Message r1 = mq.Peek (new TimeSpan (0, 0, 2));
+ }
+
+ [Test]
+ public void PeekById ()
+ {
+ String body = "Foo-" + DateTime.Now.ToString ();
+ Message s1 = new Message (body, new BinaryMessageFormatter());
+ MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-4");
+ q.Send (s1);
+
+ String id = s1.Id;
+ try {
+ Message r1 = q.PeekById (id);
+ Assert.AreEqual (body, r1.Body, "Unable to PeekById correctly");
+ } finally {
+ q.Purge ();
+ }
+ }
+
+ [Test]
+ public void PeekByIdWithTimeout ()
+ {
+ String body = "Foo-" + DateTime.Now.ToString ();
+ Message s1 = new Message (body, new BinaryMessageFormatter());
+ MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-5");
+ q.Send (s1);
+
+ String id = s1.Id;
+ try {
+ Message r1 = q.PeekById (id, new TimeSpan (0, 0, 2));
+ Assert.AreEqual (body, r1.Body, "Unable to PeekById correctly");
+ } finally {
+ q.Purge ();
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void PeekByIdNotFound ()
+ {
+ String body = "Foo-" + DateTime.Now.ToString ();
+ Message s1 = new Message (body, new BinaryMessageFormatter());
+ MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-6");
+ q.Send (s1);
+
+ String id = "fail!";
+
+ try {
+ Message r1 = q.PeekById (id);
+ } finally {
+ q.Purge ();
+ }
+ }
+
+ [Test]
+ public void PeekByCorrelationId ()
+ {
+ String correlationId = Guid.NewGuid () + "\\0";
+ String body = "Foo-" + DateTime.Now.ToString ();
+ Message s1 = new Message (body, new BinaryMessageFormatter());
+ s1.CorrelationId = correlationId;
+ MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-7");
+ q.Formatter = new BinaryMessageFormatter ();
+ q.Send (s1);
+
+ try {
+ Message r1 = q.PeekByCorrelationId (correlationId);
+ Assert.AreEqual (body, r1.Body, "Unable to PeekByCorrelationId correctly");
+ } finally {
+ q.Purge ();
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void PeekByCorrelationIdNotFound ()
+ {
+ String body = "Foo-" + DateTime.Now.ToString ();
+ Message s1 = new Message (body);
+ String correlationId = Guid.NewGuid() + "\\0";
+ MessageQueue q = MQUtil.GetQueue(@".\private$\peek-queue-8");
+ q.Formatter = new BinaryMessageFormatter ();
+ q.Send (s1);
+
+ try {
+ Message r1 = q.PeekByCorrelationId ("fail!");
+ } finally {
+ q.Purge ();
+ }
+ }
+
+ [Test]
+ public void PeekByCorrelationIdWithTimeout ()
+ {
+ String correlationId = Guid.NewGuid () + "\\0";
+ String body = "Foo-" + DateTime.Now.ToString ();
+ Message s1 = new Message (body, new BinaryMessageFormatter());
+ s1.CorrelationId = correlationId;
+ MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-9");
+ q.Formatter = new BinaryMessageFormatter ();
+ q.Send (s1);
+
+ try {
+ Message r1 = q.PeekByCorrelationId (correlationId, new TimeSpan (0, 0, 2));
+ Assert.AreEqual (body, r1.Body, "Unable to PeekByCorrelationId correctly");
+ } finally {
+ q.Purge ();
+ }
+ }
+ }
+}
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ [TestFixture]
+ public class SelectorTest
+ {
+
+ [Test]
+ public void SelectById ()
+ {
+ String body = "Foo-" + DateTime.Now.ToString ();
+ Message s1 = new Message (body, new BinaryMessageFormatter());
+ MessageQueue q = MQUtil.GetQueue (@".\private$\selector-queue-1");
+ q.Send (s1);
+
+ String id = s1.Id;
+
+ Message r1 = q.ReceiveById (id);
+
+ Assert.AreEqual (body, r1.Body, "Unable to ReceiveById correctly");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void SelectByIdNotFound ()
+ {
+ String body = "Foo-" + DateTime.Now.ToString();
+ Message s1 = new Message(body, new BinaryMessageFormatter());
+ MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-2");
+ q.Send (s1);
+
+ String id = "fail!";
+
+ try {
+ Message r1 = q.ReceiveById (id);
+ } finally {
+ q.Purge ();
+ }
+ }
+
+ [Test]
+ public void SelectByCorrelationId ()
+ {
+ string correlationId = Guid.NewGuid () + "\\0";
+ String body = "Foo-" + DateTime.Now.ToString();
+ Message s1 = new Message(body, new BinaryMessageFormatter());
+ s1.CorrelationId = correlationId;
+ MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-3");
+ q.Send (s1);
+
+ Message r1 = q.ReceiveByCorrelationId (correlationId);
+
+ Assert.AreEqual (body, r1.Body, "Unable to ReceiveByCorrelationId correctly");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void SelectByCorrelationIdNotFound ()
+ {
+ string correlationId = Guid.NewGuid() + "\\0";
+ String body = "Foo-" + DateTime.Now.ToString();
+ Message s1 = new Message(body, new BinaryMessageFormatter());
+ s1.CorrelationId = correlationId;
+ MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-4");
+ q.Send (s1);
+
+ try {
+ Message r1 = q.ReceiveByCorrelationId ("fail!");
+ } finally {
+ q.Purge ();
+ }
+ }
+
+ [Test]
+ public void SelectByIdWithTimeout ()
+ {
+ String body = "Foo-" + DateTime.Now.ToString();
+ Message s1 = new Message(body, new BinaryMessageFormatter());
+ MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-5");
+ q.Send (s1);
+
+ String id = s1.Id;
+
+ Message r1 = q.ReceiveById (id, new TimeSpan (0, 0, 2));
+
+ Assert.AreEqual (body, r1.Body, "Unable to ReceiveById correctly");
+ }
+
+ [Test]
+ public void SelectByCorrelationIdWithTimeout ()
+ {
+ string correlationId = Guid.NewGuid() + "\\0";
+ String body = "Foo-" + DateTime.Now.ToString();
+ Message s1 = new Message(body, new BinaryMessageFormatter());
+ s1.CorrelationId = correlationId;
+ MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-3");
+ q.Send (s1);
+
+ Message r1 = q.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2));
+
+ Assert.AreEqual (body, r1.Body, "Unable to ReceiveByCorrelationId correctly");
+ }
+ }
+}
--- /dev/null
+//
+// Test.Mono.Messaging.RabbitMQ
+//
+// Authors:
+// Michael Barker (mike@middlesoft.co.uk)
+//
+// (C) 2008 Michael Barker
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Messaging;
+using System.Reflection;
+using System.Threading;
+using System.Text.RegularExpressions;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Messaging.RabbitMQ
+{
+ [TestFixture]
+ public class TransactionMessageTest {
+
+ [Test]
+ public void Send2WithTransaction ()
+ {
+ Message sent1 = new Message ("Message 1", new BinaryMessageFormatter ());
+ Message sent2 = new Message ("Message 2", new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-1", true);
+ mq.MessageReadPropertyFilter.SetAll ();
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ mq.Send (sent1, tx);
+ mq.Send (sent2, tx);
+
+ tx.Commit ();
+
+ Message received1 = mq.Receive ();
+ Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
+ Message received2 = mq.Receive ();
+ Assert.IsNotNull (received2.TransactionId, "TransactionId not set");
+
+ Assert.AreEqual (received1.TransactionId, received2.TransactionId, "Messages have differing TransactionIds");
+ Assert.IsTrue (received1.TransactionId.Length > 1);
+ Assert.AreEqual (sent1.Body, received1.Body, "Message 1 not delivered correctly");
+ Assert.AreEqual (sent2.Body, received2.Body, "Message 2 not delivered correctly");
+ }
+ }
+
+ [Test]
+ public void Send2WithLabelWithTransaction ()
+ {
+ String label1 = "label1";
+ String label2 = "label2";
+ Message sent1 = new Message ("Message 1", new BinaryMessageFormatter ());
+ Message sent2 = new Message ("Message 2", new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-2", true);
+ mq.MessageReadPropertyFilter.SetAll ();
+ Assert.IsTrue(mq.Transactional, "Message Queue should be transactional");
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ mq.Send (sent1, label1, tx);
+ mq.Send (sent2, label2, tx);
+
+ tx.Commit ();
+
+ Message received1 = mq.Receive ();
+ Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
+ Message received2 = mq.Receive ();
+ Assert.IsNotNull (received2.TransactionId, "TransactionId not set");
+
+ Assert.AreEqual (received1.TransactionId, received2.TransactionId, "Messages have differing TransactionIds");
+ Assert.IsTrue (received1.TransactionId.Length > 1);
+ Assert.AreEqual (sent1.Body, received1.Body, "Message 1 not delivered correctly");
+ Assert.AreEqual (sent2.Body, received2.Body, "Message 2 not delivered correctly");
+ Assert.AreEqual (label1, received1.Label, "Label 1 not passed correctly");
+ Assert.AreEqual (label2, received2.Label, "Label 2 not passed correctly");
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (MessageQueueException))]
+ public void Send2WithTransactionAbort ()
+ {
+ Message sent1 = new Message ("Message 1", new BinaryMessageFormatter ());
+ Message sent2 = new Message ("Message 2", new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-1", true);
+ mq.MessageReadPropertyFilter.SetAll ();
+ Assert.IsTrue(mq.Transactional, "Message Queue should be transactional");
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ mq.Send (sent1, tx);
+ mq.Send (sent2, tx);
+
+ tx.Abort ();
+ mq.Receive (new TimeSpan (0, 0, 2));
+ }
+ }
+
+ [Test]
+ public void ReceiveWithTransaction ()
+ {
+ String body = "Message 4";
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-4", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.Receive (tx);
+
+ tx.Commit ();
+
+ Assert.AreEqual (body, received1.Body);
+ }
+ }
+
+ [Test]
+ public void ReceiveWithTransactionAbort ()
+ {
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-5", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.Receive (tx);
+
+ tx.Abort ();
+ }
+
+ Message received2 = mq.Receive ();
+ Assert.AreEqual (body, received2.Body);
+ }
+
+ [Test]
+ public void ReceiveWithTransactionType ()
+ {
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-6", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+
+ Message received1 = mq.Receive (MessageQueueTransactionType.Single);
+
+ Assert.AreEqual (body, received1.Body);
+ }
+
+ [Test]
+ public void SendWithTransactionType ()
+ {
+ Message sent1 = new Message ("Message 1");
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-7", true);
+ mq.MessageReadPropertyFilter.SetAll();
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+
+ Message received1 = mq.Receive ();
+ Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
+ }
+
+ [Test]
+ public void SendWithTransactionTypeAndLabel ()
+ {
+ Message sent1 = new Message ("Message 1");
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-8", true);
+ mq.MessageReadPropertyFilter.SetAll();
+ String label = "mylabel";
+
+ mq.Send (sent1, label, MessageQueueTransactionType.Single);
+
+ Message received1 = mq.Receive ();
+ Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
+ Assert.AreEqual (label, received1.Label, "Label not set");
+ }
+
+ [Test]
+ public void ReceiveByIdWithTransaction ()
+ {
+ String body = "Message 4";
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-9", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.ReceiveById (id, tx);
+
+ tx.Commit ();
+
+ Assert.AreEqual (body, received1.Body);
+ }
+ }
+
+ [Test]
+ public void ReceiveByIdWithTransactionAbort ()
+ {
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-10", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.ReceiveById (id, tx);
+
+ tx.Abort ();
+ }
+
+ Message received2 = mq.Receive ();
+ Assert.AreEqual (body, received2.Body);
+ }
+
+ [Test]
+ public void ReceiveByIdWithTransactionType ()
+ {
+ String body = "Message 4";
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-11", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ Message received1 = mq.ReceiveById (id, MessageQueueTransactionType.Single);
+ Assert.AreEqual (body, received1.Body);
+ }
+
+ [Test]
+ public void ReceiveByCorrelationIdWithTransaction ()
+ {
+ string correlationId = Guid.NewGuid() + "\\0";
+ String body = "Message 4";
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ sent1.CorrelationId = correlationId;
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-12", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.ReceiveByCorrelationId(correlationId, tx);
+
+ tx.Commit ();
+
+ Assert.AreEqual (body, received1.Body);
+ }
+ }
+
+ [Test]
+ public void ReceiveByCorrelationIdWithTransactionAbort ()
+ {
+ string correlationId = Guid.NewGuid() + "\\0";
+ String body = "foo-" + DateTime.Now.ToString();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ sent1.CorrelationId = correlationId;
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-13", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.ReceiveByCorrelationId (correlationId, tx);
+
+ tx.Abort ();
+ }
+
+ Message received2 = mq.Receive ();
+ Assert.AreEqual (body, received2.Body);
+ }
+
+ [Test]
+ public void ReceiveByCorrelationIdWithTransactionType ()
+ {
+ string correlationId = Guid.NewGuid() + "\\0";
+ String body = "Message 10";
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ sent1.CorrelationId = correlationId;
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-14", true);
+ mq.Formatter = new BinaryMessageFormatter ();
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ Message received1 = mq.ReceiveByCorrelationId (correlationId, MessageQueueTransactionType.Single);
+ Assert.AreEqual (body, received1.Body);
+ }
+
+ [Test]
+ public void ReceiveWithTransactionAndTimeout ()
+ {
+ String body = "Message 11";
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-15", true);
+ mq.Formatter = new BinaryMessageFormatter ();
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.Receive (new TimeSpan (0, 0, 2), tx);
+
+ tx.Commit ();
+
+ Assert.AreEqual (body, received1.Body);
+ }
+ }
+
+ [Test]
+ public void ReceiveWithTransactionAndTimeoutAndAbort ()
+ {
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-16", true);
+ mq.Formatter = new BinaryMessageFormatter ();
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.Receive (new TimeSpan (0, 0, 2), tx);
+
+ tx.Abort ();
+ }
+
+ Message received2 = mq.Receive ();
+ Assert.AreEqual (body, received2.Body);
+ }
+
+ [Test]
+ public void ReceiveWithTransactionTypeAndTimeout ()
+ {
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-17", true);
+ mq.Formatter = new BinaryMessageFormatter ();
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+
+ Message received1 = mq.Receive (new TimeSpan (0, 0, 5), MessageQueueTransactionType.Single);
+
+ Assert.AreEqual (body, received1.Body);
+ }
+
+ [Test]
+ [ExpectedException (typeof (MessageQueueException))]
+ public void ReceiveWithTransactionTypeAndTimeoutFailure ()
+ {
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-18", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ Message received1 = mq.Receive (new TimeSpan (0, 0, 2), MessageQueueTransactionType.Single);
+ }
+
+ [Test]
+ public void ReceiveByIdWithTransactionAndTimeout ()
+ {
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-19", true);
+ mq.Formatter = new BinaryMessageFormatter ();
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.ReceiveById (id, new TimeSpan (0, 0, 2), tx);
+
+ tx.Commit ();
+
+ Assert.AreEqual (body, received1.Body);
+ }
+ }
+
+ [Test]
+ public void ReceiveByIdWithTransactionTypeAndTimeout ()
+ {
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-20", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ Message received1 = mq.ReceiveById (id, new TimeSpan (0, 0, 2), MessageQueueTransactionType.Single);
+ Assert.AreEqual (body, received1.Body);
+ }
+
+ [Test]
+ public void ReceiveByCorrelationIdWithTransactionAndTimeout ()
+ {
+ string correlationId = Guid.NewGuid () + "\\0";
+ String body = "foo-" + DateTime.Now.ToString ();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ sent1.CorrelationId = correlationId;
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-21", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
+ tx.Begin ();
+
+ Message received1 = mq.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2), tx);
+ tx.Commit ();
+ Assert.AreEqual (body, received1.Body);
+ }
+ }
+
+ [Test]
+ public void ReceiveByCorrelationIdWithTransactionTypeAndTimeout ()
+ {
+ string correlationId = Guid.NewGuid() + "\\0";
+ String body = "foo-" + DateTime.Now.ToString();
+ Message sent1 = new Message (body, new BinaryMessageFormatter ());
+ sent1.CorrelationId = correlationId;
+ MessageQueue mq = MQUtil.GetQueue (@".\private$\tx-queue-22", true);
+ Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
+ mq.Send (sent1, MessageQueueTransactionType.Single);
+ string id = sent1.Id;
+
+ Message received1 = mq.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2), MessageQueueTransactionType.Single);
+ Assert.AreEqual (body, received1.Body);
+ }
+ }
+}
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Makefile: filter the valid profile on the framework version,
+ to make it easier to have custom variants.
+
2009-07-14 Sebastien Pouliot <sebastien@ximian.com>
* System.Net.dll.sources: Remove extra files not needed to
EXTRA_DISTFILES =
-VALID_PROFILE := $(filter net_2_0 net_2_1_raw net_4_0, $(PROFILE))
+VALID_PROFILE := $(filter 2.0 2.1 4.0, $(FRAMEWORK_VERSION))
ifndef VALID_PROFILE
LIBRARY_NAME = dummy-System.Net.dll
NO_INSTALL = yes
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Makefile: filter the valid profile on the framework version,
+ to make it easier to have custom variants.
+
2009-04-21 Sebastien Pouliot <sebastien@ximian.com>
* System.Xml.Schema/*: Remove (not needed for 2.1 anymore)
Test/Resources/FrameworkTypes/* \
Test/System.Runtime.Serialization/one.xml
-VALID_PROFILE := $(filter net_2_0 net_2_1_raw net_4_0, $(PROFILE))
+VALID_PROFILE := $(filter 2.0 2.1 4.0, $(FRAMEWORK_VERSION))
ifndef VALID_PROFILE
LIBRARY_NAME = dummy-System.Runtime.Serialization.dll
NO_INSTALL = yes
--- /dev/null
+#include net_2_1_raw_System.Runtime.Serialization.dll.sources
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Makefile: filter the valid profile on the framework version,
+ to make it easier to have custom variants.
+
2009-04-22 Sebastien Pouliot <sebastien@ximian.com>
* net_2_1_raw_System.ServiceModel.Web.dll.sources: Remove the common
EXTRA_DISTFILES = $(RESOURCE_FILES)
-VALID_PROFILE := $(filter net_2_0 net_2_1_raw net_4_0, $(PROFILE))
+VALID_PROFILE := $(filter 2.0 2.1 4.0, $(FRAMEWORK_VERSION))
ifndef VALID_PROFILE
LIBRARY_NAME = dummy-System.ServiceModel.Web.dll
NO_INSTALL = yes
--- /dev/null
+#include net_2_1_raw_System.ServiceModel.Web.dll.sources
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Makefile: filter the valid profile on the framework version,
+ to make it easier to have custom variants.
+
2009-07-17 Astushi Enomoto <atsushi@ximian.com>
* System.ServiceModel.dll.sources: add TcpRequestChannel.
# Useful for debugging under Visual Studio 2005
# NO_SIGN_ASSEMBLY = yes
-VALID_PROFILE := $(filter net_2_0 net_2_1_raw net_4_0, $(PROFILE))
+VALID_PROFILE := $(filter 2.0 2.1 4.0, $(FRAMEWORK_VERSION))
ifndef VALID_PROFILE
LIBRARY_NAME = dummy-System.ServiceModel.dll
NO_INSTALL = yes
--- /dev/null
+#include net_2_1_raw_System.ServiceModel.dll.sources
--- /dev/null
+#include net_2_1_raw_System.Xml.dll.sources
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * net_2_1_raw_System.Xml.Linq.dll: delete, and use ifdefs
+ in the few specific files.
+
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Makefile: filter the valid profile on the framework version,
+ to make it easier to have custom variants.
+
2009-06-05 Jb Evain <jbevain@novell.com>
* Makefile: fix the 2.1 build.
EXTRA_DISTFILES =
-VALID_PROFILE := $(filter net_2_0 net_2_1_raw net_4_0, $(PROFILE))
+VALID_PROFILE := $(filter 2.0 2.1 4.0, $(FRAMEWORK_VERSION))
ifndef VALID_PROFILE
LIBRARY_NAME = dummy-System.Xml.Linq.dll
NO_INSTALL = yes
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * XNodeNavigator.cs: do not compile for a NET_2_1 profile.
+
2009-05-07 Sebastien Pouliot <sebastien@ximian.com>
* XElement.cs: Use XmlReaderSettings.DtdProcessing property instead
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+#if !NET_2_1
+
using System;
using System.IO;
using System.Text;
}
}
}
+
+#endif
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Extensions.cs: do not compile for a NET_2_1 profile.
+
2007-05-02 Atsushi Enomoto <atsushi@ximian.com>
* Extensions.cs : new stub file.
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+#if !NET_2_1
+
using System;
using System.Xml;
using System.Xml.Linq;
}
}
+#endif
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Extensions.cs: do not compile for a NET_2_1 profile.
+
2007-05-06 Atsushi Enomoto <atsushi@ximian.com>
* Extensions.cs : implemented.
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+#if !NET_2_1
+
using System;
using System.Collections.Generic;
using System.Xml;
}
}
+#endif
+++ /dev/null
-../../build/common/Consts.cs
-../../build/common/Locale.cs
-../../build/common/MonoTODOAttribute.cs
-Assembly/AssemblyInfo.cs
-System.Xml.Linq/Extensions.cs
-System.Xml.Linq/LoadOptions.cs
-System.Xml.Linq/SaveOptions.cs
-System.Xml.Linq/XAttribute.cs
-System.Xml.Linq/XCData.cs
-System.Xml.Linq/XComment.cs
-System.Xml.Linq/XContainer.cs
-System.Xml.Linq/XDeclaration.cs
-System.Xml.Linq/XDocument.cs
-System.Xml.Linq/XDocumentType.cs
-System.Xml.Linq/XElement.cs
-System.Xml.Linq/XIterators.cs
-System.Xml.Linq/XName.cs
-System.Xml.Linq/XNamespace.cs
-System.Xml.Linq/XNode.cs
-System.Xml.Linq/XNodeDocumentOrderComparer.cs
-System.Xml.Linq/XNodeEqualityComparer.cs
-System.Xml.Linq/XNodeReader.cs
-System.Xml.Linq/XNodeWriter.cs
-System.Xml.Linq/XObject.cs
-System.Xml.Linq/XObjectChange.cs
-System.Xml.Linq/XObjectChangeEventArgs.cs
-System.Xml.Linq/XProcessingInstruction.cs
-System.Xml.Linq/XStreamingElement.cs
-System.Xml.Linq/XText.cs
-System.Xml.Linq/XUtil.cs
--- /dev/null
+#include net_2_1_raw_System.dll.sources
+2009-07-20 Jb Evain <jbevain@novell.com>
+
+ * Thread.cs: use the moonlight specific thread start
+ hack for the net_2_1 profile exclusively.
+
2009-06-25 Miguel de Icaza <miguel@novell.com>
* Timer.cs: Throw ArgumentNullException if the callback is null.
}
}
-#if NET_2_1
+#if NET_2_1 && !MONOTOUCH
private void StartSafe ()
{
try {
_principal = CurrentThread._principal;
// Thread_internal creates and starts the new thread,
-#if NET_2_1
+#if NET_2_1 && !MONOTOUCH
if (Thread_internal((ThreadStart) StartSafe) == (IntPtr) 0)
#else
if (Thread_internal(threadstart) == (IntPtr) 0)
static WaitCallback MoonlightHandler (WaitCallback callback)
{
-#if NET_2_1
+#if NET_2_1 && !MONOTOUCH
return delegate (object o) {
try {
callback (o);
Assert.IsNotNull (prop, "short");
}
-#if NET_2_0
+ [Test]
+ [Category ("NotWorking")]
+ public void SelectMethod_AmbiguousMatch ()
+ {
+ Type type = typeof (BinderTest);
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
+ MethodBase [] match;
+ Type [] types;
+
+ types = new Type [] { typeof (object), typeof (object []) };
+ MethodInfo mi_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_params, "#A1");
+ Assert.AreEqual (2, mi_params.GetParameters ().Length, "#A2");
+ Assert.AreEqual (typeof (object), mi_params.GetParameters () [0].ParameterType, "#B3");
+ Assert.AreEqual (typeof (object []), mi_params.GetParameters () [1].ParameterType, "#B4");
+ types = new Type [] { typeof (object) };
+ MethodInfo mi_single_param = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_single_param, "#B1");
+ Assert.AreEqual (1, mi_single_param.GetParameters ().Length, "#B2");
+ Assert.AreEqual (typeof (object), mi_single_param.GetParameters () [0].ParameterType, "#B3");
+
+ match = new MethodBase [] { mi_single_param, mi_single_param };
+ types = new Type [] { typeof (object) };
+ try {
+ binder.SelectMethod (flags, match, types, null);
+ Assert.Fail ("#C1");
+ } catch (AmbiguousMatchException) {
+ // Ambiguous match found
+ }
+
+ match = new MethodBase [] { mi_single_param, mi_single_param };
+ types = new Type [] { typeof (string) };
+ try {
+ binder.SelectMethod (flags, match, types, null);
+ Assert.Fail ("#D1");
+ } catch (AmbiguousMatchException) {
+ // Ambiguous match found
+ }
+ }
+
[Test]
public void SelectMethod_ByRef ()
{
MethodBase [] match;
Type [] types;
MethodBase selected;
+ Type ref_int;
MethodInfo mi_run = type.GetMethod ("Run", flags, binder,
new Type [] { typeof (int) }, null);
Assert.IsFalse (mi_run.GetParameters () [0].ParameterType.IsByRef, "#A1");
+#if NET_2_0
MethodInfo mi_run_ref = type.GetMethod ("Run", flags, binder,
new Type [] { typeof (int).MakeByRefType () }, null);
+#else
+ MethodInfo mi_run_ref = type.GetMethod ("RunV1", flags);
+#endif
Assert.IsTrue (mi_run_ref.GetParameters () [0].ParameterType.IsByRef, "#A2");
+#if NET_2_0
+ ref_int = typeof (int).MakeByRefType ();
+#else
+ ref_int = mi_run_ref.GetParameters () [0].ParameterType;
+#endif
+
match = new MethodBase [] { mi_run_ref };
types = new Type [] { typeof (int) };
selected = binder.SelectMethod (flags, match, types, null);
Assert.IsNull (selected, "#B1");
- types = new Type [] { typeof (int).MakeByRefType () };
+ types = new Type [] { ref_int };
selected = binder.SelectMethod (flags, match, types, null);
Assert.AreSame (mi_run_ref, selected, "#B2");
types = new Type [] { typeof (int) };
selected = binder.SelectMethod (flags, match, types, null);
Assert.AreSame (mi_run, selected, "#C1");
- types = new Type [] { typeof (int).MakeByRefType () };
+ types = new Type [] { ref_int };
selected = binder.SelectMethod (flags, match, types, null);
Assert.IsNull (selected, "#C1");
types = new Type [] { typeof (int) };
selected = binder.SelectMethod (flags, match, types, null);
Assert.AreSame (mi_run, selected, "#D1");
- types = new Type [] { typeof (int).MakeByRefType () };
+ types = new Type [] { ref_int };
selected = binder.SelectMethod (flags, match, types, null);
Assert.AreSame (mi_run_ref, selected, "#D2");
}
-#endif
[Test]
- public void ArgNullOnMethod () // see bug 58846. We throwed nullref here.
+ [Category ("NotWorking")]
+ public void SelectMethod_Params ()
+ {
+ Type type = typeof (BinderTest);
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
+ MethodBase [] match;
+ Type [] types;
+ MethodBase selected;
+
+ types = new Type [] { typeof (object), typeof (object) };
+ MethodInfo mi_non_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_non_params, "#A1");
+ Assert.AreEqual (2, mi_non_params.GetParameters ().Length, "#A2");
+ Assert.AreEqual (typeof (object), mi_non_params.GetParameters () [0].ParameterType, "#A3");
+ Assert.AreEqual (typeof (object), mi_non_params.GetParameters () [1].ParameterType, "#A4");
+ types = new Type [] { typeof (object), typeof (object []) };
+ MethodInfo mi_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_params, "#B1");
+ Assert.AreEqual (2, mi_params.GetParameters ().Length, "#B2");
+ Assert.AreEqual (typeof (object), mi_params.GetParameters () [0].ParameterType, "#B3");
+ Assert.AreEqual (typeof (object []), mi_params.GetParameters () [1].ParameterType, "#B4");
+ types = new Type [] { typeof (object) };
+ MethodInfo mi_single_param = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_single_param, "#C1");
+ Assert.AreEqual (1, mi_single_param.GetParameters ().Length, "#C2");
+ Assert.AreEqual (typeof (object), mi_single_param.GetParameters () [0].ParameterType, "#C3");
+
+ match = new MethodBase [] { mi_params };
+ types = new Type [] { typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#D1");
+ types = new Type [] { typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#D2");
+ types = new Type [] { typeof (object), typeof (object []) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_params, selected, "#D3");
+ types = new Type [] { typeof (object), typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#D4");
+
+ match = new MethodBase [] { mi_non_params };
+ types = new Type [] { typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#E1");
+ types = new Type [] { typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_non_params, selected, "#E2");
+ types = new Type [] { typeof (object), typeof (object []) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_non_params, selected, "#E3");
+ types = new Type [] { typeof (object), typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#E4");
+
+ match = new MethodBase [] { mi_non_params, mi_params };
+ types = new Type [] { typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#F1");
+ match = new MethodBase [] { mi_non_params, mi_params };
+ types = new Type [] { typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_non_params, selected, "#F2");
+ match = new MethodBase [] { mi_non_params, mi_params };
+ types = new Type [] { typeof (object), typeof (object []) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_params, selected, "#F3");
+ match = new MethodBase [] { mi_non_params, mi_params };
+ types = new Type [] { typeof (object), typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#F4");
+
+ match = new MethodBase [] { mi_params, mi_non_params };
+ types = new Type [] { typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#G1");
+ match = new MethodBase [] { mi_params, mi_non_params };
+ types = new Type [] { typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_non_params, selected, "#G2");
+ match = new MethodBase [] { mi_params, mi_non_params };
+ types = new Type [] { typeof (object), typeof (object []) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_params, selected, "#G3");
+ match = new MethodBase [] { mi_params, mi_non_params };
+ types = new Type [] { typeof (object), typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#G4");
+
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ types = new Type [] { typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_single_param, selected, "#H1");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ types = new Type [] { typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_non_params, selected, "#H2");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ types = new Type [] { typeof (object), typeof (object []) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_params, selected, "#H3");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ types = new Type [] { typeof (object), typeof (object), typeof (object) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#H4");
+
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ types = new Type [] { typeof (string) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_single_param, selected, "#I1");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ types = new Type [] { typeof (string), typeof (string) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_non_params, selected, "#I2");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ types = new Type [] { typeof (string), typeof (string []) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.AreSame (mi_params, selected, "#I3");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ types = new Type [] { typeof (string), typeof (string), typeof (long) };
+ selected = binder.SelectMethod (flags, match, types, null);
+ Assert.IsNull (selected, "#I4");
+ }
+
+ [Test] // bug #314809
+ public void ArgNullOnMethod ()
{
Type type = typeof (SampleClass);
BindingFlags flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod;
Assert.IsNotNull (prop);
}
-#if NET_2_0
[Test]
public void BindToMethod_ByRef ()
{
MethodInfo mi_run = type.GetMethod ("Run", flags, binder,
new Type [] { typeof (int) }, null);
Assert.IsFalse (mi_run.GetParameters () [0].ParameterType.IsByRef, "#A1");
+#if NET_2_0
MethodInfo mi_run_ref = type.GetMethod ("Run", flags, binder,
new Type [] { typeof (int).MakeByRefType () }, null);
+#else
+ MethodInfo mi_run_ref = type.GetMethod ("RunV1", flags);
+#endif
Assert.IsTrue (mi_run_ref.GetParameters () [0].ParameterType.IsByRef, "#A2");
match = new MethodBase [] { mi_run };
selected = binder.BindToMethod (flags, match, ref args, null, culture,
null, out state);
- Assert.AreSame (mi_run, selected, "#1");
+ Assert.AreSame (mi_run, selected, "#B1");
match = new MethodBase [] { mi_run_ref };
selected = binder.BindToMethod (flags, match, ref args, null, culture,
null, out state);
- Assert.AreSame (mi_run_ref, selected, "#2");
+ Assert.AreSame (mi_run_ref, selected, "#B2");
match = new MethodBase [] { mi_run, mi_run_ref };
selected = binder.BindToMethod (flags, match, ref args, null, culture,
null, out state);
- Assert.AreSame (mi_run, selected, "#3");
+ Assert.AreSame (mi_run, selected, "#B3");
match = new MethodBase [] { mi_run_ref, mi_run };
selected = binder.BindToMethod (flags, match, ref args, null, culture,
null, out state);
- Assert.AreSame (mi_run, selected, "#4");
+ Assert.AreSame (mi_run, selected, "#B4");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void BindToMethod_AmbiguousMatch ()
+ {
+ Type type = typeof (BinderTest);
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
+ MethodBase [] match;
+ Type [] types;
+ object state;
+ object [] args;
+ CultureInfo culture = CultureInfo.InvariantCulture;
+
+ types = new Type [] { typeof (object), typeof (object []) };
+ MethodInfo mi_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_params, "#A1");
+ Assert.AreEqual (2, mi_params.GetParameters ().Length, "#A2");
+ Assert.AreEqual (typeof (object), mi_params.GetParameters () [0].ParameterType, "#B3");
+ Assert.AreEqual (typeof (object []), mi_params.GetParameters () [1].ParameterType, "#B4");
+ types = new Type [] { typeof (object) };
+ MethodInfo mi_single_param = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_single_param, "#B1");
+ Assert.AreEqual (1, mi_single_param.GetParameters ().Length, "#B2");
+ Assert.AreEqual (typeof (object), mi_single_param.GetParameters () [0].ParameterType, "#B3");
+
+ match = new MethodBase [] { mi_single_param, mi_single_param };
+ args = new object [] { new object () };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#C1");
+ } catch (AmbiguousMatchException) {
+ // Ambiguous match found
+ }
+
+ match = new MethodBase [] { mi_single_param, mi_single_param };
+ args = new object [] { string.Empty };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#D1");
+ } catch (AmbiguousMatchException) {
+ // Ambiguous match found
+ }
+
+ match = new MethodBase [] { mi_params, mi_params };
+ args = new object [] { new object (), new object () };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#E1");
+ } catch (AmbiguousMatchException) {
+ // Ambiguous match found
+ }
+
+ match = new MethodBase [] { mi_params, mi_params };
+ args = new object [] { string.Empty, 0L };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#F1");
+ } catch (AmbiguousMatchException) {
+ // Ambiguous match found
+ }
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void BindToMethod_Params ()
+ {
+ Type type = typeof (BinderTest);
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
+ MethodBase [] match;
+ Type [] types;
+ MethodBase selected;
+ object state;
+ object [] args;
+ CultureInfo culture = CultureInfo.InvariantCulture;
+
+ types = new Type [] { typeof (object), typeof (object) };
+ MethodInfo mi_non_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_non_params, "#A1");
+ Assert.AreEqual (2, mi_non_params.GetParameters ().Length, "#A2");
+ Assert.AreEqual (typeof (object), mi_non_params.GetParameters () [0].ParameterType, "#A3");
+ Assert.AreEqual (typeof (object), mi_non_params.GetParameters () [1].ParameterType, "#A4");
+ types = new Type [] { typeof (object), typeof (object []) };
+ MethodInfo mi_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_params, "#B1");
+ Assert.AreEqual (2, mi_params.GetParameters ().Length, "#B2");
+ Assert.AreEqual (typeof (object), mi_params.GetParameters () [0].ParameterType, "#B3");
+ Assert.AreEqual (typeof (object []), mi_params.GetParameters () [1].ParameterType, "#B4");
+ types = new Type [] { typeof (object) };
+ MethodInfo mi_single_param = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_single_param, "#C1");
+ Assert.AreEqual (1, mi_single_param.GetParameters ().Length, "#C2");
+ Assert.AreEqual (typeof (object), mi_single_param.GetParameters () [0].ParameterType, "#C3");
+
+ match = new MethodBase [] { mi_params };
+ args = new object [] { new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#D1");
+ args = new object [] { new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#D2");
+ args = new object [] { new object (), new object [0] };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#D3");
+ args = new object [] { new object (), new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#D4");
+
+ match = new MethodBase [] { mi_non_params };
+ args = new object [] { new object () };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#E1");
+ } catch (MissingMethodException) {
+ // Member not found
+ }
+ args = new object [] { new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_non_params, selected, "#E2");
+ args = new object [] { new object (), new object [0] };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_non_params, selected, "#E3");
+ args = new object [] { new object (), new object (), new object () };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#E4");
+ } catch (MissingMethodException) {
+ // Member not found
+ }
+
+ match = new MethodBase [] { mi_non_params, mi_params };
+ args = new object [] { new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#F1");
+ match = new MethodBase [] { mi_non_params, mi_params };
+ args = new object [] { new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_non_params, selected, "#F2");
+ match = new MethodBase [] { mi_non_params, mi_params };
+ args = new object [] { new object (), new object [0] };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#F3");
+ match = new MethodBase [] { mi_non_params, mi_params };
+ args = new object [] { new object (), new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#F4");
+
+ match = new MethodBase [] { mi_params, mi_non_params };
+ args = new object [] { new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#G1");
+ match = new MethodBase [] { mi_params, mi_non_params };
+ args = new object [] { new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_non_params, selected, "#G2");
+ match = new MethodBase [] { mi_params, mi_non_params };
+ args = new object [] { new object (), new object [0] };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#G3");
+ match = new MethodBase [] { mi_params, mi_non_params };
+ args = new object [] { new object (), new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#G4");
+
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_single_param, selected, "#H1");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_non_params, selected, "#H2");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { new object (), new object [0] };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#H3");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { new object (), new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#H4");
+
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { string.Empty };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_single_param, selected, "#I1");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { string.Empty, string.Empty };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_non_params, selected, "#I2");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { string.Empty, new string [0] };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#I3");
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { string.Empty, string.Empty, 5L };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#I4");
+ }
+
+ [Test]
+ [Category ("NotDotNet")]
+ [Category ("NotWorking")]
+ public void BindToMethod_Params_Mono ()
+ {
+ Type type = typeof (BinderTest);
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
+ MethodBase [] match;
+ Type [] types;
+ MethodBase selected;
+ object state;
+ object [] args;
+ CultureInfo culture = CultureInfo.InvariantCulture;
+
+ types = new Type [] { typeof (object), typeof (object) };
+ MethodInfo mi_non_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_non_params, "#A1");
+ Assert.AreEqual (2, mi_non_params.GetParameters ().Length, "#A2");
+ Assert.AreEqual (typeof (object), mi_non_params.GetParameters () [0].ParameterType, "#A3");
+ Assert.AreEqual (typeof (object), mi_non_params.GetParameters () [1].ParameterType, "#A4");
+ types = new Type [] { typeof (object), typeof (object []) };
+ MethodInfo mi_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_params, "#B1");
+ Assert.AreEqual (2, mi_params.GetParameters ().Length, "#B2");
+ Assert.AreEqual (typeof (object), mi_params.GetParameters () [0].ParameterType, "#B3");
+ Assert.AreEqual (typeof (object []), mi_params.GetParameters () [1].ParameterType, "#B4");
+ types = new Type [] { typeof (object) };
+ MethodInfo mi_single_param = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_single_param, "#C1");
+ Assert.AreEqual (1, mi_single_param.GetParameters ().Length, "#C2");
+ Assert.AreEqual (typeof (object), mi_single_param.GetParameters () [0].ParameterType, "#C3");
+
+ match = new MethodBase [] { mi_non_params, mi_params };
+ args = new object [] { new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#D1");
+ args = new object [] { new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_non_params, selected, "#D2");
+ args = new object [] { new object (), new object [0] };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#D3");
+ args = new object [] { new object (), new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#D4");
+
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_single_param, selected, "#E1");
+ args = new object [] { new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_non_params, selected, "#E2");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void BindToMethod_Params_MS ()
+ {
+ Type type = typeof (BinderTest);
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
+ MethodBase [] match;
+ Type [] types;
+ MethodBase selected;
+ object state;
+ object [] args;
+ CultureInfo culture = CultureInfo.InvariantCulture;
+
+ types = new Type [] { typeof (object), typeof (object) };
+ MethodInfo mi_non_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_non_params, "#A1");
+ Assert.AreEqual (2, mi_non_params.GetParameters ().Length, "#A2");
+ Assert.AreEqual (typeof (object), mi_non_params.GetParameters () [0].ParameterType, "#A3");
+ Assert.AreEqual (typeof (object), mi_non_params.GetParameters () [1].ParameterType, "#A4");
+ types = new Type [] { typeof (object), typeof (object []) };
+ MethodInfo mi_params = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_params, "#B1");
+ Assert.AreEqual (2, mi_params.GetParameters ().Length, "#B2");
+ Assert.AreEqual (typeof (object), mi_params.GetParameters () [0].ParameterType, "#B3");
+ Assert.AreEqual (typeof (object []), mi_params.GetParameters () [1].ParameterType, "#B4");
+ types = new Type [] { typeof (object) };
+ MethodInfo mi_single_param = type.GetMethod ("params_method1", flags, binder, types, null);
+ Assert.IsNotNull (mi_single_param, "#C1");
+ Assert.AreEqual (1, mi_single_param.GetParameters ().Length, "#C2");
+ Assert.AreEqual (typeof (object), mi_single_param.GetParameters () [0].ParameterType, "#C3");
+
+ match = new MethodBase [] { mi_non_params, mi_params };
+ args = new object [] { new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#D1");
+ args = new object [] { new object (), new object () };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#D2");
+ } catch (AmbiguousMatchException) {
+ }
+ args = new object [] { new object (), new object [0] };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#D3");
+ } catch (AmbiguousMatchException) {
+ }
+ args = new object [] { new object (), new object (), new object () };
+ try {
+ binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.Fail ("#D4");
+ } catch (IndexOutOfRangeException) {
+ }
+
+ match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
+ args = new object [] { new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_single_param, selected, "#E1");
+ args = new object [] { new object (), new object () };
+ selected = binder.BindToMethod (flags, match, ref args, null, culture,
+ null, out state);
+ Assert.AreSame (mi_params, selected, "#E2");
}
-#endif
[Test] // bug #41691
public void BindToMethodNamedArgs ()
[Test]
public void TestParamsAttribute ()
{
- MethodInfo mi = typeof (BinderTest).GetMethod ("params_method1", BindingFlags.Static|BindingFlags.Public, null, new Type [] { typeof (object), typeof (object) }, null);
- Assert.AreEqual (typeof (object), mi.GetParameters ()[1].ParameterType);
+ MethodInfo mi;
+
+ mi = typeof (BinderTest).GetMethod ("params_method1", BindingFlags.Static | BindingFlags.Public, null, new Type [] { typeof (object), typeof (object) }, null);
+ Assert.IsNotNull (mi, "#A1");
+ Assert.AreEqual (typeof (object), mi.GetParameters () [1].ParameterType, "#A2");
+
+ mi = typeof (BinderTest).GetMethod ("params_method1", BindingFlags.Static | BindingFlags.Public, null, new Type [] { typeof (object), typeof (object []) }, null);
+ Assert.IsNotNull (mi, "#B1");
+ Assert.AreEqual (typeof (object []), mi.GetParameters () [1].ParameterType, "#B2");
+ }
+
+ [Test]
+ [Category ("NotDotNet")]
+ public void TestParamsAttribute2_Mono ()
+ {
+ MethodInfo mi = typeof (BinderTest).GetMethod ("params_method1", BindingFlags.Static|BindingFlags.Public, null, new Type [] { typeof (object), typeof (object), typeof (object) }, null);
+ Assert.IsNotNull (mi, "#1");
+ Assert.AreEqual (typeof (object []), mi.GetParameters () [1].ParameterType, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestParamsAttribute2_MS ()
+ {
+ MethodInfo mi = typeof (BinderTest).GetMethod ("params_method1", BindingFlags.Static | BindingFlags.Public, null, new Type [] { typeof (object), typeof (object), typeof (object) }, null);
+ Assert.IsNull (mi, "#1");
+ }
- MethodInfo mi2 = typeof (BinderTest).GetMethod ("params_method1", BindingFlags.Static|BindingFlags.Public, null, new Type [] { typeof (object), typeof (object), typeof (object) }, null);
- Assert.AreEqual (typeof (object[]), mi2.GetParameters ()[1].ParameterType);
+ public static void params_method1 (object o)
+ {
}
- public static void params_method1 (object o, params object[] o2) {
+ public static void params_method1 (object o, params object[] o2)
+ {
}
- public static void params_method1 (object o, object o2) {
+ public static void params_method1 (object o, object o2)
+ {
}
public static double DoubleMethod (double d) {
public void TestExactBinding ()
{
Type[] types = new Type[] { typeof(int) };
- Assert.AreEqual (null, typeof (BinderTest).GetMethod("MethodWithLongParam", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.ExactBinding, null, types, null));
+ BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.ExactBinding;
+ Assert.IsNull (typeof (BinderTest).GetMethod("MethodWithLongParam",
+ flags, null, types, null));
}
public void Bug42457Method (object thing)
typeof(Bug324998BBad).GetMethod("f", BUG324998_BINDING_FLAGS);
}
- void Bug380361 (MyEnum e) { }
+ void Bug380361 (MyEnum e) { }
- [Test]
- public void TestEnumConversion ()
- {
- Type type = this.GetType ();
- MethodInfo mi = type.GetMethod ("Bug380361", BindingFlags.NonPublic | BindingFlags.Instance, binder, new Type [] { typeof (MyEnum) }, null);
- mi.Invoke (this, new object [] { (int)MyEnum.Zero });
- }
+ [Test]
+ public void TestEnumConversion ()
+ {
+ Type type = this.GetType ();
+ MethodInfo mi = type.GetMethod ("Bug380361", BindingFlags.NonPublic | BindingFlags.Instance, binder, new Type [] { typeof (MyEnum) }, null);
+ mi.Invoke (this, new object [] { (int)MyEnum.Zero });
+ }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void TestEnumConversion2 ()
- {
- Type type = this.GetType ();
- MethodInfo mi = type.GetMethod ("Bug380361", BindingFlags.NonPublic | BindingFlags.Instance, binder, new Type [] { typeof (MyEnum) }, null);
- mi.Invoke (this, new object [] { (long)MyEnum.Zero });
- }
+ [Test]
+ public void TestEnumConversion2 ()
+ {
+ Type type = this.GetType ();
+ MethodInfo mi = type.GetMethod ("Bug380361", BindingFlags.NonPublic | BindingFlags.Instance, binder, new Type [] { typeof (MyEnum) }, null);
+ try {
+ mi.Invoke (this, new object [] { (long) MyEnum.Zero });
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName, "#5");
+ }
+ }
class AssertingBinder : Binder {
{
}
+#if NET_2_0
public void Run (out int i)
+#else
+ public void RunV1 (out int i)
+#endif
{
i = 0;
}
+2009-07-14 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * BinderTests.cs: Modified SelectMethod_ByRef and BindToMethod_ByRef
+ to compile on net_1_1 profile. Added tests for SelectMethod and
+ BindToMethod with params arguments, currently marked NotWorking.
+
2009-07-14 Raja R Harinath <harinath@hurrynot.org>
* BinderTests.cs (SelectMethod_ByRef, BindToMethod_ByRef): Disable
+2009-07-20 Geoff Norton <gnorton@novell.com>
+
+ * thread-private.h: Use the new mono-semaphore.h.
+
2009-06-25 Gonzalo Paniagua Javier <gonzalo@novell.com>
* sockets.c: add the error number to the message so we can figure out
#include <config.h>
#include <glib.h>
#include <pthread.h>
-#ifdef HAVE_SEMAPHORE_H
-#include <semaphore.h>
-#endif
-
-#ifdef USE_MACH_SEMA
-# include <mach/mach_init.h>
-# include <mach/task.h>
-# include <mach/semaphore.h>
-
-typedef semaphore_t MonoSemType;
-# define MONO_SEM_INIT(addr,value) semaphore_create (current_task (), (addr), SYNC_POLICY_FIFO, (value))
-# define MONO_SEM_WAIT(sem) semaphore_wait (*(sem))
-# define MONO_SEM_POST(sem) semaphore_signal (*(sem))
-# define MONO_SEM_DESTROY(sem) semaphore_destroy (current_task (), *(sem))
-#else
-
-typedef sem_t MonoSemType;
-# define MONO_SEM_INIT(addr,value) sem_init ((addr), 0, (value))
-# define MONO_SEM_WAIT(sem) sem_wait ((sem))
-# define MONO_SEM_POST(sem) sem_post ((sem))
-# define MONO_SEM_DESTROY(sem) sem_destroy ((sem))
-#endif
+#include <mono/utils/mono-semaphore.h>
/* There doesn't seem to be a defined symbol for this */
#define _WAPI_THREAD_CURRENT (gpointer)0xFFFFFFFE
+2009-07-20 Geoff Norton <gnorton@novell.com>
+
+ * gc.c: Use proper semaphores where available on posix and darwin.
+
+2009-07-19 Geoff Norton <gnorton@novell.com>
+
+ * gc.c: Unnamed posix semaphores are broken on darwin-arm too.
+
+2009-07-19 Rodrigo Kumpera <rkumpera@novell.com>
+
+ * refletion.c (is_sre_usertype): Change name to is_usertype and
+ invert it's result so it returns true if the type is an user type
+ and not the opposite.
+
+ * reflection.c (is_*_type): Change all of those to use new macro
+ check_corlib_type_cached that cached the type lookup so we don't
+ need to do string comparisons all the type. Changed the signature
+ to take a MonoClass instead.
+
+ * reflection.c: Change mono_image_create_token and resolve_object
+ to use is_sre_* functions.
+
2009-07-18 Mark Probst <mark.probst@gmail.com>
* sgen-gc.c: Check for writes to the stack in the managed
#include <mono/metadata/gc-internal.h>
#include <mono/metadata/marshal.h> /* for mono_delegate_free_ftnptr () */
#include <mono/metadata/attach.h>
-#if HAVE_SEMAPHORE_H
-#include <semaphore.h>
-/* we do this only for known working systems (OSX for example
- * has the header and functions, but they don't work at all): in other cases
- * we fall back to the io-layer slightly slower and signal-unsafe Event.
- */
-#if defined (__linux__) || (defined(__APPLE__) && defined(__arm__))
-#define USE_POSIX_SEM 1
-#endif
-#endif
+#include <mono/utils/mono-semaphore.h>
#ifndef PLATFORM_WIN32
#include <pthread.h>
#ifndef HAVE_NULL_GC
-#if USE_POSIX_SEM
-static sem_t finalizer_sem;
+#ifdef MONO_HAS_SEMAPHORES
+static MonoSemType finalizer_sem;
#endif
static HANDLE finalizer_event;
static volatile gboolean finished=FALSE;
g_message (G_GNUC_PRETTY_FUNCTION ": prodding finalizer");
#endif
-#if USE_POSIX_SEM
- sem_post (&finalizer_sem);
+#ifdef MONO_HAS_SEMAPHORES
+ MONO_SEM_POST (&finalizer_sem);
#else
SetEvent (finalizer_event);
#endif
/* Wait to be notified that there's at least one
* finaliser to run
*/
-#if USE_POSIX_SEM
- sem_wait (&finalizer_sem);
+#ifdef MONO_HAS_SEMAPHORES
+ MONO_SEM_WAIT (&finalizer_sem);
#else
/* Use alertable=FALSE since we will be asked to exit using the event too */
WaitForSingleObjectEx (finalizer_event, INFINITE, FALSE);
if (finalizer_event == NULL || pending_done_event == NULL || shutdown_event == NULL) {
g_assert_not_reached ();
}
-#if USE_POSIX_SEM
- sem_init (&finalizer_sem, 0, 0);
+#ifdef MONO_HAS_SEMAPHORES
+ MONO_SEM_INIT (&finalizer_sem, 0);
#endif
gc_thread = mono_thread_create_internal (mono_domain_get (), finalizer_thread, NULL, FALSE);
static MonoReflectionType *mono_reflection_type_get_underlying_system_type (MonoReflectionType* t);
static MonoType* mono_reflection_get_type_with_rootimage (MonoImage *rootimage, MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase, gboolean *type_resolve);
static MonoReflectionType* mono_reflection_type_resolve_user_types (MonoReflectionType *type);
+static gboolean is_sre_array (MonoClass *class);
+static gboolean is_sre_byref (MonoClass *class);
+static gboolean is_sre_pointer (MonoClass *class);
#define RESOLVE_TYPE(type) do { type = (void*)mono_reflection_type_resolve_user_types ((MonoReflectionType*)type); } while (0)
#define RESOLVE_ARRAY_TYPE_ELEMENT(array, index) do { \
} else if (strcmp (klass->name, "MethodOnTypeBuilderInst") == 0) {
MonoReflectionMethodOnTypeBuilderInst *m = (MonoReflectionMethodOnTypeBuilderInst*)obj;
token = mono_image_get_method_on_inst_token (assembly, m, create_methodspec);
- } else if (strcmp (klass->name, "ArrayType") == 0 ||
- strcmp (klass->name, "ByRefType") == 0||
- strcmp (klass->name, "PointerType") == 0) {
+ } else if (is_sre_array (klass) || is_sre_byref (klass) || is_sre_pointer (klass)) {
MonoReflectionType *type = (MonoReflectionType *)obj;
token = mono_metadata_token_from_dor (
mono_image_typedef_or_ref (assembly, mono_reflection_type_get_handle (type)));
#ifndef DISABLE_REFLECTION_EMIT
static gboolean
-is_corlib_type (MonoReflectionType *ref)
+is_corlib_type (MonoClass *class)
{
- return ref && mono_object_class (ref)->image == mono_defaults.corlib;
+ return class->image == mono_defaults.corlib;
}
static gboolean
-is_sre_usertype (MonoReflectionType *ref)
+is_usertype (MonoReflectionType *ref)
{
MonoClass *class = mono_object_class (ref);
- return ref && class->image == mono_defaults.corlib && strcmp ("TypeDelegator", class->name);
+ return class->image != mono_defaults.corlib || strcmp ("TypeDelegator", class->name) == 0;
}
+#define check_corlib_type_cached(_class, _namespace, _name) do { \
+ static MonoClass *cached_class; \
+ if (cached_class) \
+ return cached_class == _class; \
+ if (is_corlib_type (_class) && !strcmp (_name, _class->name) && !strcmp (_namespace, _class->name_space)) { \
+ cached_class = _class; \
+ return TRUE; \
+ } \
+ return FALSE; \
+} while (0) \
+
static gboolean
-is_sre_array (MonoReflectionType *ref)
+is_sre_array (MonoClass *class)
{
- return ref && is_corlib_type (ref) &&
- !strcmp ("ArrayType", mono_object_class (ref)->name) &&
- !strcmp ("System.Reflection.Emit", mono_object_class (ref)->name_space);
+ check_corlib_type_cached (class, "System.Reflection.Emit", "ArrayType");
}
static gboolean
-is_sre_byref (MonoReflectionType *ref)
+is_sre_byref (MonoClass *class)
{
- return ref && is_corlib_type (ref) &&
- !strcmp ("ByRefType", mono_object_class (ref)->name) &&
- !strcmp ("System.Reflection.Emit", mono_object_class (ref)->name_space);
+ check_corlib_type_cached (class, "System.Reflection.Emit", "ByRefType");
}
static gboolean
-is_sre_pointer (MonoReflectionType *ref)
+is_sre_pointer (MonoClass *class)
{
- return ref && is_corlib_type (ref) &&
- !strcmp ("PointerType", mono_object_class (ref)->name) &&
- !strcmp ("System.Reflection.Emit", mono_object_class (ref)->name_space);
+ check_corlib_type_cached (class, "System.Reflection.Emit", "PointerType");
}
MonoType*
mono_reflection_type_get_handle (MonoReflectionType* ref)
{
+ MonoClass *class;
if (!ref)
return NULL;
if (ref->type)
return ref->type;
- if (!is_sre_usertype (ref))
+ if (is_usertype (ref)) {
ref = mono_reflection_type_get_underlying_system_type (ref);
+ g_assert (!is_usertype (ref)); /*FIXME fail better*/
+ if (ref->type)
+ return ref->type;
+ }
+
+ class = mono_object_class (ref);
- if (is_sre_array (ref)) {
+ if (is_sre_array (class)) {
MonoType *res;
MonoReflectionArrayType *sre_array = (MonoReflectionArrayType*)ref;
MonoType *base = mono_reflection_type_get_handle (sre_array->element_type);
res = &mono_array_class_get (mono_class_from_mono_type (base), sre_array->rank)->byval_arg;
sre_array->type.type = res;
return res;
- } else if (is_sre_byref (ref)) {
+ } else if (is_sre_byref (class)) {
MonoType *res;
MonoReflectionDerivedType *sre_byref = (MonoReflectionDerivedType*)ref;
MonoType *base = mono_reflection_type_get_handle (sre_byref->element_type);
res = &mono_class_from_mono_type (base)->this_arg;
sre_byref->type.type = res;
return res;
- } else if (is_sre_pointer (ref)) {
+ } else if (is_sre_pointer (class)) {
MonoType *res;
MonoReflectionDerivedType *sre_pointer = (MonoReflectionDerivedType*)ref;
MonoType *base = mono_reflection_type_get_handle (sre_pointer->element_type);
if (!type || type->type)
return type;
- if (!is_sre_usertype (type)) {
+ if (is_usertype (type)) {
type = mono_reflection_type_get_underlying_system_type (type);
- if (!is_sre_usertype (type))
+ if (is_usertype (type))
mono_raise_exception (mono_get_exception_not_supported ("User defined subclasses of System.Type are not yet supported22"));
}
result = inflate_mono_method (inflated_klass, m->mb->mhandle, (MonoObject*)m->mb);
*handle_class = mono_defaults.methodhandle_class;
mono_metadata_free_type (type);
- } else if (strcmp (mono_object_get_class(obj)->name, "ArrayType") == 0 ||
- strcmp (mono_object_get_class(obj)->name, "ByRefType") == 0 ||
- strcmp (mono_object_get_class(obj)->name, "PointerType") == 0) {
+ } else if (is_sre_array (mono_object_get_class(obj)) ||
+ is_sre_byref (mono_object_get_class(obj)) ||
+ is_sre_pointer (mono_object_get_class(obj))) {
MonoReflectionType *ref_type = (MonoReflectionType *)obj;
MonoType *type = mono_reflection_type_get_handle (ref_type);
result = mono_class_from_mono_type (type);
+2009-07-20 Geoff Norton <gnorton@novell.com>
+
+ * mini-x86.c: Fix --trace on darwin-x86 and other systems which require
+ aligned access.
+
+2009-07-20 Zoltan Varga <vargaz@gmail.com>
+
+ * mini.c (mono_jit_runtime_invoke): Speed this up by adding a hash to
+ MonoJitDomainInfo which maps MonoMethod's to a structure containing all
+ the information which is needed for invokes, so only one locking+hash table
+ lookup is needed.
+
+ * aot-compiler.c: Add a 'tool-prefix' option to be used when cross-compiling.
+
+ * aot-compiler.c (add_generic_instances): Emit instances of
+ GenericComparer<T> for primitive types.
+
+2009-07-19 Rodrigo Kumpera <rkumpera@novell.com>
+
+ * mini-posix.c: Fix linux build.
+
+2009-07-19 Geoff Norton <gnorton@novell.com>
+
+ * mini.h: Add prototypes for mono_runtime_syscall_fork and
+ mono_gdb_render_native_backtraces
+ * mini-darwin.c: Apple's syscall(SYS_fork) is very weird on x86,
+ so we implement the sane semantics to the runtime here
+ (mono_gdb_render_native_backtraces). Apple also uses an ancient gdb
+ so we need to call it differently (mono_gdb_render_native_backtraces)
+ * mini-posix.c: Move the old semantics from mini.c to the prototypes
+ here for default implementations.
+ * mini.c: Refactor mono_handle_native_sigsegv so that we can properly
+ support Apple's weird syscall (SYS_fork) implementation and not busy
+ loop in abort() on native crashes on OSX anymore.
+
2009-07-18 Zoltan Varga <vargaz@gmail.com>
* aot-runtime.c (load_method): Change the handling of the
int nthreads;
int ntrampolines;
gboolean print_skipped_methods;
+ char *tool_prefix;
} MonoAotOptions;
typedef struct MonoAotStats {
add_generic_class (acfg, mono_class_from_mono_type (header->locals [j]));
}
}
+
+ if (acfg->image == mono_defaults.corlib) {
+ /* Add GenericComparer<T> instances for primitive types for Enum.ToString () */
+ MonoClass *klass = mono_class_from_name (acfg->image, "System.Collections.Generic", "GenericComparer`1");
+
+ if (klass) {
+ MonoGenericContext ctx;
+ MonoType *args [16];
+
+ memset (&ctx, 0, sizeof (ctx));
+
+ args [0] = &mono_defaults.byte_class->byval_arg;
+ ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+ add_generic_class (acfg, mono_class_inflate_generic_class (klass, &ctx));
+
+ args [0] = &mono_defaults.sbyte_class->byval_arg;
+ ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+ add_generic_class (acfg, mono_class_inflate_generic_class (klass, &ctx));
+
+ args [0] = &mono_defaults.int16_class->byval_arg;
+ ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+ add_generic_class (acfg, mono_class_inflate_generic_class (klass, &ctx));
+
+ args [0] = &mono_defaults.uint16_class->byval_arg;
+ ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+ add_generic_class (acfg, mono_class_inflate_generic_class (klass, &ctx));
+
+ args [0] = &mono_defaults.int32_class->byval_arg;
+ ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+ add_generic_class (acfg, mono_class_inflate_generic_class (klass, &ctx));
+
+ args [0] = &mono_defaults.uint32_class->byval_arg;
+ ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+ add_generic_class (acfg, mono_class_inflate_generic_class (klass, &ctx));
+
+ args [0] = &mono_defaults.int64_class->byval_arg;
+ ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+ add_generic_class (acfg, mono_class_inflate_generic_class (klass, &ctx));
+
+ args [0] = &mono_defaults.uint64_class->byval_arg;
+ ctx.class_inst = mono_metadata_get_generic_inst (1, args);
+ add_generic_class (acfg, mono_class_inflate_generic_class (klass, &ctx));
+ }
+ }
}
/*
opts->nodebug = TRUE;
} else if (str_begins_with (arg, "ntrampolines=")) {
opts->ntrampolines = atoi (arg + strlen ("ntrampolines="));
+ } else if (str_begins_with (arg, "tool-prefix=")) {
+ opts->tool_prefix = g_strdup (arg + strlen ("tool-prefix="));
} else {
fprintf (stderr, "AOT : Unknown argument '%s'.\n", arg);
exit (1);
{
char *command, *objfile;
char *outfile_name, *tmp_outfile_name;
+ const char *tool_prefix = acfg->aot_opts.tool_prefix ? acfg->aot_opts.tool_prefix : "";
#if defined(TARGET_AMD64)
#define AS_OPTIONS "--64"
} else {
objfile = g_strdup_printf ("%s.o", acfg->tmpfname);
}
- command = g_strdup_printf ("as %s %s -o %s", AS_OPTIONS, acfg->tmpfname, objfile);
+ command = g_strdup_printf ("%sas %s %s -o %s", tool_prefix, AS_OPTIONS, acfg->tmpfname, objfile);
printf ("Executing the native assembler: %s\n", command);
if (system (command) != 0) {
g_free (command);
#elif defined(PLATFORM_WIN32)
command = g_strdup_printf ("gcc -shared --dll -mno-cygwin -o %s %s.o", tmp_outfile_name, acfg->tmpfname);
#else
- command = g_strdup_printf ("ld %s -shared -o %s %s.o", LD_OPTIONS, tmp_outfile_name, acfg->tmpfname);
+ command = g_strdup_printf ("%sld %s -shared -o %s %s.o", tool_prefix, LD_OPTIONS, tmp_outfile_name, acfg->tmpfname);
#endif
printf ("Executing the native linker: %s\n", command);
if (system (command) != 0) {
* gas generates 'mapping symbols' each time code and data is mixed, which
* happens a lot in emit_and_reloc_code (), so we need to get rid of them.
*/
- command = g_strdup_printf ("strip --strip-symbol=\\$a --strip-symbol=\\$d %s", tmp_outfile_name);
+ command = g_strdup_printf ("%sstrip --strip-symbol=\\$a --strip-symbol=\\$d %s", tool_prefix, tmp_outfile_name);
printf ("Stripping the binary: %s\n", command);
if (system (command) != 0) {
g_free (tmp_outfile_name);
macosx_register_exception_handler ();
mono_runtime_posix_install_handlers ();
}
+
+pid_t
+mono_runtime_syscall_fork ()
+{
+#if defined(__i386__)
+ /* Apple's fork syscall returns a regpair in EAX:EDX.
+ * EAX == pid of caller always
+ * EDX == 0 for parent, 1 for child
+ */
+ register_t eax;
+ register_t edx;
+ pid_t pid;
+
+ __asm__ __volatile__ (
+ "mov $0x2, %%eax;"
+ "int $0x80;"
+ "mov %%eax, %0;"
+ "mov %%edx, %1;"
+ : "=m" (eax), "=m" (edx));
+
+ if (edx == 0) {
+ pid = eax;
+ } else if (edx == 1) {
+ pid = 0;
+ } else {
+ g_assert_not_reached ();
+ }
+
+ return pid;
+#else
+ g_assert_not_reached ();
+#endif
+}
+
+gboolean
+mono_gdb_render_native_backtraces ()
+{
+ const char *argv [5];
+ char gdb_template [] = "/tmp/mono-gdb-commands.XXXXXX";
+
+ argv [0] = g_find_program_in_path ("gdb");
+ if (argv [0] == NULL) {
+ return FALSE;
+ }
+
+ if (mkstemp (gdb_template) != -1) {
+ FILE *gdb_commands = fopen (gdb_template, "w");
+
+ fprintf (gdb_commands, "attach %ld\n", (long) getpid ());
+ fprintf (gdb_commands, "info threads\n");
+ fprintf (gdb_commands, "thread apply all bt\n");
+
+ fflush (gdb_commands);
+ fclose (gdb_commands);
+
+ argv [1] = "-batch";
+ argv [2] = "-x";
+ argv [3] = gdb_template;
+ argv [4] = 0;
+
+ execv (argv [0], (char**)argv);
+
+ unlink (gdb_template);
+ }
+
+ return TRUE;
+}
int res;
int stdout_pipe [2] = { -1, -1 };
pid_t pid;
- const char *argv [16];
- char buf1 [128];
int status;
char buffer [1024];
* glibc fork acquires some locks, so if the crash happened inside malloc/free,
* it will deadlock. Call the syscall directly instead.
*/
- pid = syscall (SYS_fork);
+ pid = mono_runtime_syscall_fork ();
+
if (pid == 0) {
close (stdout_pipe [0]);
dup2 (stdout_pipe [1], STDOUT_FILENO);
for (i = getdtablesize () - 1; i >= 3; i--)
close (i);
- argv [0] = g_find_program_in_path ("gdb");
- if (argv [0] == NULL) {
+ if (!mono_gdb_render_native_backtraces ())
close (STDOUT_FILENO);
- exit (1);
- }
- argv [1] = "-ex";
- sprintf (buf1, "attach %ld", (long)getpid ());
- argv [2] = buf1;
- argv [3] = "--ex";
- argv [4] = "info threads";
- argv [5] = "--ex";
- argv [6] = "thread apply all bt";
- argv [7] = "--batch";
- argv [8] = 0;
-
- execv (argv [0], (char**)argv);
exit (1);
}
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
#include <mono/metadata/assembly.h>
#include <mono/metadata/loader.h>
add_signal_handler (SIGPROF, sigprof_signal_handler);
#endif
}
+
+#if !defined(__APPLE__)
+pid_t
+mono_runtime_syscall_fork ()
+{
+ return (pid_t) syscall (SYS_fork);
+}
+
+gboolean
+mono_gdb_render_native_backtraces ()
+{
+ const char *argv [9];
+ char buf1 [128];
+
+ argv [0] = g_find_program_in_path ("gdb");
+ if (argv [0] == NULL) {
+ return FALSE;
+ }
+
+ argv [1] = "-ex";
+ sprintf (buf1, "attach %ld", (long)getpid ());
+ argv [2] = buf1;
+ argv [3] = "--ex";
+ argv [4] = "info threads";
+ argv [5] = "--ex";
+ argv [6] = "thread apply all bt";
+ argv [7] = "--batch";
+ argv [8] = 0;
+
+ execv (argv [0], (char**)argv);
+
+ return TRUE;
+}
+#endif
mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
{
guchar *code = p;
- int arg_size = 0, save_mode = SAVE_NONE;
+ int arg_size = 0, stack_usage = 0, save_mode = SAVE_NONE;
MonoMethod *method = cfg->method;
switch (mini_type_get_underlying_type (cfg->generic_sharing_context, mono_method_signature (method)->ret)->type) {
case MONO_TYPE_VOID:
/* special case string .ctor icall */
- if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
+ if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class) {
save_mode = SAVE_EAX;
- else
+ stack_usage = enable_arguments ? 8 : 4;
+ } else
save_mode = SAVE_NONE;
break;
case MONO_TYPE_I8:
case MONO_TYPE_U8:
save_mode = SAVE_EAX_EDX;
+ stack_usage = enable_arguments ? 16 : 8;
break;
case MONO_TYPE_R4:
case MONO_TYPE_R8:
save_mode = SAVE_FP;
+ stack_usage = enable_arguments ? 16 : 8;
break;
case MONO_TYPE_GENERICINST:
if (!mono_type_generic_inst_is_valuetype (mono_method_signature (method)->ret)) {
save_mode = SAVE_EAX;
+ stack_usage = enable_arguments ? 8 : 4;
break;
}
/* Fall through */
case MONO_TYPE_VALUETYPE:
+ // FIXME: Handle SMALL_STRUCT_IN_REG here for proper alignment on darwin-x86
save_mode = SAVE_STRUCT;
+ stack_usage = enable_arguments ? 4 : 0;
break;
default:
save_mode = SAVE_EAX;
+ stack_usage = enable_arguments ? 8 : 4;
break;
}
+ x86_alu_reg_imm (code, X86_SUB, X86_ESP, MONO_ARCH_FRAME_ALIGNMENT - stack_usage - 4);
+
switch (save_mode) {
case SAVE_EAX_EDX:
x86_push_reg (code, X86_EDX);
mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_ABS, func);
x86_call_code (code, 0);
}
+
x86_alu_reg_imm (code, X86_ADD, X86_ESP, arg_size + 4);
switch (save_mode) {
default:
break;
}
+
+ x86_alu_reg_imm (code, X86_ADD, X86_ESP, MONO_ARCH_FRAME_ALIGNMENT - stack_usage);
return code;
}
g_hash_table_remove (domain_jit_info (domain)->dynamic_code_hash, method);
mono_internal_hash_table_remove (&domain->jit_code_hash, method);
g_hash_table_remove (domain_jit_info (domain)->jump_trampoline_hash, method);
+ g_hash_table_remove (domain_jit_info (domain)->runtime_invoke_hash, method);
mono_domain_unlock (domain);
#ifdef MONO_ARCH_HAVE_INVALIDATE_METHOD
return mono_jit_find_compiled_method_with_jit_info (domain, method, NULL);
}
+typedef struct {
+ MonoMethod *method;
+ gpointer compiled_method;
+ gpointer runtime_invoke;
+ MonoVTable *vtable;
+} RuntimeInvokeInfo;
+
/**
* mono_jit_runtime_invoke:
* @method: the method to invoke
static MonoObject*
mono_jit_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc)
{
- MonoMethod *to_compile;
MonoMethod *invoke;
MonoObject *(*runtime_invoke) (MonoObject *this, void **params, MonoObject **exc, void* compiled_method);
- void* compiled_method;
- MonoVTable *vtable;
- gboolean need_rgctx_tramp = FALSE;
-
+ MonoDomain *domain = mono_domain_get ();
+ MonoJitDomainInfo *domain_info;
+ RuntimeInvokeInfo *info, *info2;
+
if (obj == NULL && !(method->flags & METHOD_ATTRIBUTE_STATIC) && !method->string_ctor && (method->wrapper_type == 0)) {
g_warning ("Ignoring invocation of an instance method on a NULL instance.\n");
return NULL;
}
- to_compile = method;
+ domain_info = domain_jit_info (domain);
- if (mono_method_needs_static_rgctx_invoke (method, FALSE))
- need_rgctx_tramp = TRUE;
+ mono_domain_lock (domain);
+ info = g_hash_table_lookup (domain_info->runtime_invoke_hash, method);
+ mono_domain_unlock (domain);
- /* Special case parameterless ctors to speed up Activator.CreateInstance () */
- if (method->flags & (METHOD_ATTRIBUTE_SPECIAL_NAME | METHOD_ATTRIBUTE_RT_SPECIAL_NAME) && !strcmp (method->name, ".ctor") && mono_method_signature (method)->param_count == 0 && !method->klass->valuetype) {
- MonoJitDomainInfo *domain_info = domain_jit_info (mono_domain_get ());
+ if (!info) {
+ info = g_new0 (RuntimeInvokeInfo, 1);
- if (!domain_info->ctor_runtime_invoke) {
- invoke = mono_marshal_get_runtime_invoke (method, FALSE);
- domain_info->ctor_runtime_invoke = mono_jit_compile_method (invoke);
+ invoke = mono_marshal_get_runtime_invoke (method, FALSE);
+ info->runtime_invoke = mono_jit_compile_method (invoke);
+ info->vtable = mono_class_vtable (domain, method->klass);
+ g_assert (info->vtable);
+
+ if (method->klass->rank && (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) &&
+ (method->iflags & METHOD_IMPL_ATTRIBUTE_NATIVE)) {
+ /*
+ * Array Get/Set/Address methods. The JIT implements them using inline code
+ * inside the runtime invoke wrappers, so no need to compile them.
+ */
+ info->compiled_method = NULL;
+ } else {
+ info->compiled_method = mono_jit_compile_method (method);
+
+ if (mono_method_needs_static_rgctx_invoke (method, FALSE))
+ info->compiled_method = mono_create_static_rgctx_trampoline (method, info->compiled_method);
}
- runtime_invoke = domain_info->ctor_runtime_invoke;
- } else {
- invoke = mono_marshal_get_runtime_invoke (method, FALSE);
- runtime_invoke = mono_jit_compile_method (invoke);
+ mono_domain_lock (domain);
+ info2 = g_hash_table_lookup (domain_info->runtime_invoke_hash, method);
+ if (info2) {
+ g_free (info);
+ info = info2;
+ } else {
+ g_hash_table_insert (domain_info->runtime_invoke_hash, method, info);
+ }
+ mono_domain_unlock (domain);
}
+ runtime_invoke = info->runtime_invoke;
+
/*
* We need this here because mono_marshal_get_runtime_invoke can place
* the helper method in System.Object and not the target class.
*/
- vtable = mono_class_vtable (mono_domain_get (), method->klass);
- g_assert (vtable);
- mono_runtime_class_init (vtable);
-
- if (method->klass->rank && (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) &&
- (method->iflags & METHOD_IMPL_ATTRIBUTE_NATIVE)) {
- /*
- * Array Get/Set/Address methods. The JIT implements them using inline code
- * inside the runtime invoke wrappers, so no need to compile them.
- */
- compiled_method = NULL;
- } else {
- compiled_method = mono_jit_compile_method (to_compile);
- }
- if (need_rgctx_tramp)
- compiled_method = mono_create_static_rgctx_trampoline (to_compile, compiled_method);
+ mono_runtime_class_init (info->vtable);
- return runtime_invoke (obj, params, exc, compiled_method);
+ return runtime_invoke (obj, params, exc, info->compiled_method);
}
void
info->delegate_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
info->static_rgctx_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
info->llvm_vcall_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
+ info->runtime_invoke_hash = g_hash_table_new_full (mono_aligned_addr_hash, NULL, NULL, g_free);
domain->runtime_info = info;
}
g_hash_table_destroy (info->delegate_trampoline_hash);
g_hash_table_destroy (info->static_rgctx_trampoline_hash);
g_hash_table_destroy (info->llvm_vcall_trampoline_hash);
+ g_hash_table_destroy (info->runtime_invoke_hash);
g_free (domain->runtime_info);
domain->runtime_info = NULL;
guint32 trampoline_got_offset_base [MONO_AOT_TRAMP_NUM];
guint32 trampoline_size [MONO_AOT_TRAMP_NUM];
} MonoAotFileInfo;
-
+
/* Per-domain information maintained by the JIT */
typedef struct
{
/* maps MonoMethod -> MonoJitDynamicMethodInfo */
GHashTable *dynamic_code_hash;
GHashTable *method_code_hash;
- /* Compiled runtime invoke function for parameterless ctors */
- gpointer ctor_runtime_invoke;
+ /* Maps methods to a RuntimeInvokeInfo structure */
+ GHashTable *runtime_invoke_hash;
} MonoJitDomainInfo;
typedef struct {
void mono_runtime_setup_stat_profiler (void) MONO_INTERNAL;
void mono_runtime_shutdown_stat_profiler (void) MONO_INTERNAL;
void mono_runtime_posix_install_handlers (void) MONO_INTERNAL;
+pid_t mono_runtime_syscall_fork (void) MONO_INTERNAL;
+gboolean mono_gdb_render_native_backtraces (void) MONO_INTERNAL;
/*
* Signal handling
+2009-07-20 Geoff Norton <gnorton@novell.com>
+
+ * mono-semaphore.h: Refactor from io-layer/thread-private.h so it
+ can be used by the runtime as well.
+
2009-07-17 Gonzalo Paniagua Javier <gonzalo@novell.com>
* mono-proclib.c: fix reading processor usage for a process. Patch
mono-uri.c \
mono-poll.c \
mono-path.c \
+ mono-semaphore.h \
mono-stdlib.c \
mono-property-hash.h \
mono-property-hash.c \
--- /dev/null
+/*
+ * mono-semaphore.h: Definitions for generic semaphore usage
+ *
+ * Author:
+ * Geoff Norton <gnorton@novell.com>
+ *
+ * (C) 2009 Novell, Inc.
+ */
+
+#ifndef _MONO_SEMAPHORE_H_
+#define _MONO_SEMAPHORE_H_
+
+#include <config.h>
+#ifdef HAVE_SEMAPHORE_H
+#include <semaphore.h>
+#endif
+
+#if defined (HAVE_SEMAPHORE_H) || defined (USE_MACH_SEMA)
+# define MONO_HAS_SEMAPHORES
+
+# if defined (USE_MACH_SEMA)
+# include <mach/mach_init.h>
+# include <mach/task.h>
+# include <mach/semaphore.h>
+typedef semaphore_t MonoSemType;
+# define MONO_SEM_INIT(addr,value) semaphore_create (current_task (), (addr), SYNC_POLICY_FIFO, (value))
+# define MONO_SEM_WAIT(sem) semaphore_wait (*(sem))
+# define MONO_SEM_POST(sem) semaphore_signal (*(sem))
+# define MONO_SEM_DESTROY(sem) semaphore_destroy (current_task (), *(sem))
+# else
+typedef sem_t MonoSemType;
+# define MONO_SEM_INIT(addr,value) sem_init ((addr), 0, (value))
+# define MONO_SEM_WAIT(sem) sem_wait ((sem))
+# define MONO_SEM_POST(sem) sem_post ((sem))
+# define MONO_SEM_DESTROY(sem) sem_destroy ((sem))
+# endif
+#endif
+
+#endif /* _MONO_SEMAPHORE_H_ */