public void ContainsWorks() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); Assert.IsTrue(arr.Contains(9), "9"); Assert.IsFalse(arr.Contains(1), "1"); }
public void SetNormalArrayWithOffsetWorks() { var arr = new Int8Array(6); arr.Set(new sbyte[] { 3, 6, 7 }, 2); AssertContent(arr, new[] { 0, 0, 3, 6, 7, 0 }, "Content"); }
public void SetNormalArrayWorks() { var arr = new Int8Array(4); arr.Set(new sbyte[] { 3, 6, 7 }); AssertContent(arr, new[] { 3, 6, 7, 0 }, "Content"); }
public void BufferPropertyWorks() { var buf = new ArrayBuffer(100); var arr = new Int8Array(buf); Assert.True(arr.Buffer == buf, "Should be correct"); }
public void CopyConstructorWorks() { var source = new Int8Array(new sbyte[] { 3, 8, 4 }); var arr = new Int8Array(source); Assert.IsTrue(arr != source, "New object"); Assert.IsTrue((object)arr is Int8Array, "is Int8Array"); AssertContent(arr, new[] { 3, 8, 4 }, "content"); }
public void IndexOfWorks() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); Assert.AreEqual(3, arr.IndexOf(9), "9"); Assert.AreEqual(-1, arr.IndexOf(1), "1"); }
public void ByteOffsetPropertyWorks() { var buf = new ArrayBuffer(100); var arr = new Int8Array(buf, 32); Assert.AreEqual(32, arr.ByteOffset, "Should be correct"); }
public void LengthConstructorWorks() { var arr = new Int8Array(13); Assert.True((object)arr is Int8Array, "is Int8Array"); Assert.AreEqual(13, arr.Length, "Length"); }
public void ArrayBufferWithOffsetConstructorWorks() { var buf = new ArrayBuffer(80); var arr = new Int8Array(buf, 16); Assert.IsTrue((object)arr is Int8Array); Assert.IsTrue(arr.Buffer == buf, "buffer"); Assert.AreEqual(arr.Length, 64, "length"); }
public void ICollectionCopyTo() { ICollection <sbyte> l = new Int8Array(new sbyte[] { 0, 1, 2 }); var a1 = new sbyte[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 sbyte[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 sbyte[2]; Assert.Throws <ArgumentException>(() => { l.CopyTo(a3, 0); }, "3.Short array"); var a4 = new sbyte[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"); }
public static void Int8ArrayFromArrayBuffer(Function objectPrototype) { Int8Array from = new Int8Array(new ArrayBuffer(50)); Assert.True(from.Length == 50); Assert.Equal("[object Int8Array]", objectPrototype.Call(from)); }
public void Int8SetArrayOutOfRange() { var buffer = new ArrayBuffer(4); var i8 = new Int8Array(buffer); Assert.Throws <ArgumentException>(() => i8.Set(new sbyte[] { 1, 2, 3, 4 }, 1)); }
public static void Int8ArrayFrom(Function objectPrototype) { var array = new sbyte[50]; Int8Array from = Int8Array.From(array); Assert.Equal(50, from.Length); Assert.Equal("[object Int8Array]", objectPrototype.Call(from)); }
public void IndexingWorks() { var arr = new Int8Array(3); arr[1] = 42; AssertContent(arr, new[] { 0, 42, 0 }, "Content"); Assert.AreEqual(42, arr[1], "[1]"); }
public void Int8SetArray() { var buffer = new ArrayBuffer(4); var i8 = new Int8Array(buffer); i8.Set(new sbyte[] { 1, 2, 3 }, 1); CollectionAssert.AreEqual(new[] { 0, 1, 2, 3 }, buffer.Data); }
public void Sharing() { var buf = new ArrayBuffer(2); var i8 = new Int8Array(buf); var i16 = new Int16Array(buf); i8 [1] = 1; Assert.AreEqual(256, i16 [0]); }
public void ArrayBufferWithOffsetConstructorWorks() { var buf = new ArrayBuffer(80); var arr = new Int8Array(buf, 16); Assert.True((object)arr is Int8Array); Assert.True(arr.Buffer == buf, "buffer"); Assert.AreEqual(64, arr.Length, "length"); }
public void ConstructorFromIntWorks() { var source = new sbyte[] { 3, 8, 4 }; var arr = new Int8Array(source); Assert.IsTrue((object)arr != (object)source, "New object"); Assert.IsTrue((object)arr is Int8Array, "is Int8Array"); AssertContent(arr, new[] { 3, 8, 4 }, "content"); }
public void CopyConstructorWorks() { var source = new Int8Array(new sbyte[] { 3, 8, 4 }); var arr = new Int8Array(source); Assert.True(arr != source, "New object"); Assert.True((object)arr is Int8Array, "is Int8Array"); AssertContent(arr, new[] { 3, 8, 4 }, "content"); }
public void SubarrayWithBeginWorks() { var source = new Int8Array(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(3, arr.ByteOffset, "ByteOffset should be correct"); }
public void ArrayBufferConstructorWorks() { var buf = new ArrayBuffer(80); var arr = new Int8Array(buf); Assert.IsTrue((object)arr is Int8Array); Assert.IsTrue(arr.Buffer == buf, "buffer"); Assert.AreEqual(arr.Length, 80, "length"); }
public void SubarrayWithBeginAndEndWorks() { var source = new Int8Array(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, 3, "ByteOffset should be correct"); Assert.AreEqual(arr.Length, 4, "Length should be correct"); }
private string getJsonFromMessage(object evt) { if (evt.data is ArrayBuffer) { var dataArray = new Int8Array(evt.data); var jsonStr = this.ab2str(dataArray); return(jsonStr); } return(null); }
public void ForeachWorks() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); var l = new List <int>(); foreach (var i in arr) { l.Add(i); } Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 }); }
public void GetEnumeratorWorks() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); var l = new List <int>(); var enm = arr.GetEnumerator(); while (enm.MoveNext()) { l.Add(enm.Current); } Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 }); }
public void ForeachWorks_SPI_1401() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); var l = new List <int>(); // #1401 foreach (var i in arr) { l.Add(i); } Assert.AreEqual(l.ToArray(), new[] { 3, 6, 2, 9, 5 }); }
private void AssertContent(Int8Array 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); }
public void TypePropertiesAreCorrect() { Assert.AreEqual(typeof(Int8Array).FullName, "Int8Array", "FullName"); var interfaces = typeof(Int8Array).GetInterfaces(); Assert.AreEqual(interfaces.Length, 3, "Interface count should be 3"); Assert.IsTrue(interfaces.Contains(typeof(IEnumerable<sbyte>)), "Interfaces should contain IEnumerable<sbyte>"); Assert.IsTrue(interfaces.Contains(typeof(ICollection<sbyte>)), "Interfaces should contain ICollection<sbyte>"); Assert.IsTrue(interfaces.Contains(typeof(IList<sbyte>)), "Interfaces should contain IList<sbyte>"); object arr = new Int8Array(0); Assert.IsTrue(arr is Int8Array, "Is Int8Array"); Assert.IsTrue(arr is IEnumerable<sbyte>, "Is IEnumerable<sbyte>"); Assert.IsTrue(arr is ICollection<sbyte>, "Is ICollection<sbyte>"); Assert.IsTrue(arr is IList<sbyte>, "Is IList<sbyte>"); }
private void AssertContent(Int8Array 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); }
public void TypePropertiesAreCorrect() { Assert.AreEqual(typeof(Int8Array).FullName, "Int8Array", "FullName"); var interfaces = typeof(Int8Array).GetInterfaces(); Assert.AreEqual(interfaces.Length, 3, "Interface count should be 3"); Assert.IsTrue(interfaces.Contains(typeof(IEnumerable <sbyte>)), "Interfaces should contain IEnumerable<sbyte>"); Assert.IsTrue(interfaces.Contains(typeof(ICollection <sbyte>)), "Interfaces should contain ICollection<sbyte>"); Assert.IsTrue(interfaces.Contains(typeof(IList <sbyte>)), "Interfaces should contain IList<sbyte>"); object arr = new Int8Array(0); Assert.IsTrue(arr is Int8Array, "Is Int8Array"); Assert.IsTrue(arr is IEnumerable <sbyte>, "Is IEnumerable<sbyte>"); Assert.IsTrue(arr is ICollection <sbyte>, "Is ICollection<sbyte>"); Assert.IsTrue(arr is IList <sbyte>, "Is IList<sbyte>"); }
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); }
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 TypePropertiesAreCorrect_SPI_1559() { Assert.AreEqual("Int8Array", typeof(Int8Array).FullName, "FullName"); var interfaces = typeof(Int8Array).GetInterfaces(); Assert.AreEqual(1, interfaces.Length, "Interface count should be 5"); Assert.True(interfaces.Contains(typeof(IEnumerable <sbyte>)), "Interfaces should contain IEnumerable<sbyte>"); Assert.False(interfaces.Contains(typeof(ICollection <sbyte>)), "Interfaces should contain ICollection<sbyte>"); Assert.False(interfaces.Contains(typeof(IList <sbyte>)), "Interfaces should contain IList<sbyte>"); // Not JS API //Assert.True(interfaces.Contains(typeof(IReadOnlyCollection<sbyte>)), "Interfaces should contain IReadOnlyCollection<sbyte>"); //Assert.True(interfaces.Contains(typeof(IReadOnlyList<sbyte>)), "Interfaces should contain IReadOnlyList<sbyte>"); object arr = new Int8Array(0); Assert.True(arr is Int8Array, "Is Int8Array"); Assert.True(arr is IEnumerable <sbyte>, "Is IEnumerable<sbyte>"); Assert.False(arr is ICollection <sbyte>, "Is ICollection<sbyte>"); Assert.False(arr is IList <sbyte>, "Is IList<sbyte>"); // Not JS API //Assert.True(arr is IReadOnlyCollection<sbyte>, "Is IReadOnlyCollection<sbyte>"); //Assert.True(arr is IReadOnlyList<sbyte>, "Is IReadOnlyList<sbyte>"); }
public void ResponseTypeArrayBuffer() { var sync = new Object(); var resourceProvider = Mocks.ResourceProvider("http://data", new byte[] { 10, 1, 0 }); var xhr = new XmlHttpRequest(resourceProvider, () => sync, null, (s, s1) => new Request(s1, UriHelper.GetUri(s))); xhr.Open("GET", "http://data", false); xhr.ResponseType = "arraybuffer"; xhr.Send(); Assert.IsInstanceOf <ArrayBuffer>(xhr.Response); var buffer = (ArrayBuffer)xhr.Response; Assert.AreEqual(3, buffer.ByteLength); var barr = new Int8Array(buffer); Assert.AreEqual(10, barr[0]); Assert.AreEqual(1, barr[1]); Assert.AreEqual(0, barr[2]); Assert.Throws <Exception>(() => { var x = xhr.ResponseText; }); }
public void BufferPropertyWorks() { var buf = new ArrayBuffer(100); var arr = new Int8Array(buf); Assert.IsTrue(arr.Buffer == buf, "Should be correct"); }
public void ByteOffsetPropertyWorks() { var buf = new ArrayBuffer(100); var arr = new Int8Array(buf, 32); Assert.AreEqual(arr.ByteOffset, 32, "Should be correct"); }
public void IndexOfWorks() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); Assert.AreEqual(arr.IndexOf(9), 3, "9"); Assert.AreEqual(arr.IndexOf(1), -1, "1"); }
public void ContainsWorks() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); Assert.IsTrue (arr.Contains(9), "9"); Assert.IsFalse(arr.Contains(1), "1"); }
public void ForeachWorks() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); var l = new List<int>(); foreach (var i in arr) { l.Add(i); } Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 }); }
public void LengthWorks() { var arr = new Int8Array(13); Assert.AreEqual(arr.Length, 13, "Length"); }
public void GetEnumeratorWorks() { var arr = new Int8Array(new sbyte[] { 3, 6, 2, 9, 5 }); var l = new List<int>(); var enm = arr.GetEnumerator(); while (enm.MoveNext()) { l.Add(enm.Current); } Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 }); }
public void LengthConstructorWorks() { var arr = new Int8Array(13); Assert.IsTrue((object)arr is Int8Array, "is Int8Array"); Assert.AreEqual(arr.Length, 13, "Length"); }
public void IndexingWorks() { var arr = new Int8Array(3); arr[1] = 42; AssertContent(arr, new[] { 0, 42, 0 }, "Content"); Assert.AreEqual(arr[1], 42, "[1]"); }
public bool Get(string name, Int8Array data) { var ss = new ScriptString(name); return Global_GetAnyData(ss.ThisPtr, data.ThisPtr); }
public void ByteLengthPropertyWorks() { var arr = new Int8Array(23); Assert.AreEqual(arr.ByteLength, 23, "Should be correct"); }