|
26 | 26 |
|
27 | 27 | import static org.junit.Assert.*;
|
28 | 28 |
|
| 29 | +import java.io.ByteArrayInputStream; |
29 | 30 | import java.io.IOException;
|
30 | 31 | import java.nio.ByteBuffer;
|
31 | 32 |
|
@@ -330,14 +331,61 @@ public void isValidCompressedData()
|
330 | 331 | }
|
331 | 332 | }
|
332 | 333 |
|
| 334 | + /* |
| 335 | +
|
| 336 | + Tests happy cases for SnappyInputStream.read method |
| 337 | + - {0} |
| 338 | + */ |
| 339 | + @Test |
| 340 | + public void isValidChunkLengthForSnappyInputStreamIn() |
| 341 | + throws Exception { |
| 342 | + byte[] data = {0}; |
| 343 | + SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data)); |
| 344 | + byte[] out = new byte[50]; |
| 345 | + in.read(out); |
| 346 | + } |
| 347 | + |
| 348 | + /* |
| 349 | + Tests sad cases for SnappyInputStream.read method |
| 350 | + - Expects a java.lang.NegativeArraySizeException catched into a SnappyError |
| 351 | + - {-126, 'S', 'N', 'A', 'P', 'P', 'Y', 0, 0, 0, 0, 0, 0, 0, 0, 0,(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff} |
| 352 | + */ |
| 353 | + @Test(expected = SnappyError.class) |
| 354 | + public void isInvalidChunkLengthForSnappyInputStreamInNegative() |
| 355 | + throws Exception { |
| 356 | + byte[] data = {-126, 'S', 'N', 'A', 'P', 'P', 'Y', 0, 0, 0, 0, 0, 0, 0, 0, 0,(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff}; |
| 357 | + SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data)); |
| 358 | + byte[] out = new byte[50]; |
| 359 | + in.read(out); |
| 360 | + } |
| 361 | + |
| 362 | + /* |
| 363 | + Tests sad cases for SnappyInputStream.read method |
| 364 | + - Expects a java.lang.OutOfMemoryError |
| 365 | + - {-126, 'S', 'N', 'A', 'P', 'P', 'Y', 0, 0, 0, 0, 0, 0, 0, 0, 0,(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff} |
| 366 | + */ |
| 367 | + @Test(expected = SnappyError.class) |
| 368 | + public void isInvalidChunkLengthForSnappyInputStreamOutOfMemory() |
| 369 | + throws Exception { |
| 370 | + byte[] data = {-126, 'S', 'N', 'A', 'P', 'P', 'Y', 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff}; |
| 371 | + SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(data)); |
| 372 | + byte[] out = new byte[50]; |
| 373 | + try { |
| 374 | + in.read(out); |
| 375 | + } catch (Exception ignored) { |
| 376 | + // Exception here will be catched |
| 377 | + // But OutOfMemoryError will not be caught, and will still be thrown |
| 378 | + } |
| 379 | + } |
| 380 | + |
333 | 381 | /*
|
334 | 382 | Tests happy cases for BitShuffle.shuffle method
|
335 | 383 | - double: 0, 10
|
336 | 384 | - float: 0, 10
|
337 | 385 | - int: 0, 10
|
338 | 386 | - long: 0, 10
|
339 | 387 | - short: 0, 10
|
340 |
| - */ |
| 388 | + */ |
341 | 389 | @Test
|
342 | 390 | public void isValidArrayInputLengthForBitShuffleShuffle()
|
343 | 391 | throws Exception
|
@@ -386,5 +434,6 @@ public void isTooLargeLongArrayInputLengthForBitShuffleShuffle() throws Exceptio
|
386 | 434 | @Test(expected = SnappyError.class)
|
387 | 435 | public void isTooLargeShortArrayInputLengthForBitShuffleShuffle() throws Exception {
|
388 | 436 | BitShuffle.shuffle(new short[Integer.MAX_VALUE / 2 + 1]);
|
| 437 | + |
389 | 438 | }
|
390 | 439 | }
|
0 commit comments