Ejemplo n.º 1
0
 private static void testAllocate()
 {
     // An IllegalArgumentException will be thrown for negative capacities.
     tryCatch((Buffer)null, typeof(ArgumentException), () =>
     {
         SingleBuffer.Allocate(-1);
     });
 }
Ejemplo n.º 2
0
 void assertContentEquals(SingleBuffer buf, float[] array,
                          int offset, int length)
 {
     for (int i = 0; i < length; i++)
     {
         assertEquals(buf.Get(i), array[offset + i], 0.01);
     }
 }
Ejemplo n.º 3
0
 internal void loadTestData2(SingleBuffer buf)
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         buf.Put(i, (float)buf.Capacity - i);
     }
 }
Ejemplo n.º 4
0
        //6231529
        private static void callReset(SingleBuffer b)
        {
            b.Position = (0);
            b.Mark();

            b.Duplicate().Reset();
            b.AsReadOnlyBuffer().Reset();
        }
Ejemplo n.º 5
0
 void assertContentEquals(SingleBuffer buf, SingleBuffer other)
 {
     assertEquals(buf.Capacity, other.Capacity);
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Get(i), other.Get(i), 0.01);
     }
 }
Ejemplo n.º 6
0
 public static void Test()
 {
     testAllocate();
     test(0, SingleBuffer.Allocate(7 * 1024), false);
     test(0, SingleBuffer.Wrap(new float[7 * 1024], 0, 7 * 1024), false);
     test(new float[1024]);
     callReset(SingleBuffer.Allocate(10));
     putBuffer();
 }
Ejemplo n.º 7
0
        void assertContentLikeTestData1(SingleBuffer buf,
                                        int startIndex, float startValue, int length)
        {
            float value = startValue;

            for (int i = 0; i < length; i++)
            {
                assertEquals(buf.Get(startIndex + i), value, 0.01);
                value = value + 1.0f;
            }
        }
Ejemplo n.º 8
0
        private static void relPut(SingleBuffer b)
        {
            int n = b.Capacity;

            b.Clear();
            for (int i = 0; i < n; i++)
            {
                b.Put((float)Ic(i));
            }
            b.Flip();
        }
Ejemplo n.º 9
0
        private static void bulkGet(SingleBuffer b)
        {
            int n = b.Capacity;

            float[] a = new float[n + 7];
            b.Get(a, 7, n);
            for (int i = 0; i < n; i++)
            {
                ck(b, (long)a[i + 7], (long)((float)Ic(i)));
            }
        }
Ejemplo n.º 10
0
        private static void relGet(SingleBuffer b, int start)
        {
            int   n = b.Remaining;
            float v;

            for (int i = start; i < n; i++)
            {
                ck(b, (long)b.Get(), (long)((float)Ic(i)));
            }
            b.Rewind();
        }
Ejemplo n.º 11
0
        private static void absGet(SingleBuffer b)
        {
            int   n = b.Capacity;
            float v;

            for (int i = 0; i < n; i++)
            {
                ck(b, (long)b.Get(), (long)((float)Ic(i)));
            }
            b.Rewind();
        }
 public void TestAllocatedFloatBuffer_IllegalArg()
 {
     try
     {
         SingleBuffer.Allocate(-1);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentException e)
     {
         // expected
     }
 }
Ejemplo n.º 13
0
 private static void checkSlice(SingleBuffer b, SingleBuffer slice)
 {
     ck(slice, 0, slice.Position);
     ck(slice, b.Remaining, slice.Limit);
     ck(slice, b.Remaining, slice.Capacity);
     //if (b.IsDirect != slice.IsDirect) // J2N: IsDirect not supported
     //    fail("Lost direction", slice);
     if (b.IsReadOnly != slice.IsReadOnly)
     {
         fail("Lost read-only", slice);
     }
 }
Ejemplo n.º 14
0
        private static void absPut(SingleBuffer b)
        {
            int n = b.Capacity;

            b.Clear();
            for (int i = 0; i < n; i++)
            {
                b.Put(i, (float)Ic(i));
            }
            b.Limit    = (n);
            b.Position = (0);
        }
Ejemplo n.º 15
0
        public virtual void TestHashCode()
        {
            buf.Clear();
            SingleBuffer @readonly = buf.AsReadOnlyBuffer();
            SingleBuffer duplicate = buf.Duplicate();

            assertTrue(buf.GetHashCode() == @readonly.GetHashCode());

            assertTrue(buf.Capacity > 5);
            duplicate.Position = (buf.Capacity / 2);
            assertTrue(buf.GetHashCode() != duplicate.GetHashCode());
        }
