FileDocCategorySizeDatePackage
JavaUtilZipZipFile.javaAPI DocAndroid 1.5 API3037Wed May 06 22:41:06 BST 2009tests.security.permissions

JavaUtilZipZipFile

public class JavaUtilZipZipFile 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_ZipFile()

        class TestSecurityManager extends SecurityManager {
            private boolean called = false;
            private String name = null;
            void reset(){
                called = false;
                name = null;
            }
            String getName(){return name;}
            @Override
            public void checkRead(String name) {
                called = true;
                this.name = name;
                super.checkRead(name);
            }
            
            @Override
            public void checkPermission(Permission permission) {
            }
        }
        
        File file = File.createTempFile("foo", "zip");
        String filename = file.getAbsolutePath();
        
        TestSecurityManager s = new TestSecurityManager();
        System.setSecurityManager(s);
        
        s.reset();
        try {
            new ZipFile(filename);
        } catch (ZipException ex) {
            // Ignore.
        }
        assertTrue("java.util.zip.ZipFile() construcor must call checkRead on security permissions", s.called);
        assertEquals("Argument of checkPermission is not correct", filename, s.getName());