Skip to content

Commit 9e6b23f

Browse files
committed
improved tests
1 parent a2d773e commit 9e6b23f

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

jbbp/src/test/java/com/igormaznitsa/jbbp/utils/JBBPUtilsTest.java

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public void testGenerateMask() {
588588
}
589589

590590
@Test
591-
public void testTraceData() throws Exception {
591+
public void testTraceData_Defaults() throws Exception {
592592
final byte[] testData = new byte[211];
593593
for (int i = 0; i < 111; i++) {
594594
testData[i] = (byte) i;
@@ -617,4 +617,66 @@ public void testTraceData() throws Exception {
617617
"000000C0 00 00 00 00 | 00 00 00 00 | 00 00 00 00 | 00 00 00 00 | 00 00 00 -- | -- -- -- -- | -- -- -- -- | -- -- -- -- ................................\n",
618618
asString);
619619
}
620+
621+
@Test
622+
public void testTraceData_CustomWithChars() throws Exception {
623+
final byte[] testData = new byte[211];
624+
for (int i = 0; i < 111; i++) {
625+
testData[i] = (byte) i;
626+
}
627+
final InputStream stream = new ByteArrayInputStream(testData);
628+
final ByteArrayOutputStream outArray = new ByteArrayOutputStream();
629+
final PrintStream out = new PrintStream(outArray, true, "UTF-8");
630+
JBBPUtils.traceData(stream, 8, 4, "#", "_", "$", "Z", '&', true, out);
631+
out.close();
632+
final String asString =
633+
new String(outArray.toByteArray(), StandardCharsets.UTF_8).replace("\r\n", "\n")
634+
.replace("\r", "\n");
635+
assertEquals(
636+
"00000000#00_01_02_03_04_05_06_07$08_09_0A_0B_0C_0D_0E_0F$10_11_12_13_14_15_16_17$18_19_1A_1B_1C_1D_1E_1FZ&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"
637+
+
638+
"00000020#20_21_22_23_24_25_26_27$28_29_2A_2B_2C_2D_2E_2F$30_31_32_33_34_35_36_37$38_39_3A_3B_3C_3D_3E_3FZ !\"#$%&'()*+,-./0123456789:;<=>?\n"
639+
+
640+
"00000040#40_41_42_43_44_45_46_47$48_49_4A_4B_4C_4D_4E_4F$50_51_52_53_54_55_56_57$58_59_5A_5B_5C_5D_5E_5FZ@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\n"
641+
+
642+
"00000060#60_61_62_63_64_65_66_67$68_69_6A_6B_6C_6D_6E_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00Z`abcdefghijklmn&&&&&&&&&&&&&&&&&\n"
643+
+
644+
"00000080#00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00Z&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"
645+
+
646+
"000000A0#00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00Z&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"
647+
+
648+
"000000C0#00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_--_--_--_--_--$--_--_--_--_--_--_--_--Z&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n",
649+
asString);
650+
}
651+
652+
@Test
653+
public void testTraceData_CustomNoChars() throws Exception {
654+
final byte[] testData = new byte[211];
655+
for (int i = 0; i < 111; i++) {
656+
testData[i] = (byte) i;
657+
}
658+
final InputStream stream = new ByteArrayInputStream(testData);
659+
final ByteArrayOutputStream outArray = new ByteArrayOutputStream();
660+
final PrintStream out = new PrintStream(outArray, true, "UTF-8");
661+
JBBPUtils.traceData(stream, 8, 4, "#", "_", "$", "Z", '&', false, out);
662+
out.close();
663+
final String asString =
664+
new String(outArray.toByteArray(), StandardCharsets.UTF_8).replace("\r\n", "\n")
665+
.replace("\r", "\n");
666+
assertEquals(
667+
"00000000#00_01_02_03_04_05_06_07$08_09_0A_0B_0C_0D_0E_0F$10_11_12_13_14_15_16_17$18_19_1A_1B_1C_1D_1E_1F\n"
668+
+
669+
"00000020#20_21_22_23_24_25_26_27$28_29_2A_2B_2C_2D_2E_2F$30_31_32_33_34_35_36_37$38_39_3A_3B_3C_3D_3E_3F\n"
670+
+
671+
"00000040#40_41_42_43_44_45_46_47$48_49_4A_4B_4C_4D_4E_4F$50_51_52_53_54_55_56_57$58_59_5A_5B_5C_5D_5E_5F\n"
672+
+
673+
"00000060#60_61_62_63_64_65_66_67$68_69_6A_6B_6C_6D_6E_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00\n"
674+
+
675+
"00000080#00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00\n"
676+
+
677+
"000000A0#00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00\n"
678+
+
679+
"000000C0#00_00_00_00_00_00_00_00$00_00_00_00_00_00_00_00$00_00_00_--_--_--_--_--$--_--_--_--_--_--_--_--\n",
680+
asString);
681+
}
620682
}

0 commit comments

Comments
 (0)