Ejemplo n.º 16
0
        private static void bulkPutArray(SingleBuffer b)
        {
            int n = b.Capacity;

            b.Clear();
            float[] a = new float[n + 7];
            for (int i = 0; i < n; i++)
            {
                a[i + 7] = (float)Ic(i);
            }
            b.Put(a, 7, n);
            b.Flip();
        }
Ejemplo n.º 17
0
        public virtual void TestCompareTo()
        {
            // J2N: Changed the behavior from Java because in .NET CompareTo is supposed to return 1 instead of throwing an exception when passed null
            //try
            //{
            //    buf.CompareTo(null);
            //    fail("Should throw NPE");
            //}
            //catch (ArgumentNullException e)
            //{
            //    // expected
            //}

            // J2N: Cover null for .NET. See: https://stackoverflow.com/a/4852537
            assertEquals(1, buf.CompareTo(null));

            // compare to self
            assertEquals(0, buf.CompareTo(buf));

            // normal cases
            assertTrue(buf.Capacity > 5);
            buf.Clear();
            SingleBuffer other = SingleBuffer.Allocate(buf.Capacity);

            loadTestData1(other);
            assertEquals(0, buf.CompareTo(other));
            assertEquals(0, other.CompareTo(buf));
            buf.Position = (1);
            assertTrue(buf.CompareTo(other) > 0);
            assertTrue(other.CompareTo(buf) < 0);
            other.Position = (2);
            assertTrue(buf.CompareTo(other) < 0);
            assertTrue(other.CompareTo(buf) > 0);
            buf.Position = (2);
            other.Limit  = (5);
            assertTrue(buf.CompareTo(other) > 0);
            assertTrue(other.CompareTo(buf) < 0);

            SingleBuffer fbuffer1 = SingleBuffer.Wrap(new float[] { float.NaN });
            SingleBuffer fbuffer2 = SingleBuffer.Wrap(new float[] { float.NaN });
            SingleBuffer fbuffer3 = SingleBuffer.Wrap(new float[] { 42f });

            assertEquals("Failed equal comparison with NaN entry", 0, fbuffer1
                         .CompareTo(fbuffer2));
            assertEquals("Failed greater than comparison with NaN entry", 1, fbuffer3
                         .CompareTo(fbuffer1));
            assertEquals("Failed less than comparison with NaN entry", -1, fbuffer1 // J2N: Corrected this (Harmony) test to match JDK 7, which expects NaN to be symmetric. This also matches .NET float.CompareTo().
                         .CompareTo(fbuffer3));
        }
Ejemplo n.º 18
0
        private static void bulkPutBuffer(SingleBuffer b)
        {
            int n = b.Capacity;

            b.Clear();
            SingleBuffer c = SingleBuffer.Allocate(n + 7);

            c.Position = (7);
            for (int i = 0; i < n; i++)
            {
                c.Put((float)Ic(i));
            }
            c.Flip();
            c.Position = (7);
            b.Put(c);
            b.Flip();
        }
Ejemplo n.º 19
0
        public virtual void TestCompareTo()
        {
            try
            {
                buf.CompareTo(null);
                fail("Should throw NPE");
            }
            catch (ArgumentNullException e)
            {
                // expected
            }

            // compare to self
            assertEquals(0, buf.CompareTo(buf));

            // normal cases
            assertTrue(buf.Capacity > 5);
            buf.Clear();
            SingleBuffer other = SingleBuffer.Allocate(buf.Capacity);

            loadTestData1(other);
            assertEquals(0, buf.CompareTo(other));
            assertEquals(0, other.CompareTo(buf));
            buf.Position = (1);
            assertTrue(buf.CompareTo(other) > 0);
            assertTrue(other.CompareTo(buf) < 0);
            other.Position = (2);
            assertTrue(buf.CompareTo(other) < 0);
            assertTrue(other.CompareTo(buf) > 0);
            buf.Position = (2);
            other.Limit  = (5);
            assertTrue(buf.CompareTo(other) > 0);
            assertTrue(other.CompareTo(buf) < 0);

            SingleBuffer fbuffer1 = SingleBuffer.Wrap(new float[] { float.NaN });
            SingleBuffer fbuffer2 = SingleBuffer.Wrap(new float[] { float.NaN });
            SingleBuffer fbuffer3 = SingleBuffer.Wrap(new float[] { 42f });

            assertEquals("Failed equal comparison with NaN entry", 0, fbuffer1
                         .CompareTo(fbuffer2));
            assertEquals("Failed greater than comparison with NaN entry", 1, fbuffer3
                         .CompareTo(fbuffer1));
            assertEquals("Failed less than comparison with NaN entry", -1, fbuffer1 // J2N: Corrected this (Harmony) test to match JDK 7, which expects NaN to be symmetric. This also matches .NET float.CompareTo().
                         .CompareTo(fbuffer3));
        }
