public static void test() { testAllocate(); test(0, ByteBufferN.allocate(7 * 1024), false); test(0, ByteBufferN.wrap(new byte[7 * 1024], 0, 7 * 1024), false); test(new byte[1024]); ByteBufferN b = ByteBufferN.allocateDirect(7 * 1024); for (b.position(0); b.position() < b.limit();) { ck(b, b.get(), 0); } test(0, b, true); callReset(ByteBufferN.allocate(10)); }
public static void test(byte[] ba) { int offset = 47; int length = 900; ByteBufferN b = ByteBufferN.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(IndexOutOfBoundsException), () => { ByteBufferN.wrap(ba, -1, ba.Length); }); tryCatch(ba, typeof(IndexOutOfBoundsException), () => { ByteBufferN.wrap(ba, ba.Length + 1, ba.Length); }); tryCatch(ba, typeof(IndexOutOfBoundsException), () => { ByteBufferN.wrap(ba, 0, -1); }); tryCatch(ba, typeof(IndexOutOfBoundsException), () => { ByteBufferN.wrap(ba, 0, ba.Length + 1); }); // A NullPointerException will be thrown if the array is null. tryCatch(ba, typeof(NullReferenceException), () => { ByteBufferN.wrap(null, 0, 5); }); tryCatch(ba, typeof(NullReferenceException), () => { ByteBufferN.wrap(null); }); }
private static void tryCatch(byte[] t, Type ex, Action thunk) { tryCatch(ByteBufferN.wrap(t), ex, thunk); }