harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r548170 - in /harmony/enhanced/classlib/branches/java6/modules/luni: make/ src/main/java/java/io/ src/main/native/luni/shared/ src/main/native/luni/unix/ src/test/java/org/apache/harmony/luni/tests/java/io/unix/ src/test/java/org/apache/har...
Date Mon, 18 Jun 2007 02:22:30 GMT
Author: tonywu
Date: Sun Jun 17 19:22:29 2007
New Revision: 548170

URL: http://svn.apache.org/viewvc?view=rev&rev=548170
Log:
new methods in java.io.File, java.io.File.canExecute(),java.io.File.setExecutable(boolean
and java.io.File.setExecutable(boolean, boolean)

Added:
    harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.ibm
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/unix/
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/windows/
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java
Modified:
    harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl
    harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl.interm
    harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.ibm
    harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86_64.drl
    harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.drl
    harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.ibm
    harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.drl
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/File.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/file.c
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.h

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl Sun Jun
17 19:22:29 2007
@@ -1,4 +1,5 @@
 org/apache/harmony/luni/tests/java/lang/ThreadTest.java
 org/apache/harmony/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
 tests/api/java/net/SocketTest.java
+org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java
 

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl.interm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl.interm?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl.interm
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.drl.interm
Sun Jun 17 19:22:29 2007
@@ -1,3 +1,4 @@
 #2315
 org/apache/harmony/luni/tests/java/net/InetAddressTest.java
 org/apache/harmony/tests/java/net/InetAddressTest.java
+org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.ibm?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.ibm (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86.ibm Sun Jun
17 19:22:29 2007
@@ -1,4 +1,5 @@
 tests/api/java/util/PropertiesTest.java
 org/apache/harmony/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
 org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
-org/apache/harmony/luni/tests/java/lang/PackageTest.java
\ No newline at end of file
+org/apache/harmony/luni/tests/java/lang/PackageTest.java
+org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86_64.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86_64.drl?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86_64.drl (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.linux.x86_64.drl Sun
Jun 17 19:22:29 2007
@@ -3,3 +3,4 @@
 org/apache/harmony/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
 tests/api/java/net/SocketTest.java
 tests/api/java/net/MulticastSocketTest.java
+org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.drl?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.drl (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.drl Sun
Jun 17 19:22:29 2007
@@ -0,0 +1 @@
+org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.ibm?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.ibm (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86.ibm Sun
Jun 17 19:22:29 2007
@@ -1,3 +1,4 @@
 tests/api/java/util/PropertiesTest.java
 org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
-org/apache/harmony/luni/tests/java/lang/PackageTest.java
\ No newline at end of file
+org/apache/harmony/luni/tests/java/lang/PackageTest.java
+org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.drl?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.drl
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.drl
Sun Jun 17 19:22:29 2007
@@ -1,2 +1,3 @@
 tests/api/java/net/MulticastSocketTest.java
 tests/api/java/util/ArrayListTest.java
+org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java

Added: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.ibm?view=auto&rev=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.ibm
(added)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.windows.x86_64.ibm
Sun Jun 17 19:22:29 2007
@@ -0,0 +1 @@
+org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/File.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/File.java?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/File.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/File.java
Sun Jun 17 19:22:29 2007
@@ -1327,4 +1327,94 @@
         char inSeparator = stream.readChar();
         path = path.replace(inSeparator, separatorChar);
     }
+    
+    /**
+	 * Manipulates the execute permission of the abstract path designated by
+	 * this file object.
+	 * 
+	 * @param executable
+	 *            To allow execute permission if true, otherwise disallow
+	 * @param ownerOnly
+	 *            To manipulate execute permission only for owner if true,
+	 *            otherwise for everyone. The manipulation will apply to
+	 *            everyone regardless of this value if the underlying system
+	 *            does not distinguish owner and other users.
+	 * @return true if and only if the operation succeeded. If the user does not
+	 *         have permission to change the access permissions of this abstract
+	 *         pathname the operation will fail. If the underlying file system
+	 *         does not support execute permission and the value of executable
+	 *         is false, this operation will fail.
+	 * @throws SecurityException -
+	 *             If a security manager exists and
+	 *             SecurityManager.checkWrite(java.lang.String) disallows write
+	 *             permission to this file object
+	 * @since 1.6
+	 */
+	public boolean setExecutable(boolean executable, boolean ownerOnly) {
+		checkWrite();
+		return (setExecutableImpl(properPath(true), executable, ownerOnly));
+	}
+
+	/**
+	 * A convenience method for setExecutable(boolean, boolean). An invocation
+	 * of this method is the same as file.setExecutable(executable, true).
+	 * 
+	 * @param executable
+	 *            To allow execute permission if true, otherwise disallow
+	 * @return true if and only if the operation succeeded. If the user does not
+	 *         have permission to change the access permissions of this abstract
+	 *         pathname the operation will fail. If the underlying file system
+	 *         does not support execute permission and the value of executable
+	 *         is false, this operation will fail.
+	 * @throws SecurityException -
+	 *             If a security manager exists and
+	 *             SecurityManager.checkWrite(java.lang.String) disallows write
+	 *             permission to this file object
+	 * @since 1.6
+	 */
+	public boolean setExecutable(boolean executable) {
+		return setExecutable(executable, true);
+	}
+
+	private native boolean setExecutableImpl(byte[] path, boolean executable,
+			boolean ownerOnly);
+	
+	  
+
+    /**
+     * Answers a boolean indicating whether or not the current context is
+     * allowed to execute this File.
+     * 
+     * @return <code>true</code> if this File can be executed,
+     *         <code>false</code> otherwise.
+     * 
+     * @throws SecurityException
+     *             If a security manager exists and
+     *             SecurityManager.checkExec(java.lang.String) disallows read
+     *             permission to this file object
+     * @see java.lang.SecurityManager#checkExec(FileDescriptor)
+     * 
+     * @since 1.6
+     */
+    public boolean canExecute() {
+        checkExec();
+        return exists() && isExecutableImpl(properPath(true));
+    }
+
+    private native boolean isExecutableImpl(byte[] filePath);
+
+    private void checkExec() {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkExec(path);
+        }
+    }
+
+    private void checkWrite() {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null) {
+			security.checkWrite(path);
+		}
+	}
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/file.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/file.c?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/file.c
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/file.c
Sun Jun 17 19:22:29 2007
@@ -520,5 +520,43 @@
 #else
   return TRUE;
 #endif
+}
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_setExecutableImpl (JNIEnv * env, jobject recv,
+                                   jbyteArray path, jboolean executable, jboolean ownerOnly)
+{
+
+#if (defined(WIN32))
+  return executable;
+#else
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  return setPlatformExecutable (env, pathCopy, executable, ownerOnly);
 
+#endif
+  
 }
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_File_isExecutableImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+#if (defined(WIN32))
+  return TRUE;
+#else
+  I_32 result;
+  char pathCopy[HyMaxPath];
+  jsize length = (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, (jbyte *)pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = getPlatformIsExecutable (env, pathCopy);
+  return result;
+#endif  
+} 
+

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt
Sun Jun 17 19:22:29 2007
@@ -255,3 +255,5 @@
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_oneTimeInitializationImpl
 Java_org_apache_harmony_luni_platform_Environment_getEnvBytes
 Java_org_apache_harmony_luni_platform_Environment_getEnvByName
+Java_java_io_File_setExecutableImp
+Java_java_io_File_isExecutableImp

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c
Sun Jun 17 19:22:29 2007
@@ -806,3 +806,34 @@
 	return 0;	
 }
 
