316
317 // appends that should always throw IndexOutOfBoundsException
318 int [][] sf = { { -1, 0 }, { 0, -1 }, { 11, 10 },
319 { 0, s.length() + 1},
320 };
321 for (int j = 0; j < sf.length; j++) {
322 int start = sf[j][0];
323 int end = sf[j][1];
324 try {
325 a.append(csq, start, end);
326 fail("start = " + start + ", end = " + end,
327 new IndexOutOfBoundsException());
328 a = thunk.reset(a);
329 } catch (IndexOutOfBoundsException x) {
330 pass();
331 } catch (IOException x) {
332 fail(x);
333 }
334 }
335
336 // appends of null
337 int start = 1;
338 int end = 2;
339 try {
340 thunk.init(a.append(null, start, end), "null",
341 "null".subSequence(start, end).toString());
342 thunk.run();
343 a = thunk.reset(a);
344 } catch (IOException x) {
345 fail(x);
346 }
347 }
348
349 public static void main(String [] args) throws Exception {
350 // CharSequences
351 CharBuffer cb = CharBuffer.allocate(128).put(s);
352 cb.limit(s.length()).rewind();
353 CharBuffer dcb = ByteBuffer.allocateDirect(128).asCharBuffer().put(s);
354 dcb.limit(s.length()).rewind();
355 CharSequence [] ca = { s,
356 new StringBuffer(s),
357 new StringBuilder(s),
358 cb,
359 dcb,
360 };
361
362 // Appendables/Writers
363 Object [][] wa = { { new CharArrayWriter(), testCharArrayWriter },
364 { new BufferedWriter(gw), testBufferedWriter },
365 // abstract, no implementing classes in jdk
|
316
317 // appends that should always throw IndexOutOfBoundsException
318 int [][] sf = { { -1, 0 }, { 0, -1 }, { 11, 10 },
319 { 0, s.length() + 1},
320 };
321 for (int j = 0; j < sf.length; j++) {
322 int start = sf[j][0];
323 int end = sf[j][1];
324 try {
325 a.append(csq, start, end);
326 fail("start = " + start + ", end = " + end,
327 new IndexOutOfBoundsException());
328 a = thunk.reset(a);
329 } catch (IndexOutOfBoundsException x) {
330 pass();
331 } catch (IOException x) {
332 fail(x);
333 }
334 }
335
336 // appendN with negative count
337 int[] neg = { -1, -2, -65537, Integer.MIN_VALUE + 1, Integer.MIN_VALUE };
338 for (int j = 0; j < neg.length; j++) {
339 try {
340 a.appendN('%', neg[j]);
341 fail("repeat count = " + neg[j], new IllegalArgumentException());
342 a = thunk.reset(a);
343 } catch (IllegalArgumentException x) {
344 pass();
345 } catch (IOException x) {
346 fail(x);
347 }
348 }
349
350 // appends of null
351 int start = 1;
352 int end = 2;
353 try {
354 thunk.init(a.append(null, start, end), "null",
355 "null".subSequence(start, end).toString());
356 thunk.run();
357 a = thunk.reset(a);
358 } catch (IOException x) {
359 fail(x);
360 }
361
362 // appendN
363 for (int i = 128; i > 0; ) {
364 try {
365 i /= 2;
366 String s = "";
367 for (int j = 0; j < i; j++) {
368 s += "@";
369 }
370 thunk.init(a.appendN('@', i), "'@' x 0", s);
371 thunk.run();
372 a = thunk.reset(a);
373 } catch (IOException x) {
374 fail(x);
375 }
376 }
377 }
378
379 public static void main(String [] args) throws Exception {
380 // CharSequences
381 CharBuffer cb = CharBuffer.allocate(128).put(s);
382 cb.limit(s.length()).rewind();
383 CharBuffer dcb = ByteBuffer.allocateDirect(128).asCharBuffer().put(s);
384 dcb.limit(s.length()).rewind();
385 CharSequence [] ca = { s,
386 new StringBuffer(s),
387 new StringBuilder(s),
388 cb,
389 dcb,
390 };
391
392 // Appendables/Writers
393 Object [][] wa = { { new CharArrayWriter(), testCharArrayWriter },
394 { new BufferedWriter(gw), testBufferedWriter },
395 // abstract, no implementing classes in jdk
|