コード例 #1
0
        public virtual void TestCompareTo()
        {
            // compare to self
            assertEquals(0, buf.CompareTo(buf));

            // normal cases
            assertTrue(buf.Capacity > 5);
            buf.Clear();
            Int16Buffer other = Int16Buffer.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));
        }
コード例 #2
0
 public override void SetUp()
 {
     base.SetUp();
     buf = Int16Buffer.Wrap(new short[BUFFER_LENGTH]);
     loadTestData1(buf);
     baseBuf = buf;
 }
コード例 #3
0
 public override void SetUp()
 {
     base.SetUp();
     buf = Int16Buffer.Allocate(BUFFER_LENGTH);
     loadTestData1(buf);
     baseBuf = buf;
 }
コード例 #4
0
        public virtual void TestAsReadOnlyBuffer()
        {
            buf.Clear();
            buf.Mark();
            buf.Position = (buf.Limit);

            // readonly's contents should be the same as buf
            Int16Buffer @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: IsDirct 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);
        }
コード例 #5
0
        public override void TestPutInt16Buffer()
        {
            Int16Buffer other = Int16Buffer.Allocate(1);

            try
            {
                buf.Put(other);
                fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
            }
            catch (ReadOnlyBufferException e)
            {
                // expected
            }
            try
            {
                buf.Put((Int16Buffer)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
            }
        }
コード例 #6
0
        public virtual void TestDuplicate()
        {
            buf.Clear();
            buf.Mark();
            buf.Position = (buf.Limit);

            // duplicate's contents should be the same as buf
            Int16Buffer 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);
            }
        }
コード例 #7
0
 public virtual void TestPutintshort()
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, 0);
         Int16Buffer ret = buf.Put(i, (short)i);
         assertEquals(buf.Get(i), (short)i);
         assertSame(ret, buf);
     }
     try
     {
         buf.Put(-1, (short)0);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentOutOfRangeException e)
     {
         // expected
     }
     try
     {
         buf.Put(buf.Limit, (short)0);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentOutOfRangeException e)
     {
         // expected
     }
 }
コード例 #8
0
 public virtual void TestPutshortArray()
 {
     short[] array = new short[1];
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, i);
         array[0] = (short)i;
         Int16Buffer ret = buf.Put(array);
         assertEquals(buf.Get(i), (short)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((short[])null);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentNullException e)
     {
         // expected
     }
 }
コード例 #9
0
        public virtual void TestSlice()
        {
            assertTrue(buf.Capacity > 5);
            buf.Position = (1);
            buf.Limit    = (buf.Capacity - 1);

            Int16Buffer 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, (short)0, slice.Capacity);
                buf.Put(2, (short)500);
                assertEquals(slice.Get(1), 500);
            }
        }
コード例 #10
0
        //6231529
        private static void callReset(Int16Buffer b)
        {
            b.Position = (0);
            b.Mark();

            b.Duplicate().Reset();
            b.AsReadOnlyBuffer().Reset();
        }
コード例 #11
0
 private static void testAllocate()
 {
     // An IllegalArgumentException will be thrown for negative capacities.
     tryCatch((Buffer)null, typeof(ArgumentException), () =>
     {
         Int16Buffer.Allocate(-1);
     });
 }
コード例 #12
0
 internal void loadTestData2(Int16Buffer buf)
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         buf.Put(i, (short)(buf.Capacity - i));
     }
 }
コード例 #13
0
 void assertContentEquals(Int16Buffer buf, short[] array,
                          int offset, int length)
 {
     for (int i = 0; i < length; i++)
     {
         assertEquals(buf.Get(i), array[offset + i]);
     }
 }
コード例 #14
0
 void assertContentEquals(Int16Buffer buf, Int16Buffer other)
 {
     assertEquals(buf.Capacity, other.Capacity);
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Get(i), other.Get(i));
     }
 }
コード例 #15
0
 public static void Test()
 {
     testAllocate();
     test(0, Int16Buffer.Allocate(7 * 1024), false);
     test(0, Int16Buffer.Wrap(new short[7 * 1024], 0, 7 * 1024), false);
     test(new short[1024]);
     callReset(Int16Buffer.Allocate(10));
     putBuffer();
 }
