Example #1
0
        public void ContainsWorks()
        {
            var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });

            Assert.True(arr.Contains(9), "9");
            Assert.False(arr.Contains(1), "1");
        }
Example #2
0
        public void ICollectionCopyTo()
        {
            ICollection <uint> l = new Uint32Array(new uint[] { 0, 1, 2 });

            var a1 = new uint[3];

            l.CopyTo(a1, 0);

            Assert.AreEqual(0, a1[0], "1.Element 0");
            Assert.AreEqual(1, a1[1], "1.Element 1");
            Assert.AreEqual(2, a1[2], "1.Element 2");

            var a2 = new uint[5];

            l.CopyTo(a2, 1);

            Assert.AreEqual(0, a2[0], "2.Element 0");
            Assert.AreEqual(0, a2[1], "2.Element 1");
            Assert.AreEqual(1, a2[2], "2.Element 2");
            Assert.AreEqual(2, a2[3], "2.Element 3");
            Assert.AreEqual(0, a2[4], "2.Element 4");

            Assert.Throws <ArgumentNullException>(() => { l.CopyTo(null, 0); }, "3.null");

            var a3 = new uint[2];

            Assert.Throws <ArgumentException>(() => { l.CopyTo(a3, 0); }, "3.Short array");

            var a4 = new uint[3];

            Assert.Throws <ArgumentException>(() => { l.CopyTo(a4, 1); }, "3.Start index 1");
            Assert.Throws <ArgumentOutOfRangeException>(() => { l.CopyTo(a4, -1); }, "3.Negative start index");
            Assert.Throws <ArgumentException>(() => { l.CopyTo(a4, 3); }, "3.Start index 3");
        }
Example #3
0
        public void IndexOfWorks()
        {
            var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });

            Assert.AreEqual(3, arr.IndexOf(9), "9");
            Assert.AreEqual(-1, arr.IndexOf(1), "1");
        }
		public void CopyConstructorWorks() {
			 var source = new Uint32Array(new uint[] { 3, 8, 4 });
			 var arr = new Uint32Array(source);
			 Assert.IsTrue(arr != source, "New object");
			 Assert.IsTrue((object)arr is Uint32Array, "is Uint32Array");
			 AssertContent(arr, new[] { 3, 8, 4 }, "content");
		}
Example #5
0
        public void SetNormalArrayWithOffsetWorks()
        {
            var arr = new Uint32Array(6);

            arr.Set(new uint[] { 3, 6, 7 }, 2);
            AssertContent(arr, new[] { 0, 0, 3, 6, 7, 0 }, "Content");
        }