Ejemplo n.º 20
0
        public virtual void TestPutSingleBuffer()
        {
            SingleBuffer other = SingleBuffer.Allocate(buf.Capacity);

            try
            {
                buf.Put(buf);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentException e)
            {
                // expected
            }
            try
            {
                buf.Put(SingleBuffer.Allocate(buf.Capacity + 1));
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (BufferOverflowException e)
            {
                // expected
            }
            try
            {
                buf.Flip();
                buf.Put((SingleBuffer)null);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentNullException e)
            {
                // expected
            }
            buf.Clear();
            loadTestData2(other);
            other.Clear();
            buf.Clear();
            SingleBuffer ret = buf.Put(other);

            assertEquals(other.Position, other.Capacity);
            assertEquals(buf.Position, buf.Capacity);
            assertContentEquals(other, buf);
            assertSame(ret, buf);
        }
Ejemplo n.º 21
0
 public virtual void TestPutfloat()
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, i);
         SingleBuffer ret = buf.Put((float)i);
         assertEquals(buf.Get(i), (float)i, 0.0);
         assertSame(ret, buf);
     }
     try
     {
         buf.Put(0);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (BufferOverflowException e)
     {
         // expected
     }
 }
Ejemplo n.º 22
0
        public static void test(float[] ba)
        {
            int          offset = 47;
            int          length = 900;
            SingleBuffer b      = SingleBuffer.Wrap(ba, offset, length);

            Show(0, b);
            ck(b, b.Capacity, ba.Length);
            ck(b, b.Position, offset);
            ck(b, b.Limit, offset + length);

            // The offset must be non-negative and no larger than <array.Length>.
            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
            {
                SingleBuffer.Wrap(ba, -1, ba.Length);
            });
            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
            {
                SingleBuffer.Wrap(ba, ba.Length + 1, ba.Length);
            });
            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
            {
                SingleBuffer.Wrap(ba, 0, -1);
            });
            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
            {
                SingleBuffer.Wrap(ba, 0, ba.Length + 1);
            });

            // A NullPointerException will be thrown if the array is null.
            tryCatch(ba, typeof(ArgumentNullException), () =>
            {
                SingleBuffer.Wrap((float[])null, 0, 5);
            });
            tryCatch(ba, typeof(ArgumentNullException), () =>
            {
                SingleBuffer.Wrap((float[])null);
            });
        }
        private static void testViews(int level, ByteBuffer b, bool direct)
        {
            Int16Buffer sb = b.AsInt16Buffer();

            TestInt16Buffer2.test(level, sb, direct);
            checkBytes(b, new byte[] { 0, (byte)Ic(0) });
            checkInvalidMarkException(sb);

            CharBuffer cb = b.AsCharBuffer();

            TestCharBuffer2.test(level, cb, direct);
            checkBytes(b, new byte[] { 0, (byte)Ic(0) });
            checkInvalidMarkException(cb);

            Int32Buffer ib = b.AsInt32Buffer();

            TestInt32Buffer2.test(level, ib, direct);
            checkBytes(b, new byte[] { 0, 0, 0, (byte)Ic(0) });
            checkInvalidMarkException(ib);

            Int64Buffer lb = b.AsInt64Buffer();

            TestInt64Buffer2.test(level, lb, direct);
            checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)Ic(0) });
            checkInvalidMarkException(lb);

            SingleBuffer fb = b.AsSingleBuffer();

            TestSingleBuffer2.test(level, fb, direct);
            checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
            checkInvalidMarkException(fb);

            DoubleBuffer db = b.AsDoubleBuffer();

            TestDoubleBuffer2.test(level, db, direct);
            checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
            checkInvalidMarkException(db);
        }
