Exemple #1
0
        public void GetMemory_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                PULSharedMemory.GetMemoryInt32ByteArrayRef().Body = (ULSharedMemory @this, int size, out byte[] buf) =>
                {
                    buf = new byte[42];
                    for (int i = 0; i < buf.Length; i++)
                        buf[i] = 42;
                    return true;
                };

                using (var sm = new ULSharedMemory())
                {
                    // Act
                    var size = 1024;
                    var buf = default(byte[]);
                    var actual = sm.GetMemory(size, out buf);

                    // Assert
                    Assert.IsTrue(actual);
                    Assert.AreEqual(42, buf.Length);
                    Assert.AreEqual((byte)42, buf[0]);
                    Assert.AreEqual((byte)42, buf[buf.Length - 1]);
                }
            }
        }
Exemple #2
0
        public void GetMemory_should_be_callable_indirectly_against_only_specified_instance()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var smProxy = new PProxyULSharedMemory();
                smProxy.GetMemoryInt32ByteArrayRef().Body = (ULSharedMemory @this, int size, out byte[] buf) =>
                {
                    buf = new byte[42];
                    for (int i = 0; i < buf.Length; i++)
                        buf[i] = 42;
                    return true;
                };
                var sm_sut = (ULSharedMemory)smProxy;


                using (var sm = new ULSharedMemory())
                {
                    // Act
                    var size = 1024;

                    var buf_sut = default(byte[]);
                    var actual_sut = sm_sut.GetMemory(size, out buf_sut);

                    var buf = default(byte[]);
                    var actual = sm.GetMemory(size, out buf);

                    // Assert
                    Assert.IsTrue(actual_sut);
                    Assert.AreEqual(42, buf_sut.Length);
                    Assert.AreEqual((byte)42, buf_sut[0]);
                    Assert.AreEqual((byte)42, buf_sut[buf_sut.Length - 1]);

                    Assert.AreNotEqual(buf.Length, buf_sut.Length); // constant value is just Length :)
                }
            }
        }
Exemple #3
0
        public void AddOnDisposed_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var handler = default(ULSharedMemory.DisposedEventHandler);

                PULSharedMemory.AddOnDisposedDisposedEventHandler().Body = (@this, value) => handler += value;
                PULSharedMemory.Dispose().Body = @this =>
                {
                    handler(true);
                    IndirectionsContext.ExecuteOriginal(() => @this.Dispose());
                };

                var called = false;

                using (var sm = new ULSharedMemory())
                {
                    // Act
                    sm.OnDisposed += disposing => called = disposing;
                }

                
                // Assert
                Assert.IsTrue(called);
            }
        }