test/java/nio/Buffer/BasicDouble.java

Print this page
rev 11666 : 8065556: (bf) Buffer.position and other methods should include detail in IAE
Summary: Add messages to IAEs which have none.
Reviewed-by: XXX


 111         int n = b.capacity();
 112         b.clear();
 113         double[] a = new double[n + 7];
 114         for (int i = 0; i < n; i++)
 115             a[i + 7] = (double)ic(i);
 116         b.put(a, 7, n);
 117         b.flip();
 118     }
 119 
 120     private static void bulkPutBuffer(DoubleBuffer b) {
 121         int n = b.capacity();
 122         b.clear();
 123         DoubleBuffer c = DoubleBuffer.allocate(n + 7);
 124         c.position(7);
 125         for (int i = 0; i < n; i++)
 126             c.put((double)ic(i));
 127         c.flip();
 128         c.position(7);
 129         b.put(c);
 130         b.flip();








 131     }
 132 
 133     //6231529
 134     private static void callReset(DoubleBuffer b) {
 135         b.position(0);
 136         b.mark();
 137 
 138         b.duplicate().reset();
 139         b.asReadOnlyBuffer().reset();
 140     }
 141 
 142 
 143 
 144     // 6221101-6234263
 145 
 146     private static void putBuffer() {
 147         final int cap = 10;
 148 
 149         DoubleBuffer direct1 = ByteBuffer.allocateDirect(cap).asDoubleBuffer();
 150         DoubleBuffer nondirect1 = ByteBuffer.allocate(cap).asDoubleBuffer();


 447                     b.get(b.limit());
 448                 }});
 449         tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
 450                 public void run() {
 451                     b.get(-1);
 452                 }});
 453 
 454         tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
 455                 public void run() {
 456                     b.put(b.limit(), (double)42);
 457                 }});
 458 
 459         tryCatch(b, InvalidMarkException.class, new Runnable() {
 460                 public void run() {
 461                     b.position(0);
 462                     b.mark();
 463                     b.compact();
 464                     b.reset();
 465                 }});
 466 




































 467         // Values
 468 
 469         b.clear();
 470         b.put((double)0);
 471         b.put((double)-1);
 472         b.put((double)1);
 473         b.put(Double.MAX_VALUE);
 474         b.put(Double.MIN_VALUE);
 475 
 476 
 477 
 478 
 479 
 480 
 481 
 482 
 483 
 484         b.put(-Double.MAX_VALUE);
 485         b.put(-Double.MIN_VALUE);
 486         b.put(Double.NEGATIVE_INFINITY);


 917                     DoubleBuffer.wrap(ba, 0, ba.length + 1);
 918                 }});
 919 
 920         // A NullPointerException will be thrown if the array is null.
 921         tryCatch(ba, NullPointerException.class, new Runnable() {
 922                 public void run() {
 923                     DoubleBuffer.wrap((double []) null, 0, 5);
 924                 }});
 925         tryCatch(ba, NullPointerException.class, new Runnable() {
 926                 public void run() {
 927                     DoubleBuffer.wrap((double []) null);
 928                 }});
 929     }
 930 
 931     private static void testAllocate() {
 932         // An IllegalArgumentException will be thrown for negative capacities.
 933         tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
 934                 public void run() {
 935                     DoubleBuffer.allocate(-1);
 936                 }});














 937 
 938 
 939 
 940 
 941 
 942 
 943     }
 944 
 945     public static void test() {
 946         testAllocate();
 947         test(0, DoubleBuffer.allocate(7 * 1024), false);
 948         test(0, DoubleBuffer.wrap(new double[7 * 1024], 0, 7 * 1024), false);
 949         test(new double[1024]);
 950 
 951 
 952 
 953 
 954 
 955 
 956 


 111         int n = b.capacity();
 112         b.clear();
 113         double[] a = new double[n + 7];
 114         for (int i = 0; i < n; i++)
 115             a[i + 7] = (double)ic(i);
 116         b.put(a, 7, n);
 117         b.flip();
 118     }
 119 
 120     private static void bulkPutBuffer(DoubleBuffer b) {
 121         int n = b.capacity();
 122         b.clear();
 123         DoubleBuffer c = DoubleBuffer.allocate(n + 7);
 124         c.position(7);
 125         for (int i = 0; i < n; i++)
 126             c.put((double)ic(i));
 127         c.flip();
 128         c.position(7);
 129         b.put(c);
 130         b.flip();
 131         try {
 132             b.put(b);
 133             fail("IllegalArgumentException expected for putting into same buffer");
 134         } catch (IllegalArgumentException e) {
 135             if (e.getMessage() == null) {
 136                 fail("Non-null IllegalArgumentException message expected from putting into same buffer");
 137             }
 138         }
 139     }
 140 
 141     //6231529
 142     private static void callReset(DoubleBuffer b) {
 143         b.position(0);
 144         b.mark();
 145 
 146         b.duplicate().reset();
 147         b.asReadOnlyBuffer().reset();
 148     }
 149 
 150 
 151 
 152     // 6221101-6234263
 153 
 154     private static void putBuffer() {
 155         final int cap = 10;
 156 
 157         DoubleBuffer direct1 = ByteBuffer.allocateDirect(cap).asDoubleBuffer();
 158         DoubleBuffer nondirect1 = ByteBuffer.allocate(cap).asDoubleBuffer();


 455                     b.get(b.limit());
 456                 }});
 457         tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
 458                 public void run() {
 459                     b.get(-1);
 460                 }});
 461 
 462         tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
 463                 public void run() {
 464                     b.put(b.limit(), (double)42);
 465                 }});
 466 
 467         tryCatch(b, InvalidMarkException.class, new Runnable() {
 468                 public void run() {
 469                     b.position(0);
 470                     b.mark();
 471                     b.compact();
 472                     b.reset();
 473                 }});
 474 
 475         try {
 476             b.position(b.limit() + 1);
 477             fail("IllegalArgumentException expected for setting position beyond limit");
 478         } catch (IllegalArgumentException e) {
 479             if (e.getMessage() == null) {
 480                 fail("Non-null IllegalArgumentException message expected for setting position beyond limit");
 481             }
 482         }
 483 
 484         try {
 485             b.position(-1);
 486             fail("IllegalArgumentException expected for setting negative position");
 487         } catch (IllegalArgumentException e) {
 488             if (e.getMessage() == null) {
 489                 fail("Non-null IllegalArgumentException message expected for setting negative position");
 490             }
 491         }
 492 
 493         try {
 494             b.limit(b.capacity() + 1);
 495             fail("IllegalArgumentException expected for setting limit beyond capacity");
 496         } catch (IllegalArgumentException e) {
 497             if (e.getMessage() == null) {
 498                 fail("Non-null IllegalArgumentException message expected for setting limit beyond capacity");
 499             }
 500         }
 501 
 502         try {
 503             b.limit(-1);
 504             fail("IllegalArgumentException expected for setting negative limit");
 505         } catch (IllegalArgumentException e) {
 506             if (e.getMessage() == null) {
 507                 fail("Non-null IllegalArgumentException message expected for setting negative limit");
 508             }
 509         }
 510 
 511         // Values
 512 
 513         b.clear();
 514         b.put((double)0);
 515         b.put((double)-1);
 516         b.put((double)1);
 517         b.put(Double.MAX_VALUE);
 518         b.put(Double.MIN_VALUE);
 519 
 520 
 521 
 522 
 523 
 524 
 525 
 526 
 527 
 528         b.put(-Double.MAX_VALUE);
 529         b.put(-Double.MIN_VALUE);
 530         b.put(Double.NEGATIVE_INFINITY);


 961                     DoubleBuffer.wrap(ba, 0, ba.length + 1);
 962                 }});
 963 
 964         // A NullPointerException will be thrown if the array is null.
 965         tryCatch(ba, NullPointerException.class, new Runnable() {
 966                 public void run() {
 967                     DoubleBuffer.wrap((double []) null, 0, 5);
 968                 }});
 969         tryCatch(ba, NullPointerException.class, new Runnable() {
 970                 public void run() {
 971                     DoubleBuffer.wrap((double []) null);
 972                 }});
 973     }
 974 
 975     private static void testAllocate() {
 976         // An IllegalArgumentException will be thrown for negative capacities.
 977         tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
 978                 public void run() {
 979                     DoubleBuffer.allocate(-1);
 980                 }});
 981         try {
 982             DoubleBuffer.allocate(-1);
 983         } catch (IllegalArgumentException e) {
 984             if (e.getMessage() == null) {
 985                 fail("Non-null IllegalArgumentException message expected attempt to allocate negative capacity buffer");
 986             }
 987         }
 988 
 989 
 990 
 991 
 992 
 993 
 994 
 995 
 996 
 997 
 998 
 999 
1000 
1001     }
1002 
1003     public static void test() {
1004         testAllocate();
1005         test(0, DoubleBuffer.allocate(7 * 1024), false);
1006         test(0, DoubleBuffer.wrap(new double[7 * 1024], 0, 7 * 1024), false);
1007         test(new double[1024]);
1008 
1009 
1010 
1011 
1012 
1013 
1014