Ejemplo n.º 24
0
        // 6221101-6234263

        private static void putBuffer()
        {
            int cap = 10;

            // J2N: AllocateDirect not implemented

            //SingleBuffer direct1 = ByteBuffer.AllocateDirect(cap).AsSingleBuffer();
            SingleBuffer nondirect1 = ByteBuffer.Allocate(cap).AsSingleBuffer();
            //direct1.Put(nondirect1);

            //SingleBuffer direct2 = ByteBuffer.AllocateDirect(cap).AsSingleBuffer();
            SingleBuffer nondirect2 = ByteBuffer.Allocate(cap).AsSingleBuffer();
            //nondirect2.Put(direct2);

            //SingleBuffer direct3 = ByteBuffer.AllocateDirect(cap).AsSingleBuffer();
            //SingleBuffer direct4 = ByteBuffer.AllocateDirect(cap).AsSingleBuffer();
            //direct3.Put(direct4);

            SingleBuffer nondirect3 = ByteBuffer.Allocate(cap).AsSingleBuffer();
            SingleBuffer nondirect4 = ByteBuffer.Allocate(cap).AsSingleBuffer();

            nondirect3.Put(nondirect4);
        }
Ejemplo n.º 25
0
        public virtual void TestEquals()
        {
            // equal to self
            assertTrue(buf.Equals(buf));
            SingleBuffer @readonly = buf.AsReadOnlyBuffer();

            assertTrue(buf.Equals(@readonly));
            SingleBuffer duplicate = buf.Duplicate();

            assertTrue(buf.Equals(duplicate));

            // always false, if type mismatch
            assertFalse(buf.Equals(true));

            assertTrue(buf.Capacity > 5);

            buf.SetLimit(buf.Capacity).SetPosition(0);
            @readonly.SetLimit(@readonly.Capacity).SetPosition(1);
            assertFalse(buf.Equals(@readonly));

            buf.SetLimit(buf.Capacity - 1).SetPosition(0);
            duplicate.SetLimit(duplicate.Capacity).SetPosition(0);
            assertFalse(buf.Equals(duplicate));
        }
        public override void TestHashCode()
        {
            SingleBuffer duplicate = buf.Duplicate();

            assertEquals(buf.GetHashCode(), duplicate.GetHashCode());
        }
        public void TestWrappedFloatBuffer_IllegalArg()
        {
            float[] array = new float[20];
            try
            {
                SingleBuffer.Wrap(array, -1, 0);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                SingleBuffer.Wrap(array, 21, 0);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                SingleBuffer.Wrap(array, 0, -1);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                SingleBuffer.Wrap(array, 0, 21);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                SingleBuffer.Wrap(array, int.MaxValue, 1);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                SingleBuffer.Wrap(array, 1, int.MaxValue);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                SingleBuffer.Wrap((float[])null, -1, 0);
                fail("Should throw NPE"); //$NON-NLS-1$
            }
            catch (ArgumentNullException e)
            {
            }

            SingleBuffer buf = SingleBuffer.Wrap(array, 2, 16);

            assertEquals(buf.Position, 2);
            assertEquals(buf.Limit, 18);
            assertEquals(buf.Capacity, 20);
        }
Ejemplo n.º 28
0
        public virtual void TestPutfloatArrayintint()
        {
            buf.Clear();
            float[] array = new float[buf.Capacity];
            try
            {
                buf.Put(new float[buf.Capacity + 1], 0, buf.Capacity + 1);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (BufferOverflowException e)
            {
                // expected
            }
            assertEquals(buf.Position, 0);
            try
            {
                buf.Put(array, -1, array.Length);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                buf.Put(array, array.Length + 1, 0);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            buf.Put(array, array.Length, 0);
            assertEquals(buf.Position, 0);
            try
            {
                buf.Put(array, 0, -1);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                buf.Put((float[])null, 0, -1);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentNullException e)
            {
                // expected
            }
            try
            {
                buf.Put(array, 2, array.Length);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                buf.Put(array, int.MaxValue, 1);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            try
            {
                buf.Put(array, 1, int.MaxValue);
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
            assertEquals(buf.Position, 0);

            loadTestData2(array, 0, array.Length);
            SingleBuffer ret = buf.Put(array, 0, array.Length);

            assertEquals(buf.Position, buf.Capacity);
            assertContentEquals(buf, array, 0, array.Length);
            assertSame(ret, buf);
        }
Ejemplo n.º 29
0
 public override void TearDown()
 {
     buf     = null;
     baseBuf = null;
 }
Ejemplo n.º 30
0
 public override void SetUp()
 {
     buf = SingleBuffer.Allocate(BUFFER_LENGTH);
     loadTestData1(buf);
     baseBuf = buf;
 }