You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gh...@apache.org on 2006/06/26 15:56:41 UTC

svn commit: r417193 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels: AllTests.java FileLockTest.java

Author: gharley
Date: Mon Jun 26 06:56:40 2006
New Revision: 417193

URL: http://svn.apache.org/viewvc?rev=417193&view=rev
Log:
HARMONY 662 : Tests for java.nio.channels.FileLock are missing

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java   (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java?rev=417193&r1=417192&r2=417193&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java Mon Jun 26 06:56:40 2006
@@ -37,6 +37,7 @@
         suite.addTestSuite(SelectorTest.class);
         suite.addTestSuite(AlreadyConnectedExceptionTest.class);
         suite.addTestSuite(SelectableChannelTest.class);
+        suite.addTestSuite(FileLockTest.class);
         //$JUnit-END$
         return suite;
     }

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java?rev=417193&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java Mon Jun 26 06:56:40 2006
@@ -0,0 +1,149 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.tests.java.nio.channels;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests class FileLock.
+ */
+public class FileLockTest extends TestCase {
+
+	private FileChannel readWriteChannel;
+
+	private MockFileLock mockLock;
+
+	class MockFileLock extends FileLock {
+
+		boolean isValid = true;
+
+		protected MockFileLock(FileChannel channel, long position, long size,
+				boolean shared) {
+			super(channel, position, size, shared);
+		}
+
+		public boolean isValid() {
+			return isValid;
+		}
+
+		public void release() throws IOException {
+			isValid = false;
+		}
+	}
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		File tempFile = File.createTempFile("testing", "tmp");
+		tempFile.deleteOnExit();
+		RandomAccessFile randomAccessFile = new RandomAccessFile(tempFile, "rw");
+		readWriteChannel = randomAccessFile.getChannel();
+		mockLock = new MockFileLock(readWriteChannel, 10, 100, false);
+	}
+
+	/**
+	 * @tests java.nio.channels.FileLock#FileLock(FileChannel, long, long,
+	 *        boolean)
+	 */
+	public void test_Constructor_Ljava_nio_channels_FileChannelJJZ() {
+		FileLock fileLock1 = new MockFileLock(null, 0, 0, false);
+		assertNull(fileLock1.channel());
+
+		try {
+			new MockFileLock(readWriteChannel, -1, 0, false);
+			fail("should throw IllegalArgumentException.");
+		} catch (IllegalArgumentException ex) {
+			// expected
+		}
+		try {
+			new MockFileLock(readWriteChannel, 0, -1, false);
+			fail("should throw IllegalArgumentException.");
+		} catch (IllegalArgumentException ex) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.FileLock#channel()
+	 */
+	public void test_channel() {
+		assertSame(readWriteChannel, mockLock.channel());
+		FileLock lock = new MockFileLock(null, 0, 10, true);
+		assertNull(lock.channel());
+	}
+
+	/**
+	 * @tests java.nio.channels.FileLock#position()
+	 */
+	public void test_position() {
+		FileLock fileLock1 = new MockFileLock(readWriteChannel, 20, 100, true);
+		assertEquals(20, fileLock1.position());
+
+		final long position = ((long) Integer.MAX_VALUE + 1);
+		FileLock fileLock2 = new MockFileLock(readWriteChannel, position, 100,
+				true);
+		assertEquals(position, fileLock2.position());
+	}
+
+	/**
+	 * @tests java.nio.channels.FileLock#size()
+	 */
+	public void test_size() {
+		FileLock fileLock1 = new MockFileLock(readWriteChannel, 20, 100, true);
+		assertEquals(100, fileLock1.size());
+
+		final long position = 0x0FFFFFFFFFFFFFFFL;
+		final long size = ((long) Integer.MAX_VALUE + 1);
+		FileLock fileLock2 = new MockFileLock(readWriteChannel, position, size,
+				true);
+		assertEquals(size, fileLock2.size());
+	}
+
+	/**
+	 * @tests java.nio.channels.FileLock#isShared()
+	 */
+	public void test_isShared() {
+		assertFalse(mockLock.isShared());
+		FileLock lock = new MockFileLock(null, 0, 10, true);
+		assertTrue(lock.isShared());
+	}
+
+	/**
+	 * @tests java.nio.channels.FileLock#overlaps(long, long)
+	 */
+	public void test_overlaps_JJ() {
+		assertTrue(mockLock.overlaps(0, 11));
+		assertFalse(mockLock.overlaps(0, 10));
+		assertTrue(mockLock.overlaps(100, 110));
+		assertTrue(mockLock.overlaps(99, 110));
+		assertFalse(mockLock.overlaps(-1, 10));
+	}
+
+	/**
+	 * @tests java.nio.channels.FileLock#isValid()
+	 */
+	public void test_isValid() throws IOException {
+		FileLock fileLock = readWriteChannel.lock();
+		assertTrue(fileLock.isValid());
+		fileLock.release();
+		assertFalse(fileLock.isValid());
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java
------------------------------------------------------------------------------
    svn:eol-style = native