FileDocCategorySizeDatePackage
JavaIoFileInputStreamTest.javaAPI DocAndroid 1.5 API4439Wed May 06 22:41:06 BST 2009tests.security.permissions

JavaIoFileInputStreamTest

public class JavaIoFileInputStreamTest extends TestCase

Fields Summary
SecurityManager
old
Constructors Summary
Methods Summary
protected voidsetUp()

        old = System.getSecurityManager();
        super.setUp();
    
protected voidtearDown()

        System.setSecurityManager(old);
        super.tearDown();
    
public voidtest_FileInputStream()

        class TestSecurityManager extends SecurityManager {
            boolean called;
            String file;
            FileDescriptor fd;
            void reset(){
                called = false;
                file = null;
                fd = null;
            }
            @Override
            public void checkRead(FileDescriptor fd) {
                called = true;
                this.fd = fd;
                super.checkRead(fd);
            }
            @Override
            public void checkRead(String file){
                called = true;
                this.file = file;
                super.checkRead(file);
            }
            @Override
            public void checkPermission(Permission p) {
                
            }
        }

        long id = new java.util.Date().getTime();
        String filename = "SecurityPermissionsTest_"+id;
        File f = File.createTempFile(filename, null);
        f.deleteOnExit();
        filename = f.getCanonicalPath();

        TestSecurityManager s = new TestSecurityManager();
        System.setSecurityManager(s);
        
        s.reset();
        FileDescriptor fd = new FileDescriptor();
        new FileInputStream(fd);
        assertTrue("FileInputStream(FileDescriptor) ctor must call checkRead on security manager", s.called);
        assertEquals("Argument of checkRead is not correct", fd, s.fd);
        
        s.reset();
        new FileInputStream(filename);
        assertTrue("FileInputStream(String) ctor must call checkRead on security manager", s.called);
        assertEquals("Argument of checkRead is not correct", filename, s.file);
        
        s.reset();
        new FileInputStream(f);
        assertTrue("FileInputStream(File) ctor must call checkRead on security manager", s.called);
        assertEquals("Argument of checkRead is not correct", filename, s.file);