public override void TestPutInt64Buffer()
        {
            Int64Buffer other = Int64Buffer.Allocate(1);

            try
            {
                buf.Put(other);
                fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
            }
            catch (ReadOnlyBufferException e)
            {
                // expected
            }
            try
            {
                buf.Put((Int64Buffer)null);
                fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
            }
            catch (ReadOnlyBufferException e)
            {
                // expected
            }
            try
            {
                buf.Put(buf);
                fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
            }
            catch (ReadOnlyBufferException e)
            {
                // expected
            }
        }
 public override void SetUp()
 {
     base.SetUp();
     buf = Int64Buffer.Wrap(new long[BUFFER_LENGTH]);
     loadTestData1(buf);
     baseBuf = buf;
 }
 public virtual void TestPutlongArray()
 {
     long[] array = new long[1];
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, i);
         array[0] = (long)i;
         Int64Buffer ret = buf.Put(array);
         assertEquals(buf.Get(i), (long)i);
         assertSame(ret, buf);
     }
     try
     {
         buf.Put(array);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (BufferOverflowException e)
     {
         // expected
     }
     try
     {
         buf.Position = (buf.Limit);
         buf.Put((long[])null);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentNullException e)
     {
         // expected
     }
 }
        public virtual void TestSlice()
        {
            assertTrue(buf.Capacity > 5);
            buf.Position = (1);
            buf.Limit    = (buf.Capacity - 1);

            Int64Buffer slice = buf.Slice();

            assertEquals(buf.IsReadOnly, slice.IsReadOnly);
            //assertEquals(buf.IsDirect, slice.IsDirect); // J2N: IsDirect not supported
            assertEquals(buf.Order, slice.Order);
            assertEquals(slice.Position, 0);
            assertEquals(slice.Limit, buf.Remaining);
            assertEquals(slice.Capacity, buf.Remaining);
            try
            {
                slice.Reset();
                fail("Should throw Exception"); //$NON-NLS-1$
            }
            catch (InvalidMarkException e)
            {
                // expected
            }

            // slice share the same content with buf
            if (!slice.IsReadOnly)
            {
                loadTestData1(slice);
                assertContentLikeTestData1(buf, 1, 0, slice.Capacity);
                buf.Put(2, 500);
                assertEquals(slice.Get(1), 500);
            }
        }
        public virtual void TestDuplicate()
        {
            buf.Clear();
            buf.Mark();
            buf.Position = (buf.Limit);

            // duplicate's contents should be the same as buf
            Int64Buffer duplicate = buf.Duplicate();

            assertNotSame(buf, duplicate);
            assertEquals(buf.Position, duplicate.Position);
            assertEquals(buf.Limit, duplicate.Limit);
            assertEquals(buf.IsReadOnly, duplicate.IsReadOnly);
            //assertEquals(buf.IsDirect, duplicate.IsDirect); // J2N: IsDirect not supported
            assertEquals(buf.Order, duplicate.Order);
            assertContentEquals(buf, duplicate);

            // duplicate's position, mark, and limit should be independent to buf
            duplicate.Reset();
            assertEquals(duplicate.Position, 0);
            duplicate.Clear();
            assertEquals(buf.Position, buf.Limit);
            buf.Reset();
            assertEquals(buf.Position, 0);

            // duplicate share the same content with buf
            if (!duplicate.IsReadOnly)
            {
                loadTestData1(buf);
                assertContentEquals(buf, duplicate);
                loadTestData2(duplicate);
                assertContentEquals(buf, duplicate);
            }
        }
 public override void SetUp()
 {
     base.SetUp();
     buf = Int64Buffer.Allocate(BUFFER_LENGTH);
     loadTestData1(buf);
     baseBuf = buf;
 }
