use of org.graalvm.polyglot.io.ByteSequence in project graal by oracle.
the class WasmPolyglotTestSuite method overwriteElement.
@Test
public void overwriteElement() throws IOException, InterruptedException {
final ByteSequence test = ByteSequence.create(compileWat("test", textOverwriteElement));
Context.Builder contextBuilder = Context.newBuilder(WasmLanguage.ID);
Source.Builder sourceBuilder = Source.newBuilder(WasmLanguage.ID, test, "main");
Source source = sourceBuilder.build();
Context context = contextBuilder.build();
context.eval(source);
Value mainFunction = context.getBindings(WasmLanguage.ID).getMember("main").getMember("main");
Value result = mainFunction.execute();
Assert.assertEquals("Should be equal: ", 11, result.asInt());
}
use of org.graalvm.polyglot.io.ByteSequence in project graal by oracle.
the class ElfSectionHeaderTable method create.
public static ElfSectionHeaderTable create(ElfHeader header, ElfReader buffer) {
Entry[] entries = new Entry[header.getShnum()];
buffer.setPosition((int) header.getShoff());
for (int cntr = 0; cntr < entries.length; cntr++) {
entries[cntr] = readEntry(header, buffer);
}
// read string table
ByteSequence data = null;
if (header.getShstrndx() < entries.length) {
Entry e = entries[header.getShstrndx()];
if (e.getSize() > 0) {
data = buffer.getStringTable(e.getOffset(), e.getSize());
}
}
return new ElfSectionHeaderTable(entries, data);
}
use of org.graalvm.polyglot.io.ByteSequence in project graal by oracle.
the class SourceBuilderTest method testBuiltFromBinarySource.
@Test
public void testBuiltFromBinarySource() throws URISyntaxException {
setupEnv();
ByteSequence bytes = ByteSequence.create(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });
Source source1 = Source.newBuilder("Lang", bytes, "testName").build();
Source source2 = Source.newBuilder(source1).build();
assertSameProperties(source1, source2);
assertNewSourceChanged(source1);
}
use of org.graalvm.polyglot.io.ByteSequence in project graal by oracle.
the class ByteSequenceTest method testEmptySequence.
@Test
public void testEmptySequence() {
ByteSequence sequence = ByteSequence.create(new byte[] {});
assertEquals(0, sequence.length());
assertArrayEquals(new byte[0], sequence.toByteArray());
assertArrayEquals(new byte[0], sequence.subSequence(0, 0).toByteArray());
}
use of org.graalvm.polyglot.io.ByteSequence in project graal by oracle.
the class ByteSequenceTest method testCustomByteSequence.
@Test
public void testCustomByteSequence() {
ByteSequence sequence = new ByteSequenceImpl();
assertTrue(sequence.bytes().allMatch((e) -> e > 0 && e <= 4));
assertEquals(1, sequence.byteAt(0));
assertEquals(2, sequence.byteAt(1));
assertEquals(3, sequence.byteAt(2));
assertEquals(4, sequence.byteAt(3));
assertEquals(4, sequence.length());
// not failing
sequence.hashCode();
assertNotEquals(sequence, ByteSequence.create(new byte[] { 1, 2, 3, 4 }));
assertNotNull(sequence.toString());
assertArrayEquals(new byte[0], sequence.subSequence(0, 0).toByteArray());
assertArrayEquals(new byte[] { 1 }, sequence.subSequence(0, 1).toByteArray());
assertArrayEquals(new byte[] { 4 }, sequence.subSequence(3, 4).toByteArray());
assertArrayEquals(new byte[] { 2, 3, 4 }, sequence.subSequence(1, 4).toByteArray());
assertArrayEquals(new byte[] { 1, 2, 3 }, sequence.subSequence(0, 3).toByteArray());
assertArrayEquals(new byte[0], sequence.subSequence(4, 4).toByteArray());
assertNotEquals(sequence, sequence.subSequence(0, 4));
assertNotEquals(sequence.subSequence(0, 1), sequence.subSequence(0, 1));
assertNotEquals(sequence.subSequence(0, 1), sequence.subSequence(0, 2));
assertNotEquals(sequence.subSequence(0, 1), sequence.subSequence(1, 2));
ByteSequence other = ByteSequence.create(new byte[] { 1, 2, 3, 4 });
assertNotEquals(sequence, other);
assertNotEquals(sequence.subSequence(0, 1), other.subSequence(0, 1));
assertNotEquals(sequence.subSequence(0, 1), other.subSequence(0, 2));
assertNotEquals(sequence.subSequence(0, 1), other.subSequence(1, 2));
assertFails(() -> sequence.subSequence(1, 0), IndexOutOfBoundsException.class);
assertFails(() -> sequence.subSequence(-1, 1), IndexOutOfBoundsException.class);
assertFails(() -> sequence.subSequence(3, 5), IndexOutOfBoundsException.class);
assertFails(() -> sequence.byteAt(-1), IndexOutOfBoundsException.class);
assertFails(() -> sequence.byteAt(4), IndexOutOfBoundsException.class);
}
Aggregations