package com.oracle.truffle.llvm.tests.interop;
import java.util.Collection;
import java.util.function.Consumer;
import org.graalvm.polyglot.Value;
import org.junit.Assert;
public class ReadPolyglotArrayTestBase extends PolyglotArrayTestBase {
protected static void addTestIntern(Collection<Object[]> configs, String function, ResultConsumer assertion, ExpectedExceptionConsumer expectedException, ExpectedResultMarker support,
Object... parameters) {
configs.add(new Object[]{function, assertion, expectedException, support, new ParameterArray(parameters)});
}
protected static void addUnsupported(Collection<Object[]> configs, String function, Object object, int index, ExpectedExceptionConsumer expectedException) {
addTestIntern(configs, function, PolyglotArrayTestBase::doNothing, expectedException, ExpectedResultMarker.UNSUPPORTED, object, index);
}
protected static void addSupported(Collection<Object[]> configs, String function, Object object, int index, ResultConsumer assertion) {
addTestIntern(configs, function, assertion, PolyglotArrayTestBase::doNothing, ExpectedResultMarker.SUPPORTED, object, index);
}
protected interface ResultConsumer extends Consumer<Value> {
}
protected static ResultConsumer resultEquals(byte expected) {
return (Value ret) -> PolyglotArrayTestBase.assertEqualsHex(expected, ret.asByte());
}
protected static ResultConsumer resultNotEquals(byte unexpected) {
return (Value ret) -> Assert.assertNotEquals(unexpected, ret.asByte());
}
protected static ResultConsumer resultEquals(short expected) {
return (Value ret) -> PolyglotArrayTestBase.assertEqualsHex(expected, ret.asShort());
}
protected static ResultConsumer resultNotEquals(short unexpected) {
return (Value ret) -> Assert.assertNotEquals(unexpected, ret.asShort());
}
protected static ResultConsumer resultEquals(int expected) {
return (Value ret) -> PolyglotArrayTestBase.assertEqualsHex(expected, ret.asInt());
}
protected static ResultConsumer resultNotEquals(int unexpected) {
return (Value ret) -> Assert.assertNotEquals(unexpected, ret.asInt());
}
protected static ResultConsumer resultEquals(long expected) {
return (Value ret) -> PolyglotArrayTestBase.assertEqualsHex(expected, ret.asLong());
}
protected static ResultConsumer resultNotEquals(long unexpected) {
return (Value ret) -> Assert.assertNotEquals(unexpected, ret.asLong());
}
protected static ResultConsumer resultEquals(float expected) {
return (Value ret) -> Assert.assertEquals(expected, ret.asFloat(), 0);
}
protected static ResultConsumer resultNotEquals(float unexpected) {
return (Value ret) -> Assert.assertNotEquals(unexpected, ret.asFloat());
}
protected static ResultConsumer resultEquals(double expected) {
return (Value ret) -> Assert.assertEquals(expected, ret.asDouble(), 0);
}
protected static ResultConsumer resultNotEquals(double unexpected) {
return (Value ret) -> Assert.assertNotEquals(unexpected, ret.asDouble());
}
protected static ResultConsumer resultEquals(Object expected) {
return (Value ret) -> Assert.assertEquals(Value.asValue(expected), ret);
}
protected static ResultConsumer resultNotEquals(Object unexpected) {
return (Value ret) -> Assert.assertNotEquals(Value.asValue(unexpected), ret);
}
}