use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method testReadUsingChannel.
@Test
public void testReadUsingChannel() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final String content = new String(file.readAllBytes(), StandardCharsets.UTF_8);
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertEquals(cfg.formatErrorMessage("Expected file content"), FILE_EXISTING_CONTENT, content);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method testDelete.
@Test
public void testDelete() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
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_EXISTING_DELETE);
toCreate.delete();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canWrite);
} 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.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method isWritable.
@Test
public void isWritable() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final boolean writable = file.isWritable();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertTrue(cfg.formatErrorMessage("Is writable"), writable);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method testGetLastModified.
@Test
public void testGetLastModified() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final FileTime lastModifiedTime = file.getLastModifiedTime();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertNotNull(cfg.formatErrorMessage("Has last modified"), lastModifiedTime);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method testRegularFile.
@Test
public void testRegularFile() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final boolean isFile = file.isRegularFile();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertTrue(cfg.formatErrorMessage("Is file"), isFile);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
}
};
ctx.eval(LANGAUGE_ID, "");
}
Aggregations