コード例 #1
0
        public virtual void TestDuplicate()
        {
            buf.Clear();
            buf.Mark();
            buf.Position = (buf.Limit);

            // duplicate's contents should be the same as buf
            Int32Buffer 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);
            }
        }
コード例 #2
0
 public override void SetUp()
 {
     base.SetUp();
     buf = Int32Buffer.Allocate(BUFFER_LENGTH);
     loadTestData1(buf);
     baseBuf = buf;
 }
コード例 #3
0
 public override void SetUp()
 {
     base.SetUp();
     buf = Int32Buffer.Wrap(new int[BUFFER_LENGTH]);
     loadTestData1(buf);
     baseBuf = buf;
 }
コード例 #4
0
        public virtual void TestSlice()
        {
            assertTrue(buf.Capacity > 5);
            buf.Position = (1);
            buf.Limit    = (buf.Capacity - 1);

            Int32Buffer 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);
            }
        }
コード例 #5
0
        public virtual void TestAsReadOnlyBuffer()
        {
            buf.Clear();
            buf.Mark();
            buf.Position = (buf.Limit);

            // readonly's contents should be the same as buf
            Int32Buffer @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);
        }
コード例 #6
0
 public virtual void TestPutintint()
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, 0);
         Int32Buffer ret = buf.Put(i, (int)i);
         assertEquals(buf.Get(i), (int)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
     }
 }
コード例 #7
0
        public virtual void TestCompareTo()
        {
            // compare to self
            assertEquals(0, buf.CompareTo(buf));

            // normal cases
            assertTrue(buf.Capacity > 5);
            buf.Clear();
            Int32Buffer other = Int32Buffer.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));
        }
コード例 #8
0
 public virtual void TestPutintArray()
 {
     int[] array = new int[1];
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, i);
         array[0] = (int)i;
         Int32Buffer ret = buf.Put(array);
         assertEquals(buf.Get(i), (int)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((int[])null);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentNullException e)
     {
         // expected
     }
 }
コード例 #9
0
        public override void TestPutInt32Buffer()
        {
            Int32Buffer other = Int32Buffer.Allocate(1);

            try
            {
                buf.Put(other);
                fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
            }
            catch (ReadOnlyBufferException e)
            {
                // expected
            }
            try
            {
                buf.Put((Int32Buffer)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
            }
        }
コード例 #10
0
 void assertContentEquals(Int32Buffer buf, int[] array,
                          int offset, int length)
 {
     for (int i = 0; i < length; i++)
     {
         assertEquals(buf.Get(i), array[offset + i]);
     }
 }
コード例 #11
0
 internal void loadTestData2(Int32Buffer buf)
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         buf.Put(i, (int)buf.Capacity - i);
     }
 }
コード例 #12
0
 private static void TestAllocate()
 {
     // An IllegalArgumentException will be thrown for negative capacities.
     tryCatch((Buffer)null, typeof(ArgumentException), () =>
     {
         Int32Buffer.Allocate(-1);
     });
 }
コード例 #13
0
 void assertContentEquals(Int32Buffer buf, Int32Buffer other)
 {
     assertEquals(buf.Capacity, other.Capacity);
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Get(i), other.Get(i));
     }
 }
コード例 #14
0
        //6231529
        private static void callReset(Int32Buffer b)
        {
            b.Position = (0);
            b.Mark();

            b.Duplicate().Reset();
            b.AsReadOnlyBuffer().Reset();
        }
コード例 #15
0
 public static void Test()
 {
     TestAllocate();
     test(0, Int32Buffer.Allocate(7 * 1024), false);
     test(0, Int32Buffer.Wrap(new int[7 * 1024], 0, 7 * 1024), false);
     test(new int[1024]);
     callReset(Int32Buffer.Allocate(10));
     putBuffer();
 }
コード例 #16
0
        private static void absGet(Int32Buffer b)
        {
            int n = b.Capacity;
            int v;

            for (int i = 0; i < n; i++)
            {
                ck(b, (long)b.Get(), (long)((int)Ic(i)));
            }
            b.Rewind();
        }
コード例 #17
0
        private static void relGet(Int32Buffer b, int start)
        {
            int n = b.Remaining;
            int v;

            for (int i = start; i < n; i++)
            {
                ck(b, (long)b.Get(), (long)((int)Ic(i)));
            }
            b.Rewind();
        }
コード例 #18
0
        private static void bulkGet(Int32Buffer b)
        {
            int n = b.Capacity;

            int[] a = new int[n + 7];
            b.Get(a, 7, n);
            for (int i = 0; i < n; i++)
            {
                ck(b, (long)a[i + 7], (long)((int)Ic(i)));
            }
        }
コード例 #19
0
        private static void relPut(Int32Buffer b)
        {
            int n = b.Capacity;

            b.Clear();
            for (int i = 0; i < n; i++)
            {
                b.Put((int)Ic(i));
            }
            b.Flip();
        }
コード例 #20
0
        void assertContentLikeTestData1(Int32Buffer buf,
                                        int startIndex, int startValue, int length)
        {
            int value = startValue;

            for (int i = 0; i < length; i++)
            {
                assertEquals(buf.Get(startIndex + i), value);
                value = value + 1;
            }
        }
コード例 #21
0
 private static void checkSlice(Int32Buffer b, Int32Buffer 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);
     }
 }
コード例 #22
0
 public void TestAllocatedIntBuffer_IllegalArg()
 {
     try
     {
         Int32Buffer.Allocate(-1);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentException e)
     {
         // expected
     }
 }
コード例 #23
0
        public virtual void TestHashCode()
        {
            buf.Clear();
            Int32Buffer @readonly = buf.AsReadOnlyBuffer();
            Int32Buffer duplicate = buf.Duplicate();

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

            assertTrue(buf.Capacity > 5);
            duplicate.Position = (buf.Capacity / 2);
            assertTrue(buf.GetHashCode() != duplicate.GetHashCode());
        }
コード例 #24
0
        private static void absPut(Int32Buffer b)
        {
            int n = b.Capacity;

            b.Clear();
            for (int i = 0; i < n; i++)
            {
                b.Put(i, (int)Ic(i));
            }
            b.Limit    = (n);
            b.Position = (0);
        }
コード例 #25
0
        private static void bulkPutArray(Int32Buffer b)
        {
            int n = b.Capacity;

            b.Clear();
            int[] a = new int[n + 7];
            for (int i = 0; i < n; i++)
            {
                a[i + 7] = (int)Ic(i);
            }
            b.Put(a, 7, n);
            b.Flip();
        }
コード例 #26
0
        private static void bulkPutBuffer(Int32Buffer b)
        {
            int n = b.Capacity;

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

            c.Position = (7);
            for (int i = 0; i < n; i++)
            {
                c.Put((int)Ic(i));
            }
            c.Flip();
            c.Position = (7);
            b.Put(c);
            b.Flip();
        }
コード例 #27
0
        public virtual void TestPutInt32Buffer()
        {
            Int32Buffer other = Int32Buffer.Allocate(buf.Capacity);

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

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

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

            // A NullPointerException will be thrown if the array is null.
            tryCatch(ba, typeof(ArgumentNullException), () =>
            {
                Int32Buffer.Wrap((int[])null, 0, 5);
            });
            tryCatch(ba, typeof(ArgumentNullException), () =>
            {
                Int32Buffer.Wrap((int[])null);
            });
        }
コード例 #30
0
        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);
        }