Example #6
0
        public ITypedArray CastNativeArray(object managedArray)
        {
            var         arrayType = managedArray.GetType();
            ITypedArray array;

            // Here are listed some JavaScript array types:
            // https://github.com/mono/mono/blob/a7f5952c69ae76015ccaefd4dfa8be2274498a21/sdks/wasm/bindings-test.cs
            if (arrayType == typeof(byte[]))
            {
                array = Uint8Array.From((byte[])managedArray);
            }
            else if (arrayType == typeof(float[]))
            {
                array = Float32Array.From((float[])managedArray);
            }
            else if (arrayType == typeof(ushort[]))
            {
                array = Uint16Array.From((ushort[])managedArray);
            }
            else if (arrayType == typeof(uint[]))
            {
                array = Uint32Array.From((uint[])managedArray);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(array);
        }
Example #7
0
        public void SetNormalArrayWorks()
        {
            var arr = new Uint32Array(4);

            arr.Set(new uint[] { 3, 6, 7 });
            AssertContent(arr, new[] { 3, 6, 7, 0 }, "Content");
        }
Example #8
0
        public void BufferPropertyWorks()
        {
            var buf = new ArrayBuffer(100);
            var arr = new Uint32Array(buf);

            Assert.True(arr.Buffer == buf, "Should be correct");
        }
Example #9
0
        public static void Uint32ArrayFromArrayBuffer(Function objectPrototype)
        {
            Uint32Array from = new Uint32Array(new ArrayBuffer(40));

            Assert.True(from.Length == 10);
            Assert.Equal("[object Uint32Array]", objectPrototype.Call(from));
        }
Example #10
0
        public void ByteOffsetPropertyWorks()
        {
            var buf = new ArrayBuffer(100);
            var arr = new Uint32Array(buf, 32);

            Assert.AreEqual(32, arr.ByteOffset, "Should be correct");
        }
Example #11
0
        public void LengthConstructorWorks()
        {
            var arr = new Uint32Array(13);

            Assert.True((object)arr is Uint32Array, "is Uint32Array");
            Assert.AreEqual(13, arr.Length, "Length");
        }
		public void ArrayBufferWithOffsetConstructorWorks() {
			var buf = new ArrayBuffer(80);
			var arr = new Uint32Array(buf, 16);
			Assert.IsTrue((object)arr is Uint32Array);
			Assert.IsTrue(arr.Buffer == buf, "buffer");
			Assert.AreEqual(arr.Length, 16, "length");
		}
Example #13
0
        public static void Uint32ArrayFromSharedArrayBuffer(Function objectPrototype)
        {
            Uint32Array from = new Uint32Array(new SharedArrayBuffer(40));

            Assert.Equal(10, from.Length);
            Assert.Equal("[object Uint32Array]", objectPrototype.Call(from));
        }
Example #14
0
        public static void Uint32ArrayFrom(Function objectPrototype)
        {
            var         array = new uint[50];
            Uint32Array from  = Uint32Array.From(array);

            Assert.Equal(50, from.Length);
            Assert.Equal("[object Uint32Array]", objectPrototype.Call(from));
        }
Example #15
0
        public void IndexingWorks()
        {
            var arr = new Uint32Array(3);

            arr[1] = 42;
            AssertContent(arr, new[] { 0, 42, 0 }, "Content");
            Assert.AreEqual(42, arr[1], "[1]");
        }
Example #16
0
        public void SubarrayWithBeginWorks()
        {
            var source = new Uint32Array(10);
            var arr    = source.SubArray(3);

            Assert.False(arr == source, "Should be a new array");
            Assert.True(arr.Buffer == source.Buffer, "Should be the same buffer");
            Assert.AreEqual(12, arr.ByteOffset, "ByteOffset should be correct");
        }
Example #17
0
        public void CopyConstructorWorks()
        {
            var source = new Uint32Array(new uint[] { 3, 8, 4 });
            var arr    = new Uint32Array(source);

            Assert.True(arr != source, "New object");
            Assert.True((object)arr is Uint32Array, "is Uint32Array");
            AssertContent(arr, new[] { 3, 8, 4 }, "content");
        }
Example #18
0
        public void ArrayBufferWithOffsetConstructorWorks()
        {
            var buf = new ArrayBuffer(80);
            var arr = new Uint32Array(buf, 16);

            Assert.True((object)arr is Uint32Array);
            Assert.True(arr.Buffer == buf, "buffer");
            Assert.AreEqual(16, arr.Length, "length");
        }
Example #19
0
        public void ArrayBufferConstructorWorks()
        {
            var buf = new ArrayBuffer(80);
            var arr = new Uint32Array(buf);

            Assert.IsTrue((object)arr is Uint32Array);
            Assert.IsTrue(arr.Buffer == buf, "buffer");
            Assert.AreEqual(arr.Length, 20, "length");
        }
Example #20
0
        public void ConstructorFromIntWorks()
        {
            var source = new uint[] { 3, 8, 4 };
            var arr    = new Uint32Array(source);

            Assert.IsTrue((object)arr != (object)source, "New object");
            Assert.IsTrue((object)arr is Uint32Array, "is Uint32Array");
            AssertContent(arr, new[] { 3, 8, 4 }, "content");
        }
Example #21
0
        public void SubarrayWithBeginAndEndWorks()
        {
            var source = new Uint32Array(10);
            var arr    = source.Subarray(3, 7);

            Assert.IsFalse(arr == source, "Should be a new array");
            Assert.IsTrue(arr.Buffer == source.Buffer, "Should be the same buffer");
            Assert.AreEqual(arr.ByteOffset, 12, "ByteOffset should be correct");
            Assert.AreEqual(arr.Length, 4, "Length should be correct");
        }
Example #22
0
        public void ForeachWorks()
        {
            var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });
            var l   = new List <uint>();

            foreach (var i in arr)
            {
                l.Add(i);
            }
            Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 });
        }
