use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class LanguageSPITest method testLookupHost.
@Test
public void testLookupHost() {
Context context = Context.newBuilder().allowHostAccess(true).build();
Value value = eval(context, new Function<Env, Object>() {
public Object apply(Env t) {
return t.lookupHostSymbol("java.util.HashMap");
}
});
assertTrue(value.isHostObject());
Object map = value.asHostObject();
assertSame(map, HashMap.class);
context.close();
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class VirtualizedFileSystemTest method testCreateDirectoryTest.
@Test
public void testCreateDirectoryTest() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
final boolean canWrite = cfg.canWrite();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile toCreate = root.resolve(FILE_NEW_CREATE_DIR);
toCreate.createDirectories();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canWrite);
if (canRead) {
Assert.assertTrue(cfg.formatErrorMessage("Expected dir exists"), toCreate.exists());
}
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canWrite);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class VirtualizedFileSystemTest method testGetAbsoluteFile.
@Test
public void testGetAbsoluteFile() {
final Context ctx = cfg.getContext();
final boolean allowsUserDir = cfg.allowsUserDir();
if (cfg.needsURI()) {
// Nothing to test for URI path
return;
}
languageAction = (Env env) -> {
final TruffleFile file = env.getTruffleFile(FOLDER_EXISTING).resolve(FILE_EXISTING);
try {
final TruffleFile absolute = file.getAbsoluteFile();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), allowsUserDir);
Assert.assertEquals(absolute.getPath(), cfg.getUserDir().resolve(FOLDER_EXISTING).resolve(FILE_EXISTING).toString());
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), allowsUserDir);
}
};
ctx.eval(LANGAUGE_ID, "");
}
Aggregations