|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
5 | 5 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
| 6 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
6 | 7 | import static org.junit.jupiter.api.Assertions.assertNull;
|
7 | 8 | import static org.junit.jupiter.api.Assertions.assertSame;
|
8 | 9 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
9 | 10 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
10 | 11 |
|
11 | 12 | import java.io.IOException;
|
12 | 13 | import java.nio.ByteBuffer;
|
| 14 | +import java.util.Arrays; |
13 | 15 | import java.util.Random;
|
14 | 16 |
|
15 | 17 | import org.junit.jupiter.api.Test;
|
@@ -106,12 +108,19 @@ public void testHexMatchLength() {
|
106 | 108 | assertEquals(0,Blob.fromHex("ffff0123").hexMatch(Blob.fromHex("ffff012f"), 3, 0));
|
107 | 109 | }
|
108 | 110 |
|
109 |
| - @Test public void testHexDigit() { |
110 |
| - |
| 111 | + @Test |
| 112 | + public void testHexDigitComplete() { |
| 113 | + Blob b = Blob.fromHex("a1b2"); |
| 114 | + assertEquals(10, b.getHexDigit(0)); // 'a' |
| 115 | + assertEquals(1, b.getHexDigit(1)); // '1' |
| 116 | + assertEquals(11, b.getHexDigit(2)); // 'b' |
| 117 | + assertEquals(2, b.getHexDigit(3)); // '2' |
| 118 | + |
| 119 | + // Test boundary conditions |
| 120 | + assertThrows(IndexOutOfBoundsException.class, () -> b.getHexDigit(-1)); |
| 121 | + assertThrows(IndexOutOfBoundsException.class, () -> b.getHexDigit(4)); |
| 122 | + assertThrows(IndexOutOfBoundsException.class, () -> Blob.EMPTY.getHexDigit(0)); |
111 | 123 | }
|
112 |
| - |
113 |
| - |
114 |
| - |
115 | 124 |
|
116 | 125 | @Test
|
117 | 126 | public void testFromHex() {
|
@@ -391,6 +400,65 @@ public void testCreate() {
|
391 | 400 | assertSame(Blobs.empty(),Blob.create(bs, 10, 0));
|
392 | 401 | }
|
393 | 402 |
|
| 403 | + @Test |
| 404 | + public void testHexParsingEdgeCases() { |
| 405 | + // Case sensitivity |
| 406 | + assertEquals(Blob.fromHex("abcd"), Blob.fromHex("ABCD")); |
| 407 | + assertEquals(Blob.fromHex("abcd"), Blob.fromHex("AbCd")); |
| 408 | + |
| 409 | + // Invalid characters |
| 410 | + assertNull(Blob.fromHex("12GH")); |
| 411 | + assertNull(Blob.fromHex("12 34")); |
| 412 | + assertNull(Blob.fromHex("12\n34")); |
| 413 | + |
| 414 | + // Empty and whitespace |
| 415 | + assertEquals(Blob.EMPTY, Blob.fromHex("")); |
| 416 | + assertNull(Blob.fromHex(" ")); // Should this be EMPTY or null? |
| 417 | + } |
| 418 | + |
| 419 | + |
| 420 | + @Test |
| 421 | + public void testBlobTreeDepthLimits() { |
| 422 | + // Test extremely deep blob trees don't cause stack overflow |
| 423 | + BlobBuilder bb = new BlobBuilder(); |
| 424 | + Blob small = Blob.fromHex("01"); |
| 425 | + |
| 426 | + // Build a very nested structure |
| 427 | + for (int i = 0; i < 1000; i++) { |
| 428 | + bb.append(small); |
| 429 | + } |
| 430 | + |
| 431 | + ABlob result = bb.toBlob(); |
| 432 | + assertNotNull(result); |
| 433 | + assertEquals(1000, result.count()); |
| 434 | + } |
| 435 | + |
| 436 | + @Test |
| 437 | + public void testCompareConsistency() { |
| 438 | + // Ensure compareTo is consistent with equals |
| 439 | + java.util.List<Blob> blobs = Arrays.asList( |
| 440 | + Blob.EMPTY, |
| 441 | + Blob.fromHex("00"), |
| 442 | + Blob.fromHex("01"), |
| 443 | + Blob.fromHex("FF"), |
| 444 | + Blob.fromHex("0000"), |
| 445 | + Blob.fromHex("0001"), |
| 446 | + Blob.fromHex("FFFF") |
| 447 | + ); |
| 448 | + |
| 449 | + for (Blob b1 : blobs) { |
| 450 | + for (Blob b2 : blobs) { |
| 451 | + // If equal, compareTo should return 0 |
| 452 | + if (b1.equals(b2)) { |
| 453 | + assertEquals(0, b1.compareTo(b2)); |
| 454 | + } |
| 455 | + |
| 456 | + // compareTo should be antisymmetric |
| 457 | + assertEquals(-Integer.signum(b1.compareTo(b2)), Integer.signum(b2.compareTo(b1))); |
| 458 | + } |
| 459 | + } |
| 460 | + } |
| 461 | + |
394 | 462 | @Test
|
395 | 463 | public void testPacked() {
|
396 | 464 | Blob chunk=Samples.FULL_BLOB;
|
|
0 commit comments