Example #23
0
        public void GetEnumeratorWorks()
        {
            var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });
            var l   = new List <uint>();
            var enm = arr.GetEnumerator();

            while (enm.MoveNext())
            {
                l.Add(enm.Current);
            }
            Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 });
        }
Example #24
0
        public void ForeachWorks_SPI_1401()
        {
            var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });
            var l   = new List <uint>();

            // #1401
            foreach (var i in arr)
            {
                l.Add(i);
            }
            Assert.AreEqual(l.ToArray(), new[] { 3, 6, 2, 9, 5 });
        }
		private void AssertContent(Uint32Array actual, int[] expected, string message) {
			if (actual.Length != expected.Length) {
				Assert.Fail(message + ": Expected length " + expected.Length + ", actual: " + actual.Length);
				return;
			}
			for (int i = 0; i < expected.Length; i++) {
				if (actual[i] != expected[i]) {
					Assert.Fail(message + ": Position " + i + ": expected " + expected[i] + ", actual: " + actual[i]);
					return;
				}
			}
			Assert.IsTrue(true, message);
		}
Example #26
0
        private unsafe void EnsureArrayCapacity(int numBatchItems)
#endif
        {
            int neededCapacity = 6 * numBatchItems;

            if (_index != null && neededCapacity <= _index.Length)
            {
                // Short circuit out of here because we have enough capacity.
                return;
            }

            var newIndex = new short[6 * numBatchItems];
            int start    = 0;

            if (_index != null)
            {
                _index.CopyTo(newIndex, 0);
                start = _index.Length / 6;
            }

            var indexPtr = (start * 6);

            for (var i = start; i < numBatchItems; i++, indexPtr += 6)
            {
                /*
                 *  TL    TR
                 *   0----1 0,1,2,3 = index offsets for vertex indices
                 *   |   /| TL,TR,BL,BR are vertex references in SpriteBatchItem.
                 *   |  / |
                 *   | /  |
                 *   |/   |
                 *   2----3
                 *  BL    BR
                 */
                // Triangle 1
                newIndex[indexPtr + 0] = (i * 4 + 0).As <short>();
                newIndex[indexPtr + 1] = (i * 4 + 1).As <short>();
                newIndex[indexPtr + 2] = (i * 4 + 2).As <short>();

                newIndex[indexPtr + 3] = (i * 4 + 1).As <short>();
                newIndex[indexPtr + 4] = (i * 4 + 3).As <short>();
                newIndex[indexPtr + 5] = (i * 4 + 2).As <short>();
            }

            _index = newIndex;

            _vertexArray  = new ArrayBuffer(4 * numBatchItems * 6 * 4);
            _vertexArrayF = new Float32Array(_vertexArray);
            _vertexArrayC = new Uint32Array(_vertexArray);
        }
		public void TypePropertiesAreCorrect() {
			Assert.AreEqual(typeof(Uint32Array).FullName, "Uint32Array", "FullName");

			var interfaces = typeof(Uint32Array).GetInterfaces();
			Assert.AreEqual(interfaces.Length, 3, "Interface count should be 3");
			Assert.IsTrue(interfaces.Contains(typeof(IEnumerable<uint>)), "Interfaces should contain IEnumerable<uint>");
			Assert.IsTrue(interfaces.Contains(typeof(ICollection<uint>)), "Interfaces should contain ICollection<uint>");
			Assert.IsTrue(interfaces.Contains(typeof(IList<uint>)), "Interfaces should contain IList<uint>");

			object arr = new Uint32Array(0);
			Assert.IsTrue(arr is Uint32Array, "Is Uint32Array");
			Assert.IsTrue(arr is IEnumerable<uint>, "Is IEnumerable<uint>");
			Assert.IsTrue(arr is ICollection<uint>, "Is ICollection<uint>");
			Assert.IsTrue(arr is IList<uint>, "Is IList<int>");
		}
