Example #1
0
            public void Write(int length, int start, int index)
            {
                TestStructs.Foo[]      a    = TestStructs.Foo.CreateArray(length);
                Span <TestStructs.Foo> span = new Span <TestStructs.Foo>(a, start);

                span[index] = new TestStructs.Foo(666, 666);

                Assert.Equal(new TestStructs.Foo(666, 666), a[start + index]);
            }
Example #2
0
            public void Read(int length, int start, int index)
            {
                TestStructs.Foo[]      a    = TestStructs.Foo.CreateArray(length);
                Span <TestStructs.Foo> span = new Span <TestStructs.Foo>(a, start);

                TestStructs.Foo element = span[index];

                Assert.Equal(a[start + index], element);
            }
Example #3
0
            internal static bool ElementsAreEqual(TestStructs.Foo[] array, byte[] rawArray, int index)
            {
                fixed(TestStructs.Foo *pArray = array)
                fixed(byte *pRaw = rawArray)
                {
                    TestStructs.Foo *pCasted = (TestStructs.Foo *)pRaw;

                    TestStructs.Foo val1 = pArray[index];
                    TestStructs.Foo val2 = pCasted[index];

                    return(val1.Equals(val2));
                }
            }
Example #4
0
            public void GenericToOwnType(int count)
            {
                TestStructs.Foo[] source = TestStructs.Foo.CreateArray(count + 2);
                TestStructs.Foo[] dest   = new TestStructs.Foo[count + 5];

                var apSource = new Span <TestStructs.Foo>(source, 1, source.Length - 1);
                var apDest   = new Span <TestStructs.Foo>(dest, 1, dest.Length - 1);

                apSource.Slice(0, count - 1).CopyTo(apDest);

                AssertNotDefault(source, 1);
                AssertNotDefault(dest, 1);

                Assert.NotEqual(source[0], dest[0]);
                Assert.Equal(source[1], dest[1]);
                Assert.Equal(source[2], dest[2]);
                Assert.Equal(source[count - 1], dest[count - 1]);
                Assert.NotEqual(source[count], dest[count]);
            }
Example #5
0
            public void BytesToGeneric(int count)
            {
                int srcCount = count * sizeof(TestStructs.Foo);

                byte[] source = CreateTestBytes(srcCount);
                var    dest   = new TestStructs.Foo[count + 2];

                var apSource = new Span <byte>(source);
                var apDest   = new Span <TestStructs.Foo>(dest);

                apSource.Slice(0, count * sizeof(TestStructs.Foo)).CopyTo(apDest.AsBytes());

                AssertNotDefault(source, sizeof(TestStructs.Foo) + 1);
                AssertNotDefault(dest, 1);

                Assert.True((bool)ElementsAreEqual(dest, source, 0));
                Assert.True((bool)ElementsAreEqual(dest, source, 1));
                Assert.True((bool)ElementsAreEqual(dest, source, count - 1));
                Assert.False((bool)ElementsAreEqual(dest, source, count));
            }