Exemplo n.º 7
0
        public virtual void TestCompareTo()
        {
            // compare to self
            assertEquals(0, buf.CompareTo(buf));

            // normal cases
            assertTrue(buf.Capacity > 5);
            buf.Clear();
            Int64Buffer other = Int64Buffer.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);

            // J2N: Cover null for .NET. See: https://stackoverflow.com/a/4852537
            assertEquals(1, buf.CompareTo(null));
        }
 public virtual void TestPutintlong()
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, 0);
         Int64Buffer ret = buf.Put(i, (long)i);
         assertEquals(buf.Get(i), (long)i);
         assertSame(ret, buf);
     }
     try
     {
         buf.Put(-1, 0);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentOutOfRangeException e)
     {
         // expected
     }
     try
     {
         buf.Put(buf.Limit, 0);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentOutOfRangeException e)
     {
         // expected
     }
 }
        public virtual void TestAsReadOnlyBuffer()
        {
            buf.Clear();
            buf.Mark();
            buf.Position = (buf.Limit);

            // readonly's contents should be the same as buf
            Int64Buffer @readonly = buf.AsReadOnlyBuffer();

            assertNotSame(buf, @readonly);
            assertTrue(@readonly.IsReadOnly);
            assertEquals(buf.Position, @readonly.Position);
            assertEquals(buf.Limit, @readonly.Limit);
            //assertEquals(buf.IsDirect, @readonly.IsDirect); // J2N: IsDirect not supported
            assertEquals(buf.Order, @readonly.Order);
            assertContentEquals(buf, @readonly);

            // readonly's position, mark, and limit should be independent to buf
            @readonly.Reset();
            assertEquals(@readonly.Position, 0);
            @readonly.Clear();
            assertEquals(buf.Position, buf.Limit);
            buf.Reset();
            assertEquals(buf.Position, 0);
        }
 void assertContentEquals(Int64Buffer buf, Int64Buffer other)
 {
     assertEquals(buf.Capacity, other.Capacity);
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Get(i), other.Get(i));
     }
 }
 internal void loadTestData2(Int64Buffer buf)
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         buf.Put(i, (long)buf.Capacity - i);
     }
 }
Exemplo n.º 12
0
 public static void TestAllocate()
 {
     // An IllegalArgumentException will be thrown for negative capacities.
     tryCatch((Buffer)null, typeof(ArgumentException), () =>
     {
         Int64Buffer.Allocate(-1);
     });
 }
 void assertContentEquals(Int64Buffer buf, long[] array,
                          int offset, int length)
 {
     for (int i = 0; i < length; i++)
     {
         assertEquals(buf.Get(i), array[offset + i]);
     }
 }
Exemplo n.º 14
0
        //6231529
        private static void callReset(Int64Buffer b)
        {
            b.Position = (0);
            b.Mark();

            b.Duplicate().Reset();
            b.AsReadOnlyBuffer().Reset();
        }
Exemplo n.º 15
0
        public static void Test()
        {
            TestAllocate();
            test(0, Int64Buffer.Allocate(7 * 1024), false);
            test(0, Int64Buffer.Wrap(new long[7 * 1024], 0, 7 * 1024), false);
            test(new long[1024]);

            callReset(Int64Buffer.Allocate(10));
            putBuffer();
        }
Exemplo n.º 16
0
        private static void absGet(Int64Buffer b)
        {
            int n = b.Capacity;

            for (int i = 0; i < n; i++)
            {
                ck(b, (long)b.Get(), (long)((long)Ic(i)));
            }
            b.Rewind();
        }
Exemplo n.º 17
0
        private static void relGet(Int64Buffer b, int start)
        {
            int n = b.Remaining;

            for (int i = start; i < n; i++)
            {
                ck(b, (long)b.Get(), (long)((long)Ic(i)));
            }
            b.Rewind();
        }
