Exemplo n.º 1
0
        public unsafe void GetSetPointer(IArrayPtr <AdventurePhysics> adventurePhysicsPointer)
        {
            // No change in element size, this class does not do marshalling.

            // Backup original pointer.
            void *originalPtr = adventurePhysicsPointer.Pointer;
            int   elementSize = adventurePhysicsPointer.ElementSize;

            // Get first two elements.
            adventurePhysicsPointer.Get(out var firstElement, 0);
            adventurePhysicsPointer.Get(out var secondElement, 1);

            // Check Indexer overloads.
            Assert.Equal(firstElement, adventurePhysicsPointer[0]);
            Assert.Equal(secondElement, adventurePhysicsPointer[1]);

            Assert.NotEqual(firstElement, secondElement);           // First two elements should not be equal. If they are, change your test data.

            // Increment pointer by 1 and get first element (true second element).
            adventurePhysicsPointer.Pointer = (void *)IntPtr.Add((IntPtr)originalPtr, elementSize);

            // Get first (second) element and compare.
            adventurePhysicsPointer.Get(out var pseudoFirstElement, 0);

            Assert.NotEqual(firstElement, pseudoFirstElement);
            Assert.Equal(secondElement, pseudoFirstElement);

            // Restore pointer.
            adventurePhysicsPointer.Pointer = originalPtr;
        }
Exemplo n.º 2
0
        public void SetArrayIndex(IArrayPtr <AdventurePhysics> adventurePhysicsPointer)
        {
            // Grab First and Second Element
            adventurePhysicsPointer.Get(out var firstElement, 0);
            adventurePhysicsPointer.Get(out var secondElement, 1);

            // Check Indexer overloads.
            Assert.Equal(firstElement, adventurePhysicsPointer[0]);
            Assert.Equal(secondElement, adventurePhysicsPointer[1]);

            // Confirm not equal.
            Assert.NotEqual(firstElement, secondElement);           // First two elements should not be equal. If they are, change your test data.

            // Set second element, get copy of it.
            adventurePhysicsPointer.Set(ref firstElement, 1);
            adventurePhysicsPointer.Get(out var newSecondElement, 1);

            Assert.NotEqual(secondElement, newSecondElement);
            Assert.Equal(firstElement, newSecondElement);

            // Set original element with Index setter.
            adventurePhysicsPointer[1] = secondElement;
            var restoredSecondelement = adventurePhysicsPointer[1];

            Assert.Equal(secondElement, restoredSecondelement);
            Assert.NotEqual(secondElement, firstElement);

            // Restore
            adventurePhysicsPointer.Set(ref secondElement, 1);
        }
Exemplo n.º 3
0
        public void ArrayElementSize(IArrayPtr <AdventurePhysics> adventurePhysicsPointer)
        {
            // No change in element size, this class does not do marshalling.
            adventurePhysicsPointer.MarshalElements = true;
            Assert.Equal(0x84, adventurePhysicsPointer.ElementSize);

            adventurePhysicsPointer.MarshalElements = false;
            Assert.Equal(0x84, adventurePhysicsPointer.ElementSize);
        }
Exemplo n.º 4
0
        public void SetArrayIndex(IArrayPtr <AdventurePhysics> adventurePhysicsPointer)
        {
            // Grab First and Second Element
            adventurePhysicsPointer.Get(out var firstElement, 0);
            adventurePhysicsPointer.Get(out var secondElement, 1);

            // Confirm not equal.
            Assert.NotEqual(firstElement, secondElement);           // First two elements should not be equal. If they are, change your test data.

            // Set second element, get copy of it.
            adventurePhysicsPointer.Set(ref firstElement, 1);
            adventurePhysicsPointer.Get(out var newSecondElement, 1);

            Assert.NotEqual(secondElement, newSecondElement);
            Assert.Equal(firstElement, newSecondElement);

            // Restore
            adventurePhysicsPointer.Set(ref secondElement, 1);
        }