Example #28
0
        public void Uint32Array_indexed_setter_stores_and_retrieves_with_correct_signedness()
        {
            // In order to test all possible values for integers, we
            // need to create a buffer large enough to store them all,
            // except .NET won't allow arrays larger than Int32.MaxValue,
            // or 0x7FFFFFFF, which is only large enough to store
            // 0x1FFFFFFF 4-byte unsigned integers, with 3 extra bytes.
            // Creating four of these covers almost all 4-byte integers
            // starting from 0x00000000 all the way to 0xFFFFFFF7,
            // leaving a final check on values 0xFFFFFFF8-0xFFFFFFFF.
            // Unfortunately, not all machines are going to have
            // 2GB of contiguous RAM sitting around handy, and it may
            // not get fully GC'd in time for the next loop, so we'll
            // shrink the window even further still to 0x1FFFFFF,
            // which over 128 windows covers 0x00000000-0xFFFFFF7F,
            // leaving a final check on values 0xFFFFFF80-0xFFFFFFFF.
            int windowSize = 0x1FFFFFF;

            for (uint window = 0; window < 128; window++)
            {
                byte[] buf       = new byte[windowSize * 4];
                var    u32winarr = new Uint32Array(buf, 0, 0);

                for (var i = 0; i < windowSize; i++)
                {
                    u32winarr[i] = (uint)((window * windowSize) + i);
                }

                for (uint i = (uint)(window * windowSize), j = 0; j < windowSize; i++, j++)
                {
                    Assert.AreEqual(u32winarr[(int)j], i);
                }
            }

            byte[] finalbuf       = new byte[0x80 * 4];
            var    finalu32winarr = new Uint32Array(finalbuf, 0, 0);

            for (var i = 0; i < 0x80; i++)
            {
                finalu32winarr[i] = (uint)(((uint)128 * windowSize) + i);
            }

            for (uint i = (uint)(windowSize * 128), j = 0; j < 0x80; j++, i++)
            {
                Assert.AreEqual(finalu32winarr[(int)j], i);
            }
        }
Example #29
0
 private void AssertContent(Uint32Array actual, int[] expected, string message)
 {
     if (actual.Length != expected.Length)
     {
         Assert.Fail(message + ": Expected length " + expected.Length + ", actual: " + actual.Length);
         return;
     }
     for (int i = 0; i < expected.Length; i++)
     {
         if (actual[i] != expected[i])
         {
             Assert.Fail(message + ": Position " + i + ": expected " + expected[i] + ", actual: " + actual[i]);
             return;
         }
     }
     Assert.True(true, message);
 }
Example #30
0
        public void TypePropertiesAreCorrect()
        {
            Assert.AreEqual(typeof(Uint32Array).FullName, "Uint32Array", "FullName");

            var interfaces = typeof(Uint32Array).GetInterfaces();

            Assert.AreEqual(interfaces.Length, 3, "Interface count should be 3");
            Assert.IsTrue(interfaces.Contains(typeof(IEnumerable <uint>)), "Interfaces should contain IEnumerable<uint>");
            Assert.IsTrue(interfaces.Contains(typeof(ICollection <uint>)), "Interfaces should contain ICollection<uint>");
            Assert.IsTrue(interfaces.Contains(typeof(IList <uint>)), "Interfaces should contain IList<uint>");

            object arr = new Uint32Array(0);

            Assert.IsTrue(arr is Uint32Array, "Is Uint32Array");
            Assert.IsTrue(arr is IEnumerable <uint>, "Is IEnumerable<uint>");
            Assert.IsTrue(arr is ICollection <uint>, "Is ICollection<uint>");
            Assert.IsTrue(arr is IList <uint>, "Is IList<int>");
        }
