harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r617085 [4/14] - in /harmony/enhanced/classlib/branches/java6: depends/build/ depends/build/platform/ depends/libs/ depends/oss/ make/ make/linux.x86_64.libstdc++6/ make/windows.x86/ make/windows.x86_64/ modules/archive/META-INF/ modules/ar...
Date Thu, 31 Jan 2008 10:04:22 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
Thu Jan 31 02:04:05 2008
@@ -1,209 +1,211 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.File;
-import java.io.FilePermission;
-import java.security.PermissionCollection;
-
-public class FilePermissionTest extends junit.framework.TestCase {
-
-    FilePermission readAllFiles = new FilePermission("<<ALL FILES>>", "read");
-
-    FilePermission alsoReadAllFiles = new FilePermission("<<ALL FILES>>",
-            "read");
-
-    FilePermission allInCurrent = new FilePermission("*",
-            "read, write, execute,delete");
-
-    FilePermission readInCurrent = new FilePermission("*", "read");
-
-    FilePermission readInFile = new FilePermission("aFile.file", "read");
-
-    /**
-     * @tests java.io.FilePermission#FilePermission(java.lang.String,
-     *        java.lang.String)
-     */
-    public void test_ConstructorLjava_lang_StringLjava_lang_String() {
-        assertTrue("Used to test", true);
-        FilePermission constructFile = new FilePermission("test constructor",
-                "write");
-        assertEquals(
-                "action given to the constructor did not correspond - constructor failed",
-                "write", constructFile.getActions());
-        assertTrue(
-                "name given to the constructor did not correspond - constructor failed",
-                constructFile.getName() == "test constructor");
-
-        // Regression test for HARMONY-1050
-        try {
-            new FilePermission(null, "drink");
-            fail("Expected IAE");
-        } catch (IllegalArgumentException e) {
-            // Expected
-        }
-
-        try {
-            new FilePermission(null, "read");
-            fail("Expected NPE");
-        } catch (NullPointerException e) {
-            // Expected
-        }
-
-        try {
-            new FilePermission(null, null);
-            fail("Expected IAE");
-        } catch (IllegalArgumentException e) {
-            // Expected
-        }
-    }
-
-    /**
-     * @tests java.io.FilePermission#getActions()
-     */
-    public void test_getActions() {
-        assertEquals("getActions should have returned only read", "read",
-                readAllFiles.getActions());
-        assertEquals("getActions should have returned all actions",
-                "read,write,execute,delete", allInCurrent.getActions());
-    }
-
-    /**
-     * @tests java.io.FilePermission#equals(java.lang.Object)
-     */
-    public void test_equalsLjava_lang_Object() {
-        assertTrue(
-                "returned false when two instance of FilePermission is equal",
-                readAllFiles.equals(alsoReadAllFiles));
-        assertTrue(
-                "returned true when two instance	of FilePermission is not equal",
-                !(readInCurrent.equals(readInFile)));
-    }
-
-    /**
-     * @tests java.io.FilePermission#implies(java.security.Permission)
-     */
-    public void test_impliesLjava_security_Permission() {
-        assertTrue("Returned true for non-subset of actions", !readAllFiles
-                .implies(allInCurrent));
-        assertTrue("Returned true for non-subset of files", !allInCurrent
-                .implies(readAllFiles));
-        assertTrue("Returned false for subset of actions", allInCurrent
-                .implies(readInCurrent));
-        assertTrue("Returned false for subset of files", readAllFiles
-                .implies(readInCurrent));
-        assertTrue("Returned false for subset of files and actions",
-                allInCurrent.implies(readInFile));
-        assertTrue("Returned false for equal FilePermissions", readAllFiles
-                .implies(alsoReadAllFiles));
-
-        FilePermission fp3 = new FilePermission("/bob/*".replace('/',
-                File.separatorChar), "read,write");
-        FilePermission fp4 = new FilePermission("/bob/".replace('/',
-                File.separatorChar), "write");
-        assertTrue("returned true for same dir using * and not *", !fp3
-                .implies(fp4));
-        FilePermission fp5 = new FilePermission("/bob/file".replace('/',
-                File.separatorChar), "write");
-        assertTrue("returned false for same dir using * and file", fp3
-                .implies(fp5));
-
-        FilePermission fp6 = new FilePermission("/bob/".replace('/',
-                File.separatorChar), "read,write");
-        FilePermission fp7 = new FilePermission("/bob/*".replace('/',
-                File.separatorChar), "write");
-        assertTrue("returned false for same dir using not * and *", !fp6
-                .implies(fp7));
-        assertTrue("returned false for same subdir", fp6.implies(fp4));
-
-        FilePermission fp8 = new FilePermission("/".replace('/',
-                File.separatorChar), "read,write");
-        FilePermission fp9 = new FilePermission("/".replace('/',
-                File.separatorChar), "write");
-        assertTrue("returned false for same dir", fp8.implies(fp9));
-
-        FilePermission fp10 = new FilePermission("/".replace('/',
-                File.separatorChar), "read,write");
-        FilePermission fp11 = new FilePermission("/".replace('/',
-                File.separatorChar), "write");
-        assertTrue("returned false for same dir", fp10.implies(fp11));
-
-        FilePermission fp12 = new FilePermission("/*".replace('/',
-                File.separatorChar), "read,write");
-        assertTrue("returned false for same dir using * and dir", !fp12
-                .implies(fp10));
-
-        // Regression for HARMONY-47
-        char separator = File.separatorChar;
-        char nonSeparator = (separator == '/') ? '\\' : '/';
-
-        FilePermission fp1 = new FilePermission(nonSeparator + "*", "read");
-        FilePermission fp2 = new FilePermission(separator + "a", "read");
-        assertFalse("Assert 0: non-separator worked", fp1.implies(fp2));
-        fp1 = new FilePermission(nonSeparator + "-", "read");
-        assertFalse("Assert 1: non-separator worked", fp1.implies(fp2));
-    }
-
-    /**
-     * @tests java.io.FilePermission#newPermissionCollection()
-     */
-    public void test_newPermissionCollection() {
-        char s = File.separatorChar;
-        FilePermission perm[] = new FilePermission[4];
-        perm[0] = readAllFiles;
-        perm[1] = allInCurrent;
-        perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*",
-                "read,write");
-        perm[3] = new FilePermission(s + "tmp" + s + "test" + s
-                + "collection.file", "read");
-
-        PermissionCollection collect = perm[0].newPermissionCollection();
-        for (int i = 0; i < perm.length; i++) {
-            collect.add(perm[i]);
-        }
-        assertTrue("returned false for subset of files", collect
-                .implies(new FilePermission("*", "write")));
-        assertTrue("returned false for subset of name and action", collect
-                .implies(new FilePermission(s + "tmp", "read")));
-        assertTrue("returned true for non subset of file and action", collect
-                .implies(readInFile));
-
-        FilePermission fp1 = new FilePermission("/tmp/-".replace('/',
-                File.separatorChar), "read");
-        PermissionCollection fpc = fp1.newPermissionCollection();
-        fpc.add(fp1);
-        fpc.add(new FilePermission("/tmp/scratch/foo/*".replace('/',
-                File.separatorChar), "write"));
-        FilePermission fp2 = new FilePermission("/tmp/scratch/foo/file"
-                .replace('/', File.separatorChar), "read,write");
-        assertTrue("collection does not collate", fpc.implies(fp2));
-    }
-
-    /**
-     * @tests java.io.FilePermission#hashCode()
-     */
-    public void test_hashCode() {
-        assertTrue(
-                "two equal filePermission instances returned different hashCode",
-                readAllFiles.hashCode() == alsoReadAllFiles.hashCode());
-        assertTrue(
-                "two filePermission instances with same permission name returned same hashCode",
-                readInCurrent.hashCode() != allInCurrent.hashCode());
-
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.io;
+
+import java.io.File;
+import java.io.FilePermission;
+import java.security.PermissionCollection;
+
+import junit.framework.TestCase;
+
+public class FilePermissionTest extends TestCase {
+
+    FilePermission readAllFiles = new FilePermission("<<ALL FILES>>", "read");
+
+    FilePermission alsoReadAllFiles = new FilePermission("<<ALL FILES>>",
+            "read");
+
+    FilePermission allInCurrent = new FilePermission("*",
+            "read, write, execute,delete");
+
+    FilePermission readInCurrent = new FilePermission("*", "read");
+
+    FilePermission readInFile = new FilePermission("aFile.file", "read");
+
+    /**
+     * @tests java.io.FilePermission#FilePermission(java.lang.String,
+     *        java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+        assertTrue("Used to test", true);
+        FilePermission constructFile = new FilePermission("test constructor",
+                "write");
+        assertEquals(
+                "action given to the constructor did not correspond - constructor failed",
+                "write", constructFile.getActions());
+        assertTrue(
+                "name given to the constructor did not correspond - constructor failed",
+                constructFile.getName() == "test constructor");
+
+        // Regression test for HARMONY-1050
+        try {
+            new FilePermission(null, "drink");
+            fail("Expected IAE");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+
+        try {
+            new FilePermission(null, "read");
+            fail("Expected NPE");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            new FilePermission(null, null);
+            fail("Expected IAE");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+    }
+
+    /**
+     * @tests java.io.FilePermission#getActions()
+     */
+    public void test_getActions() {
+        assertEquals("getActions should have returned only read", "read",
+                readAllFiles.getActions());
+        assertEquals("getActions should have returned all actions",
+                "read,write,execute,delete", allInCurrent.getActions());
+    }
+
+    /**
+     * @tests java.io.FilePermission#equals(java.lang.Object)
+     */
+    public void test_equalsLjava_lang_Object() {
+        assertTrue(
+                "returned false when two instance of FilePermission is equal",
+                readAllFiles.equals(alsoReadAllFiles));
+        assertTrue(
+                "returned true when two instance	of FilePermission is not equal",
+                !(readInCurrent.equals(readInFile)));
+    }
+
+    /**
+     * @tests java.io.FilePermission#implies(java.security.Permission)
+     */
+    public void test_impliesLjava_security_Permission() {
+        assertTrue("Returned true for non-subset of actions", !readAllFiles
+                .implies(allInCurrent));
+        assertTrue("Returned true for non-subset of files", !allInCurrent
+                .implies(readAllFiles));
+        assertTrue("Returned false for subset of actions", allInCurrent
+                .implies(readInCurrent));
+        assertTrue("Returned false for subset of files", readAllFiles
+                .implies(readInCurrent));
+        assertTrue("Returned false for subset of files and actions",
+                allInCurrent.implies(readInFile));
+        assertTrue("Returned false for equal FilePermissions", readAllFiles
+                .implies(alsoReadAllFiles));
+
+        FilePermission fp3 = new FilePermission("/bob/*".replace('/',
+                File.separatorChar), "read,write");
+        FilePermission fp4 = new FilePermission("/bob/".replace('/',
+                File.separatorChar), "write");
+        assertTrue("returned true for same dir using * and not *", !fp3
+                .implies(fp4));
+        FilePermission fp5 = new FilePermission("/bob/file".replace('/',
+                File.separatorChar), "write");
+        assertTrue("returned false for same dir using * and file", fp3
+                .implies(fp5));
+
+        FilePermission fp6 = new FilePermission("/bob/".replace('/',
+                File.separatorChar), "read,write");
+        FilePermission fp7 = new FilePermission("/bob/*".replace('/',
+                File.separatorChar), "write");
+        assertTrue("returned false for same dir using not * and *", !fp6
+                .implies(fp7));
+        assertTrue("returned false for same subdir", fp6.implies(fp4));
+
+        FilePermission fp8 = new FilePermission("/".replace('/',
+                File.separatorChar), "read,write");
+        FilePermission fp9 = new FilePermission("/".replace('/',
+                File.separatorChar), "write");
+        assertTrue("returned false for same dir", fp8.implies(fp9));
+
+        FilePermission fp10 = new FilePermission("/".replace('/',
+                File.separatorChar), "read,write");
+        FilePermission fp11 = new FilePermission("/".replace('/',
+                File.separatorChar), "write");
+        assertTrue("returned false for same dir", fp10.implies(fp11));
+
+        FilePermission fp12 = new FilePermission("/*".replace('/',
+                File.separatorChar), "read,write");
+        assertTrue("returned false for same dir using * and dir", !fp12
+                .implies(fp10));
+
+        // Regression for HARMONY-47
+        char separator = File.separatorChar;
+        char nonSeparator = (separator == '/') ? '\\' : '/';
+
+        FilePermission fp1 = new FilePermission(nonSeparator + "*", "read");
+        FilePermission fp2 = new FilePermission(separator + "a", "read");
+        assertFalse("Assert 0: non-separator worked", fp1.implies(fp2));
+        fp1 = new FilePermission(nonSeparator + "-", "read");
+        assertFalse("Assert 1: non-separator worked", fp1.implies(fp2));
+    }
+
+    /**
+     * @tests java.io.FilePermission#newPermissionCollection()
+     */
+    public void test_newPermissionCollection() {
+        char s = File.separatorChar;
+        FilePermission perm[] = new FilePermission[4];
+        perm[0] = readAllFiles;
+        perm[1] = allInCurrent;
+        perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*",
+                "read,write");
+        perm[3] = new FilePermission(s + "tmp" + s + "test" + s
+                + "collection.file", "read");
+
+        PermissionCollection collect = perm[0].newPermissionCollection();
+        for (int i = 0; i < perm.length; i++) {
+            collect.add(perm[i]);
+        }
+        assertTrue("returned false for subset of files", collect
+                .implies(new FilePermission("*", "write")));
+        assertTrue("returned false for subset of name and action", collect
+                .implies(new FilePermission(s + "tmp", "read")));
+        assertTrue("returned true for non subset of file and action", collect
+                .implies(readInFile));
+
+        FilePermission fp1 = new FilePermission("/tmp/-".replace('/',
+                File.separatorChar), "read");
+        PermissionCollection fpc = fp1.newPermissionCollection();
+        fpc.add(fp1);
+        fpc.add(new FilePermission("/tmp/scratch/foo/*".replace('/',
+                File.separatorChar), "write"));
+        FilePermission fp2 = new FilePermission("/tmp/scratch/foo/file"
+                .replace('/', File.separatorChar), "read,write");
+        assertTrue("collection does not collate", fpc.implies(fp2));
+    }
+
+    /**
+     * @tests java.io.FilePermission#hashCode()
+     */
+    public void test_hashCode() {
+        assertTrue(
+                "two equal filePermission instances returned different hashCode",
+                readAllFiles.hashCode() == alsoReadAllFiles.hashCode());
+        assertTrue(
+                "two filePermission instances with same permission name returned same hashCode",
+                readInCurrent.hashCode() != allInCurrent.hashCode());
+
+    }
+}

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileReaderTest.java
Thu Jan 31 02:04:05 2008
@@ -24,7 +24,9 @@
 import java.io.FileWriter;
 import java.io.IOException;
 
-public class FileReaderTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class FileReaderTest extends TestCase {
 
     FileReader br;
 
@@ -101,14 +103,20 @@
     protected void tearDown() {
         try {
             bw.close();
+        } catch (Exception e) {
+            // Ignore
+        }
+        try {
             br.close();
         } catch (Exception e) {
+            // Ignore
         }
-
         try {
-            if (fis != null)
+            if (fis != null) {
                 fis.close();
+            }
         } catch (Exception e) {
+            // Ignore
         }
         f.delete();
     }



Mime
View raw message