コード例 #16
0
        private static void relGet(Int16Buffer b, int start)
        {
            int   n = b.Remaining;
            short v;

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

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

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

            for (int i = 0; i < length; i++)
            {
                assertEquals(buf.Get(startIndex + i), value);
                value = (short)(value + 1);
            }
        }
コード例 #20
0
        private static void absGet(Int16Buffer b)
        {
            int   n = b.Capacity;
            short v;

            for (int i = 0; i < n; i++)
            {
                ck(b, (long)b.Get(), (long)((short)Ic(i)));
            }
            b.Rewind();
        }
コード例 #21
0
        private static void absPut(Int16Buffer b)
        {
            int n = b.Capacity;

            b.Clear();
            for (int i = 0; i < n; i++)
            {
                b.Put(i, (short)Ic(i));
            }
            b.Limit    = (n);
            b.Position = (0);
        }
コード例 #22
0
        public virtual void TestHashCode()
        {
            buf.Clear();
            Int16Buffer @readonly = buf.AsReadOnlyBuffer();
            Int16Buffer duplicate = buf.Duplicate();

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

            assertTrue(buf.Capacity > 5);
            duplicate.Position = (buf.Capacity / 2);
            assertTrue(buf.GetHashCode() != duplicate.GetHashCode());
        }
コード例 #23
0
 private static void checkSlice(Int16Buffer b, Int16Buffer 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);
     }
 }
コード例 #24
0
 public void TestAllocatedShortBuffer_IllegalArg()
 {
     try
     {
         Int16Buffer.Allocate(-1);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (ArgumentException e)
     {
         // expected
     }
 }
コード例 #25
0
        private static void bulkPutArray(Int16Buffer b)
        {
            int n = b.Capacity;

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

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

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

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

            loadTestData2(other);
            other.Clear();
            buf.Clear();
            Int16Buffer 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 TestPutshort()
 {
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, i);
         Int16Buffer ret = buf.Put((short)i);
         assertEquals(buf.Get(i), (short)i);
         assertSame(ret, buf);
     }
     try
     {
         buf.Put((short)0);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (BufferOverflowException e)
     {
         // expected
     }
 }
コード例 #29
0
        // 6221101-6234263

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

            //Int16Buffer direct1 = ByteBuffer.AllocateDirect(cap).AsInt16Buffer();
            Int16Buffer nondirect1 = ByteBuffer.Allocate(cap).AsInt16Buffer();
            //direct1.Put(nondirect1);

            //Int16Buffer direct2 = ByteBuffer.AllocateDirect(cap).AsInt16Buffer();
            Int16Buffer nondirect2 = ByteBuffer.Allocate(cap).AsInt16Buffer();
            //nondirect2.Put(direct2);

            //Int16Buffer direct3 = ByteBuffer.AllocateDirect(cap).AsInt16Buffer();
            //Int16Buffer direct4 = ByteBuffer.AllocateDirect(cap).AsInt16Buffer();
            //direct3.Put(direct4);

            Int16Buffer nondirect3 = ByteBuffer.Allocate(cap).AsInt16Buffer();
            Int16Buffer nondirect4 = ByteBuffer.Allocate(cap).AsInt16Buffer();

            nondirect3.Put(nondirect4);
        }
コード例 #30
0
 /*
  * Class under test for java.nio.Int16Buffer get(short[])
  */
 public virtual void TestGetshortArray()
 {
     short[] array = new short[1];
     buf.Clear();
     for (int i = 0; i < buf.Capacity; i++)
     {
         assertEquals(buf.Position, i);
         Int16Buffer ret = buf.Get(array);
         assertEquals(array[0], buf.Get(i));
         assertSame(ret, buf);
     }
     try
     {
         buf.Get(array);
         fail("Should throw Exception"); //$NON-NLS-1$
     }
     catch (BufferUnderflowException e)
     {
         // expected
     }
 }