示例#1
0
 public void ConstructorDefaultsValueToZero()
 {
     using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp))
     {
         Assert.That(intPtr.Value, Is.EqualTo(0));
     }
 }
示例#2
0
 public void ConstructorSetsInitialValue()
 {
     using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp, 123))
     {
         Assert.That(intPtr.Value, Is.EqualTo(123));
     }
 }
示例#3
0
        public void ParallelForJobCanUseParallelPtr()
        {
            using (NativeArray <long> array = new NativeArray <long>(
                       3,
                       Allocator.TempJob))
            {
                NativeArray <long> arrayCopy = array;
                arrayCopy[0] = 10;
                arrayCopy[1] = 20;
                arrayCopy[2] = 30;

                using (NativeLongPtr sum = new NativeLongPtr(
                           Allocator.TempJob))
                {
                    ParallelForTestJob job = new ParallelForTestJob
                    {
                        Array = array,
                        Sum   = sum.GetParallel()
                    };
                    job.Run(array.Length);

                    Assert.That(sum.Value, Is.EqualTo(60));
                }
            }
        }
示例#4
0
 public void DisposeRequiresReadAccess()
 {
     using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp))
     {
         AssertRequiresReadOrWriteAccess(
             intPtr,
             intPtr.Dispose);
     }
 }
示例#5
0
        public void DisposeMakesUnusable()
        {
            NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp);

            intPtr.Dispose();
            Assert.That(
                () => intPtr.Value = 10,
                Throws.TypeOf <InvalidOperationException>());
        }
示例#6
0
        public void ParallelIncrementIncrementsValue()
        {
            using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp, 123))
            {
                NativeLongPtr.Parallel parallel = intPtr.GetParallel();
                parallel.Increment();

                Assert.That(intPtr.Value, Is.EqualTo(124));
            }
        }
示例#7
0
 public void SetValueRequiresReadAccess()
 {
     using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp))
     {
         NativeLongPtr copy = intPtr;
         AssertRequiresReadOrWriteAccess(
             intPtr,
             () => copy.Value = 123);
     }
 }
示例#8
0
 public void GetValueRequiresReadAccess()
 {
     using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp))
     {
         long value;
         AssertRequiresReadOrWriteAccess(
             intPtr,
             () => value = intPtr.Value);
     }
 }
示例#9
0
        public void GetValueReturnsWhatSetValueSets()
        {
            using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp))
            {
                NativeLongPtr copy = intPtr;
                copy.Value = 123;

                Assert.That(intPtr.Value, Is.EqualTo(123));
            }
        }
示例#10
0
        public void IsCreatedOnlyReturnsTrueBeforeDispose()
        {
            NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp);

            Assert.That(intPtr.IsCreated, Is.True);

            intPtr.Dispose();

            Assert.That(intPtr.IsCreated, Is.False);
        }
示例#11
0
 public void ParallelAddRequiresReadAccess()
 {
     using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp))
     {
         NativeLongPtr.Parallel parallel = intPtr.GetParallel();
         AssertRequiresReadOrWriteAccess(
             intPtr,
             () => parallel.Add(10));
     }
 }
示例#12
0
 public void ParallelDecrementRequiresReadAccess()
 {
     using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp))
     {
         NativeLongPtr.Parallel parallel = intPtr.GetParallel();
         AssertRequiresReadOrWriteAccess(
             intPtr,
             parallel.Decrement);
     }
 }
示例#13
0
        public void CanDeallocateOnJobCompletion()
        {
            NativeLongPtr intPtr = new NativeLongPtr(Allocator.TempJob);
            var           job    = new DeallocateOnJobCompletionJob {
                LongPtr = intPtr
            };

            job.Run();

            Assert.That(
                () => intPtr.Value = 10,
                Throws.TypeOf <InvalidOperationException>());
        }
示例#14
0
        public void ParallelAddOffsetsValue()
        {
            using (NativeLongPtr intPtr = new NativeLongPtr(Allocator.Temp, 123))
            {
                NativeLongPtr.Parallel parallel = intPtr.GetParallel();
                parallel.Add(5);

                Assert.That(intPtr.Value, Is.EqualTo(128));

                parallel.Add(-15);

                Assert.That(intPtr.Value, Is.EqualTo(113));
            }
        }
示例#15
0
 private static void AssertRequiresReadOrWriteAccess(
     NativeLongPtr intPtr,
     Action action)
 {
     intPtr.TestUseOnlySetAllowReadAndWriteAccess(false);
     try
     {
         Assert.That(
             () => action(),
             Throws.TypeOf <InvalidOperationException>());
     }
     finally
     {
         intPtr.TestUseOnlySetAllowReadAndWriteAccess(true);
     }
 }