use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SegmentCommandUtilsTest method testGettingHeaderSize64Bit.
@Test
public void testGettingHeaderSize64Bit() throws Exception {
byte[] bytes = SegmentCommandTestData.getBigEndian64Bits();
final int commandSize = bytes.length;
SegmentCommand command = SegmentCommandUtils.createFromBuffer(ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN), new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
assertThat(SegmentCommandUtils.getSegmentCommandHeaderSize(command), equalTo(commandSize));
}
use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SegmentCommandUtilsTest method testGettingHeaderSize32Bit.
@Test
public void testGettingHeaderSize32Bit() throws Exception {
byte[] bytes = SegmentCommandTestData.getBigEndian32Bits();
final int commandSize = bytes.length;
SegmentCommand command = SegmentCommandUtils.createFromBuffer(ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN), new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
assertThat(SegmentCommandUtils.getSegmentCommandHeaderSize(command), equalTo(commandSize));
}
use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SegmentCommandUtilsTest method testEnumeratingSections64Bit.
@Test
public void testEnumeratingSections64Bit() throws Exception {
final int sectionSize = SectionTestData.getBigEndian64Bit().length;
byte[] sectionData1 = SectionTestData.getBigEndian64Bit();
// offset = 1
sectionData1[51] = (byte) 0x01;
byte[] sectionData2 = SectionTestData.getBigEndian64Bit();
// sectname = "DECTNAME"
sectionData2[0] = (byte) 0x44;
// segname = "DEGNAME"
sectionData2[16] = (byte) 0x44;
// offset = 2
sectionData2[51] = (byte) 0x02;
byte[] sectionData3 = SectionTestData.getBigEndian64Bit();
// sectname = "LECTNAME"
sectionData3[0] = (byte) 0x4C;
// segname = "LEGNAME"
sectionData3[16] = (byte) 0x4C;
// offset = 3
sectionData3[51] = (byte) 0x03;
byte[] segmentBytes = SegmentCommandTestData.getBigEndian64Bits();
// nsects = 3
segmentBytes[67] = (byte) 0x03;
SegmentCommand command = SegmentCommandUtils.createFromBuffer(ByteBuffer.wrap(segmentBytes).order(ByteOrder.BIG_ENDIAN), new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
ByteBuffer buffer = ByteBuffer.allocate(command.getLoadCommandCommonFields().getCmdsize().intValue() + 3 * sectionSize);
buffer.order(ByteOrder.BIG_ENDIAN);
SegmentCommandUtils.writeCommandToBuffer(command, buffer, true);
buffer.put(sectionData1);
buffer.put(sectionData2);
buffer.put(sectionData3);
final List<Section> enumeratedSections = new ArrayList<>();
SegmentCommandUtils.enumerateSectionsInSegmentLoadCommand(buffer, new MachoMagicInfo(UnsignedInteger.fromIntBits(0xFEEDFACF)), command, new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()), input -> {
enumeratedSections.add(input);
return Boolean.TRUE;
});
assertThat(enumeratedSections.size(), equalTo(3));
assertThat(enumeratedSections.get(0).getSectname(), equalToObject("SECTNAME"));
assertThat(enumeratedSections.get(0).getSegname(), equalToObject("SEGNAME"));
assertThat(enumeratedSections.get(0).getOffset(), equalToObject(UnsignedInteger.fromIntBits(0x01)));
assertThat(enumeratedSections.get(1).getSectname(), equalToObject("DECTNAME"));
assertThat(enumeratedSections.get(1).getSegname(), equalToObject("DEGNAME"));
assertThat(enumeratedSections.get(1).getOffset(), equalToObject(UnsignedInteger.fromIntBits(0x02)));
assertThat(enumeratedSections.get(2).getSectname(), equalToObject("LECTNAME"));
assertThat(enumeratedSections.get(2).getSegname(), equalToObject("LEGNAME"));
assertThat(enumeratedSections.get(2).getOffset(), equalToObject(UnsignedInteger.fromIntBits(0x03)));
}
use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SectionTest method testCreatingFromBytesBigEndian64Bit.
@Test
public void testCreatingFromBytesBigEndian64Bit() throws Exception {
Section section = SectionUtils.createFromBuffer(createBuffer(SectionTestData.getBigEndian64Bit(), 10, ByteOrder.BIG_ENDIAN), true, new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
assertThat(section.getOffsetInBinary(), equalTo(10));
checkValues(section);
}
use of com.facebook.buck.charset.NulTerminatedCharsetDecoder in project buck by facebook.
the class SectionTest method testCreatingFromBytesLittleEndian32Bit.
@Test
public void testCreatingFromBytesLittleEndian32Bit() throws Exception {
Section section = SectionUtils.createFromBuffer(createBuffer(SectionTestData.getLittleEndian32Bit(), 40, ByteOrder.LITTLE_ENDIAN), false, new NulTerminatedCharsetDecoder(StandardCharsets.UTF_8.newDecoder()));
assertThat(section.getOffsetInBinary(), equalTo(40));
checkValues(section);
}
Aggregations