+I_32
+getPlatformIsExecutable (JNIEnv * env, char *path)
+{
+  I_32 result;
+  struct stat buffer;
+
+  result = stat (path, &buffer);
+  if (result == -1)
+    return 0;
+
+  PORT_ACCESS_FROM_ENV (env);
+
+  //if the current user is 'root', then the file is executable when 
+  //either of user/group/others has the permission to execute.
+  // and the directory is always executable.
+  if (geteuid() == 0) {
+     if(HyIsDir == hyfile_attr (path)) {
+         return 1;
+     } else {
+         return (buffer.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0;
+     }
+  }
+
+  if (buffer.st_uid == geteuid ())
+    return (buffer.st_mode & S_IXUSR) != 0;
+  else if (buffer.st_gid == getegid ())
+    return (buffer.st_mode & S_IXGRP) != 0;
+
+  result = hasPrivilegeInOtherGroups(env, &buffer, S_IXGRP);
+  return -1 == result ? (buffer.st_mode & S_IXOTH) != 0 : result;
+}

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.h?view=diff&rev=548170&r1=548169&r2=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.h
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.h
Sun Jun 17 19:22:29 2007
@@ -61,4 +61,7 @@
 jboolean getPlatformSupportMulticast(JNIEnv * env, jstring ifname, jint index);
 jint getPlatformGetMTU(JNIEnv * env, jstring ifname, jint index);
 I_32 getPlatformGetInterfaceAddresses(JNIEnv * env, jstring ifname, jint index, interfaceAddressArray_struct*
interfaceAddressArray);
+I_32 getPlatformIsExecutable (JNIEnv * env, char *path);
+I_32 setPlatformExecutable (JNIEnv * env, char *path, jboolean executable, jboolean ownerOnly);
 #endif /* helpers_h */
+

Added: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java?view=auto&rev=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java
(added)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/unix/UnixFileTest.java
Sun Jun 17 19:22:29 2007
@@ -0,0 +1,142 @@
+package org.apache.harmony.luni.tests.java.io.unix;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * Please note that this case can only be passed on Linux due to some file
+ * system dependent reason.
+ * 
+ */
+public class UnixFileTest extends TestCase {
+	private boolean root = false;
+	
+	private File testFile;
+
+	private File testDir;
+
+	/**
+	 * @tests java.io.File#canExecute()
+	 * 
+	 * @since 1.6
+	 */
+	public void test_canExecute() {		
+		assertFalse(testFile.canExecute());
+		assertTrue(testFile.setExecutable(true, false));
+		assertTrue(testFile.canExecute());
+		assertTrue(testFile.setExecutable(true, true));
+		assertTrue(testFile.canExecute());
+
+		assertTrue(testFile.setExecutable(false, false));
+		assertFalse(testFile.canExecute());
+		assertTrue(testFile.setExecutable(false, true));
+		assertFalse(testFile.canExecute());
+
+		assertTrue(testFile.setExecutable(true, false));
+		assertTrue(testFile.canExecute());
+
+		// tests directory
+		assertTrue(testDir.canExecute());
+		assertTrue(testDir.setExecutable(false, true));
+		if (root) {
+			assertTrue(testDir.canExecute());
+		} else {
+			assertFalse(testDir.canExecute());			
+		}		
+		assertTrue(testDir.setExecutable(true, false));
+		assertTrue(testDir.canExecute());
+	}
+
+	/**
+	 * @tests java.io.File#setExecutable(boolean, boolean)
+	 * 
+	 * @since 1.6
+	 */
+	public void test_setExecutableZZ() {		
+		// setExecutable(true, true/false)
+		assertFalse(testFile.canExecute());
+		assertTrue(testFile.setExecutable(true, false));
+		assertTrue(testFile.canExecute());
+		assertTrue(testFile.setExecutable(true, true));
+		assertTrue(testFile.canExecute());
+
+		// setExecutable(false, true/false)
+		assertTrue(testFile.setExecutable(false, true));
+		if (root) {
+			assertTrue(testFile.canExecute());			
+		} else {
+			assertFalse(testFile.canExecute());			
+		}		
+		assertTrue(testFile.setExecutable(false, false));
+		assertFalse(testFile.canExecute());
+
+		// tests directory
+		assertTrue(testDir.canExecute());
+		assertTrue(testDir.setExecutable(false, true));
+		if (root) {
+			assertTrue(testDir.canExecute());
+		} else {
+			assertFalse(testDir.canExecute());
+		}
+		assertTrue(testDir.setExecutable(false, false));
+		if (root) {
+			assertTrue(testDir.canExecute());
+		} else {
+			assertFalse(testDir.canExecute());
+		}
+
+		assertTrue(testDir.setExecutable(true, true));
+		assertTrue(testDir.canExecute());
+		assertTrue(testDir.setExecutable(true, false));
+		assertTrue(testDir.canExecute());
+	}
+
+	/**
+	 * @tests java.io.File#setExecutable(boolean)
+	 * 
+	 * @since 1.6
+	 */
+	public void test_setExecutableZ() {
+		// So far this method only deals with the situation that the user is the
+		// owner of the file
+		assertTrue(testFile.setExecutable(true));
+		assertTrue(testFile.canExecute());
+		assertTrue(testFile.setExecutable(false));
+		assertFalse(testFile.canExecute());
+		assertTrue(testFile.setExecutable(true));
+
+		// tests directory
+		assertTrue(testDir.canExecute());
+		assertTrue(testDir.setExecutable(false));
+		if (root) {
+			assertTrue(testDir.canExecute());
+		} else {
+			assertFalse(testDir.canExecute());			
+		}		
+		assertTrue(testDir.setExecutable(true));
+		assertTrue(testDir.canExecute());
+	}
+
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		testFile = File.createTempFile("testfile", null);
+		testDir = new File(System.getProperty("java.io.tmpdir") + "/temp");
+		if (!testDir.exists()) {
+			testDir.mkdir();
+		}
+		root = System.getProperty("user.name").equals("root");
+	}
+
+	@Override
+	protected void tearDown() throws Exception {
+		testFile.delete();
+		testDir.delete();
+		testFile = null;
+		testDir = null;
+		root = false;
+		super.tearDown();
+	}
+
+}

