Exemple #1
0
        public void DataBufferAllocTest()
        {
            using (IGorgonPointer buffer = new GorgonPointer(666))
            {
                byte[] expected = new byte[666];
                byte[] actual   = new byte[666];

                Assert.AreEqual(666, buffer.Size);

                for (int i = 0; i < expected.Length; ++i)
                {
                    expected[i] = 0;
                }

                _rnd.NextBytes(actual);

                for (int i = 0; i < 262144; i++)
                {
                    buffer.Zero();
                }

                buffer.ReadRange(0, actual);

                Assert.IsTrue(actual.SequenceEqual(expected));

                for (int i = 0; i < expected.Length; ++i)
                {
                    expected[i] = 0x23;
                }

                buffer.Fill(0x23);

                buffer.ReadRange(0, actual);

                Assert.IsTrue(actual.SequenceEqual(expected));

                buffer.Zero();

                for (int i = 0; i < expected.Length; ++i)
                {
                    if ((i < 50) || (i > 127))
                    {
                        expected[i] = 0x0;
                    }
                    else
                    {
                        expected[i] = 0xAA;
                    }
                }

                buffer.Fill(0xAA, 78, 50);

                buffer.ReadRange(0, actual);

                Assert.IsTrue(actual.SequenceEqual(expected));
            }
        }
Exemple #2
0
        public void DataBufferReadWriteValueTest()
        {
            var expected = new Vector4(1, 2, 3, 4);

            using (IGorgonPointer buffer = new GorgonPointerTyped <Vector4>())
            {
                buffer.Write(ref expected);

                Vector4 actual = buffer.Read <Vector4>();

                Assert.AreEqual(expected, actual);
            }

            for (int i = 0; i < _vectors.Length; ++i)
            {
                _vectors[i] = new Vector2(i * 2, ((i * 2) + 1));
            }

            using (IGorgonPointer buffer = new GorgonPointer(Vector2.SizeInBytes * _vectors.Length))
            {
                buffer.WriteRange(_vectors, 16, 1);

                Vector2 value = buffer.Read <Vector2>();

                Assert.IsTrue(_vectors[16].X.EqualsEpsilon(value.X));
                Assert.IsTrue(_vectors[16].Y.EqualsEpsilon(value.Y));

                buffer.WriteRange(_vectors);

                value = buffer.Read <Vector2>();

                Assert.IsTrue(_vectors[0].X.EqualsEpsilon(value.X));
                Assert.IsTrue(_vectors[0].Y.EqualsEpsilon(value.Y));

                value = buffer.Read <Vector2>(Vector2.SizeInBytes * 12);

                Assert.IsTrue(_vectors[12].X.EqualsEpsilon(value.X));
                Assert.IsTrue(_vectors[12].Y.EqualsEpsilon(value.Y));

                value = buffer.Read <Vector2>(Vector2.SizeInBytes * (_vectors.Length - 1));

                Assert.IsTrue(_vectors[_vectors.Length - 1].X.EqualsEpsilon(value.X));
                Assert.IsTrue(_vectors[_vectors.Length - 1].Y.EqualsEpsilon(value.Y));

                float[] values = new float[_vectors.Length * 2];
                buffer.ReadRange(values);

                for (int i = 0; i < _vectors.Length; ++i)
                {
                    Assert.IsTrue(_vectors[i].X.EqualsEpsilon(values[i * 2]));
                    Assert.IsTrue(_vectors[i].Y.EqualsEpsilon(values[(i * 2) + 1]));
                }
            }
        }