Ejemplo n.º 1
0
    public unsafe void UnsafeUtility_MemSwap_DoesThrow_Overlapped()
    {
        using (var array0 = MakeTestArray(0x12345678, 0x12345678, 0x12345678, 0x12345678, 0x12345678, 0x12345678))
        {
            var mem = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(array0);
            var len = array0.Length * UnsafeUtility.SizeOf <int>();

            Assert.DoesNotThrow(() => { UnsafeUtilityExtensions.MemSwap(mem + 10, mem, 10); });
            Assert.Throws <InvalidOperationException>(() => { UnsafeUtilityExtensions.MemSwap(mem + 10, mem, len - 10); });

            Assert.DoesNotThrow(() => { UnsafeUtilityExtensions.MemSwap(mem, mem + 10, 10); });
            Assert.Throws <InvalidOperationException>(() => { UnsafeUtilityExtensions.MemSwap(mem, mem + 10, len - 10); });
        }
    }
Ejemplo n.º 2
0
    public unsafe void UnsafeUtility_MemSwap()
    {
        using (var array0 = MakeTestArray(0x12345678, 0x12345678, 0x12345678, 0x12345678, 0x12345678, 0x12345678))
            using (var array1 = MakeTestArray(0x21436587, 0x21436587, 0x21436587, 0x21436587, 0x21436587, 0x21436587))
            {
                UnsafeUtilityExtensions.MemSwap(NativeArrayUnsafeUtility.GetUnsafePtr(array0), NativeArrayUnsafeUtility.GetUnsafePtr(array1), array0.Length * UnsafeUtility.SizeOf <int>());

                foreach (var b in array0)
                {
                    Assert.AreEqual(0x21436587, b);
                }
                foreach (var b in array1)
                {
                    Assert.AreEqual(0x12345678, b);
                }
            }
    }