Example #31
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(10);

            var array1 = new Int8Array(1);

            Bridge550.TestMethod(array1, "Int8Array", assert);

            var array2 = new Uint8Array(1);

            Bridge550.TestMethod(array2, "Uint8Array", assert);

            var array3 = new Uint8ClampedArray(1);

            Bridge550.TestMethod(array3, "Uint8ClampedArray", assert);

            var array4 = new Int16Array(1);

            Bridge550.TestMethod(array4, "Int16Array", assert);

            var array5 = new Uint16Array(1);

            Bridge550.TestMethod(array5, "Uint16Array", assert);

            var array6 = new Int32Array(1);

            Bridge550.TestMethod(array6, "Int32Array", assert);

            var array7 = new Uint32Array(1);

            Bridge550.TestMethod(array7, "Uint32Array", assert);

            var array8 = new Float32Array(1);

            Bridge550.TestMethod(array8, "Float32Array", assert);

            var array9 = new Float64Array(1);

            Bridge550.TestMethod(array9, "Float64Array", assert);

            var array10 = new DataView(array9.Buffer);

            Bridge550.TestMethod(array10, "DataView", assert);
        }
Example #32
0
        public void Uint32Array_indexed_setter_alters_source_buffer_contents_according_to_native_endianness()
        {
            byte[] buf    = new byte[] { 0x00, 0x01, 0x02, 0x03 };
            var    u32arr = new Uint32Array(buf, 0);

            u32arr[0] = 2864434397; // 0xAABBCCDD, stored as [0xAA, 0xBB, 0xCC, 0xDD] on big endian archs and [0xDD, 0xCC, 0xBB, 0xAA] on little endian archs.

            if (BitConverter.IsLittleEndian)
            {
                Assert.AreEqual(buf[0], 0xDD);
                Assert.AreEqual(buf[1], 0xCC);
                Assert.AreEqual(buf[2], 0xBB);
                Assert.AreEqual(buf[3], 0xAA);
            }
            else
            {
                Assert.AreEqual(buf[3], 0xDD);
                Assert.AreEqual(buf[2], 0xCC);
                Assert.AreEqual(buf[1], 0xBB);
                Assert.AreEqual(buf[0], 0xAA);
            }
        }
Example #33
0
        private void BufferData <T>(int offsetInBytes, T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct
        {
            GenerateIfRequired();

            var elementSizeInByte = (IndexElementSize == IndexElementSize.SixteenBits ? 2 : 4);
            var bufferSize        = IndexCount * elementSizeInByte;

            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
            GraphicsExtensions.CheckGLError();

            if (options == SetDataOptions.Discard)
            {
                // By assigning NULL data to the buffer this gives a hint
                // to the device to discard the previous content.
                gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Int16Array(0), _isDynamic ? gl.STREAM_DRAW : gl.STATIC_DRAW);
                GraphicsExtensions.CheckGLError();
            }

            if (elementSizeInByte == 2)
            {
                var arr = new Uint16Array((uint)elementCount);
                for (uint i = 0; i < elementCount; i++)
                {
                    arr[i] = data[i + startIndex].As <ushort>();
                }
                gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, offsetInBytes, arr);
            }
            else
            {
                var arr = new Uint32Array((uint)elementCount);
                for (uint i = 0; i < elementCount; i++)
                {
                    arr[i] = data[i + startIndex].As <uint>();
                }
                gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, offsetInBytes, arr);
            }
            GraphicsExtensions.CheckGLError();
        }
