jdk/test/java/nio/Buffer/BasicInt.java
changeset 14001 e8e8413ad49a
parent 13563 13c8e8f0302b
child 14342 8435a30053c1
equal deleted inserted replaced
14000:bd8282a5e0ab 14001:e8e8413ad49a
   333                              IntBuffer xb, IntBuffer yb,
   333                              IntBuffer xb, IntBuffer yb,
   334                              int x, int y) {
   334                              int x, int y) {
   335         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
   335         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
   336     }
   336     }
   337 
   337 
   338     private static void tryCatch(Buffer b, Class ex, Runnable thunk) {
   338     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
   339         boolean caught = false;
   339         boolean caught = false;
   340         try {
   340         try {
   341             thunk.run();
   341             thunk.run();
   342         } catch (Throwable x) {
   342         } catch (Throwable x) {
   343             if (ex.isAssignableFrom(x.getClass())) {
   343             if (ex.isAssignableFrom(x.getClass())) {
   348         }
   348         }
   349         if (!caught)
   349         if (!caught)
   350             fail(ex.getName() + " not thrown", b);
   350             fail(ex.getName() + " not thrown", b);
   351     }
   351     }
   352 
   352 
   353     private static void tryCatch(int [] t, Class ex, Runnable thunk) {
   353     private static void tryCatch(int [] t, Class<?> ex, Runnable thunk) {
   354         tryCatch(IntBuffer.wrap(t), ex, thunk);
   354         tryCatch(IntBuffer.wrap(t), ex, thunk);
   355     }
   355     }
   356 
   356 
   357     public static void test(int level, final IntBuffer b, boolean direct) {
   357     public static void test(int level, final IntBuffer b, boolean direct) {
   358 
   358 
   679         tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
   679         tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
   680                 public void run() {
   680                 public void run() {
   681                     bulkPutBuffer(rb);
   681                     bulkPutBuffer(rb);
   682                 }});
   682                 }});
   683 
   683 
       
   684         // put(IntBuffer) should not change source position
       
   685         final IntBuffer src = IntBuffer.allocate(1);
   684         tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
   686         tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
   685                 public void run() {
   687                 public void run() {
       
   688                     rb.put(src);
       
   689                  }});
       
   690         ck(src, src.position(), 0);
       
   691 
       
   692         tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
       
   693                 public void run() {
   686                     rb.compact();
   694                     rb.compact();
   687                 }});
   695                 }});
       
   696 
       
   697 
       
   698 
       
   699 
       
   700 
       
   701 
       
   702 
       
   703 
       
   704 
       
   705 
       
   706 
       
   707 
       
   708 
       
   709 
       
   710 
       
   711 
   688 
   712 
   689 
   713 
   690 
   714 
   691 
   715 
   692 
   716