Exemplo n.º 18
0
        private static void relPut(Int64Buffer b)
        {
            int n = b.Capacity;

            b.Clear();
            for (int i = 0; i < n; i++)
            {
                b.Put((long)Ic(i));
            }
            b.Flip();
        }
        void assertContentLikeTestData1(Int64Buffer buf,
                                        int startIndex, long startValue, int length)
        {
            long value = startValue;

            for (int i = 0; i < length; i++)
            {
                assertEquals(buf.Get(startIndex + i), value);
                value = value + 1;
            }
        }
Exemplo n.º 20
0
        private static void bulkGet(Int64Buffer b)
        {
            int n = b.Capacity;

            long[] a = new long[n + 7];
            b.Get(a, 7, n);
            for (int i = 0; i < n; i++)
            {
                ck(b, (long)a[i + 7], (long)((long)Ic(i)));
            }
        }
 public void TestAllocatedLongBuffer_IllegalArg()
 {
     try
     {
         Int64Buffer.Allocate(-1);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentException e)
     {
         // expected
     }
 }
Exemplo n.º 22
0
        private static void absPut(Int64Buffer b)
        {
            int n = b.Capacity;

            b.Clear();
            for (int i = 0; i < n; i++)
            {
                b.Put(i, (long)Ic(i));
            }
            b.Limit    = (n);
            b.Position = (0);
        }
Exemplo n.º 23
0
 private static void checkSlice(Int64Buffer b, Int64Buffer 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 implemented
     //    fail("Lost direction", slice);
     if (b.IsReadOnly != slice.IsReadOnly)
     {
         fail("Lost read-only", slice);
     }
 }
        public virtual void TestHashCode()
        {
            buf.Clear();
            Int64Buffer @readonly = buf.AsReadOnlyBuffer();
            Int64Buffer duplicate = buf.Duplicate();

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

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

            b.Clear();
            long[] a = new long[n + 7];
            for (int i = 0; i < n; i++)
            {
                a[i + 7] = (long)Ic(i);
            }
            b.Put(a, 7, n);
            b.Flip();
        }
Exemplo n.º 26
0
        private static void bulkPutBuffer(Int64Buffer b)
        {
            int n = b.Capacity;

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

            c.Position = (7);
            for (int i = 0; i < n; i++)
            {
                c.Put((long)Ic(i));
            }
            c.Flip();
            c.Position = (7);
            b.Put(c);
            b.Flip();
        }
        public virtual void TestPutInt64Buffer()
        {
            Int64Buffer other = Int64Buffer.Allocate(buf.Capacity);

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

            loadTestData2(other);
            other.Clear();
            buf.Clear();
            Int64Buffer ret = buf.Put(other);

            assertEquals(other.Position, other.Capacity);
            assertEquals(buf.Position, buf.Capacity);
            assertContentEquals(other, buf);
            assertSame(ret, buf);
        }
 public virtual void TestPutlong()
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, i);
         Int64Buffer ret = buf.Put((long)i);
         assertEquals(buf.Get(i), (long)i);
         assertSame(ret, buf);
     }
     try
     {
         buf.Put(0);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (BufferOverflowException e)
     {
         // expected
     }
 }
Exemplo n.º 29
0
        public static void test(long[] ba)
        {
            int         offset = 47;
            int         length = 900;
            Int64Buffer b      = Int64Buffer.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), () =>
            {
                Int64Buffer.Wrap(ba, -1, ba.Length);
            });
            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
            {
                Int64Buffer.Wrap(ba, ba.Length + 1, ba.Length);
            });
            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
            {
                Int64Buffer.Wrap(ba, 0, -1);
            });
            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
            {
                Int64Buffer.Wrap(ba, 0, ba.Length + 1);
            });

            // A NullPointerException will be thrown if the array is null.
            tryCatch(ba, typeof(ArgumentNullException), () =>
            {
                Int64Buffer.Wrap((long[])null, 0, 5);
            });
            tryCatch(ba, typeof(ArgumentNullException), () =>
            {
                Int64Buffer.Wrap((long[])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);
        }