@Test
    public void testFileReadOnly() throws Exception {
        final Permissions permissions = new Permissions();
        final String fileName = "testFileReadOnly.txt";
        permissions.add(new LibUVPermission("libuv.handle"));
        permissions.add(new FilePermission(fileName, "read"));
        permissions.add(new FilePermission(fileName, "delete"));
        final File f = new File(fileName);
        f.createNewFile();

        init(permissions);
        final LoopHandle loop = new LoopHandle();
        final Files handle = new Files(loop);
        final int fd = handle.open(fileName, Constants.O_RDONLY, Constants.S_IRWXU);

        handle.read(fd, ByteBuffer.allocateDirect(5), 0, 0, 0);
        final Stats s = handle.fstat(fd);
        if (s == null) {
            throw new Exception("Stats is null");
        }

        try {
            handle.fdatasync(fd);
            if (OS.startsWith("Windows")) {
                throw new Exception("fdatasync should have failed");
            }
        } catch (final NativeException ex) {
            // XXX OK.
        }

        try {
            handle.fsync(fd);
            if (OS.startsWith("Windows")) {
                throw new Exception("fsync should have failed");
            }
        } catch (final NativeException ex) {
            // XXX OK.
        }

        try {
            handle.write(fd, ByteBuffer.wrap("Hello".getBytes()), 0, 2, 0);
            throw new Exception("Write should have failed");
        } catch (final AccessControlException ex) {
            // XXX OK.
        }

        try {
            handle.ftruncate(fd, 1);
            throw new Exception("Write should have failed");
        } catch (final AccessControlException ex) {
            // XXX OK.
        }

        testFailure(new Runnable() {
            @Override
            public void run() {
                handle.futime(fd, 999, 999999);
            }
        });

        testFailure(new Runnable() {
            @Override
            public void run() {
                handle.fchmod(fd, Constants.S_IRWXU);
            }
        });

        testFailure(new Runnable() {
            @Override
            public void run() {
                handle.fchown(fd, 01, 01);
            }
        });

        testFailure(new Runnable() {
            @Override
            public void run() {
                handle.futime(fd, 999, 99999);
            }
        });

        handle.unlink(fileName);
    }