Added: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java?view=auto&rev=548170
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java
(added)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/windows/WinFileTest.java
Sun Jun 17 19:22:29 2007
@@ -0,0 +1,94 @@
+package org.apache.harmony.luni.tests.java.io.windows;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * Please note that this case can only be passed on Windows due to some file
+ * system dependent reason.
+ * 
+ */
+
+public class WinFileTest extends TestCase {
+	private File testFile;
+
+	private File testDir;	
+
+	/**
+	 * @tests java.io.File#canExecute()
+	 * 
+	 * @since 1.6
+	 */
+	public void test_canExecute() {
+		// files and directories are always executable on Windows.
+		assertTrue(testFile.canExecute());
+		assertFalse(testFile.setExecutable(false, false));
+		assertTrue(testFile.canExecute());
+		assertTrue(testFile.setExecutable(true));
+		assertTrue(testFile.canExecute());
+
+		assertFalse(testDir.setExecutable(false, false));
+		assertTrue(testDir.canExecute());
+	}
+	
+	/**
+	 * @tests java.io.File#setExecutable(boolean, boolean)
+	 * 
+	 * @since 1.6
+	 */
+	public void test_setExecutableZZ() {
+		// setExecutable(false, true/false) fails on Windows.
+		assertTrue(testFile.canExecute());
+		assertFalse(testFile.setExecutable(false, false));
+		assertTrue(testFile.canExecute());
+		assertFalse(testFile.setExecutable(false, true));
+		// setExecutable(true, true/false)
+		assertTrue(testFile.setExecutable(true, false));
+		assertTrue(testFile.canExecute());
+		assertTrue(testFile.setExecutable(true, true));
+
+		// tests directory
+		assertTrue(testDir.canExecute());
+		assertFalse(testDir.setExecutable(false, true));
+		assertTrue(testDir.canExecute());
+		assertFalse(testDir.setExecutable(false, false));
+
+		assertTrue(testDir.setExecutable(true, true));
+		assertTrue(testDir.setExecutable(true, false));
+		assertTrue(testDir.canExecute());
+	}
+
+	/**
+	 * @tests java.io.File#setExecutable(boolean)
+	 * 
+	 * @since 1.6
+	 */
+	public void test_setExecutableZ() {
+		// So far this method only deals with the situation that the user is the
+		// owner of the file
+		assertTrue(testFile.setExecutable(true));
+		assertFalse(testFile.setExecutable(false));
+		// tests directory
+		assertTrue(testDir.setExecutable(true));
+		assertFalse(testDir.setExecutable(false));
+		assertTrue(testDir.canExecute());
+	}
+
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		testFile = File.createTempFile("testfile", null);
+		testDir = new File(System.getProperty("java.io.tmpdir"));
+	}
+
+	@Override
+	protected void tearDown() throws Exception {
+		testFile.deleteOnExit();
+		testDir.deleteOnExit();
+		testFile = null;
+		testDir = null;
+		super.tearDown();
+	}
+
+}



Mime
View raw message