Example #34
0
        public static IEnumerable <object[]> ArrayType_TestData()
        {
            _objectPrototype ??= new Function("return Object.prototype.toString;");
            yield return(new object[] { _objectPrototype.Call(), "Uint8Array", Uint8Array.From(new byte[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Uint8ClampedArray", Uint8ClampedArray.From(new byte[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Int8Array", Int8Array.From(new sbyte[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Uint16Array", Uint16Array.From(new ushort[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Int16Array", Int16Array.From(new short[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Uint32Array", Uint32Array.From(new uint[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Int32Array", Int32Array.From(new int[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Float32Array", Float32Array.From(new float[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Float64Array", Float64Array.From(new double[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Array", new Array(10) });
        }
		public void ByteLengthPropertyWorks() {
			var arr = new Uint32Array(23);
			Assert.AreEqual(arr.ByteLength, 92, "Should be correct");
		}
		public void LengthConstructorWorks() {
			var arr = new Uint32Array(13);
			Assert.IsTrue((object)arr is Uint32Array, "is Uint32Array");
			Assert.AreEqual(arr.Length, 13, "Length");
		}
		public void ForeachWorks() {
			var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });
			var l = new List<uint>();
			foreach (var i in arr) {
				l.Add(i);
			}
			Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 });
		}
		public void LengthWorks() {
			var arr = new Uint32Array(13);
			Assert.AreEqual(arr.Length, 13, "Length");
		}
		public void IndexingWorks() {
			var arr = new Uint32Array(3);
			arr[1] = 42;
			AssertContent(arr, new[] { 0, 42, 0 }, "Content");
			Assert.AreEqual(arr[1], 42, "[1]");
		}
		public void SetNormalArrayWorks() {
			var arr = new Uint32Array(4);
			arr.Set(new uint[] { 3, 6, 7 });
			AssertContent(arr, new[] { 3, 6, 7, 0 }, "Content");
		}
		public void SetNormalArrayWithOffsetWorks() {
			var arr = new Uint32Array(6);
			arr.Set(new uint[] { 3, 6, 7 }, 2);
			AssertContent(arr, new[] { 0, 0, 3, 6, 7, 0 }, "Content");
		}
		public void SubarrayWithBeginAndEndWorks() {
			var source = new Uint32Array(10);
			var arr = source.Subarray(3, 7);
			Assert.IsFalse(arr == source, "Should be a new array");
			Assert.IsTrue(arr.Buffer == source.Buffer, "Should be the same buffer");
			Assert.AreEqual(arr.ByteOffset, 12, "ByteOffset should be correct");
			Assert.AreEqual(arr.Length, 4, "Length should be correct");
		}
		public void ContainsWorks() {
			var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });
			Assert.IsTrue (arr.Contains(9), "9");
			Assert.IsFalse(arr.Contains(1), "1");
		}
		public void IndexOfWorks() {
			var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });
			Assert.AreEqual(arr.IndexOf(9), 3, "9");
			Assert.AreEqual(arr.IndexOf(1), -1, "1");
		}
		public void ByteOffsetPropertyWorks() {
			var buf = new ArrayBuffer(100);
			var arr = new Uint32Array(buf, 32);
			Assert.AreEqual(arr.ByteOffset, 32, "Should be correct");
		}
		public void BufferPropertyWorks() {
			var buf = new ArrayBuffer(100);
			var arr = new Uint32Array(buf);
			Assert.IsTrue(arr.Buffer == buf, "Should be correct");
		}
Example #47
0
 /// <summary>
 /// Creates a new Uint32Array out of the specified Uint32Array.
 /// </summary>
 /// <param name="typedArray">Uint32Array to use as initial contents to the new array.</param>
 public Uint32Array(Uint32Array typedArray)
 {
 }
		public void GetEnumeratorWorks() {
			var arr = new Uint32Array(new uint[] { 3, 6, 2, 9, 5 });
			var l = new List<uint>();
			var enm = arr.GetEnumerator();
			while (enm.MoveNext()) {
				l.Add(enm.Current);
			}
			Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 });
		}