public inbox for mauve-discuss@sourceware.org
 help / color / mirror / Atom feed
* More tests for 4 java.io classes
@ 2002-12-16  7:58 David King
  2002-12-19 19:10 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: David King @ 2002-12-16  7:58 UTC (permalink / raw)
  To: mauve-discuss

[-- Attachment #1: Type: text/plain, Size: 4840 bytes --]

Attached are new tests for java.io.FileDescriptor and
java.io.FilePermission, and updated tests for java.io.FileInputStream and
java.io.FileOutputStream.  I believe that all of the methods for 1.4 are
now tested for these classes.

The results of these tests with Classpath CVS and Kissme CVS are:

gnu.testlet.java.io.FileDescriptor.Test
----
PASS: gnu.testlet.java.io.FileDescriptor.Test (number 1)
PASS: gnu.testlet.java.io.FileDescriptor.Test (number 2)
PASS: gnu.testlet.java.io.FileDescriptor.Test (number 3)
PASS: gnu.testlet.java.io.FileDescriptor.Test (number 4)
0 of 4 tests failed
gnu.testlet.java.io.FileInputStream.read
----
PASS: gnu.testlet.java.io.FileInputStream.read: Empty file created (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: empty byte[] read (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: Nonexistent file detected (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: Nonempty file created (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: available (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: skip length (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: available skipped (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: read length (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: read data match (number 1)
PASS: gnu.testlet.java.io.FileInputStream.read: descriptor (number 1)
0 of 10 tests failed
gnu.testlet.java.io.FileInputStream.GetChannel
----
PASS: gnu.testlet.java.io.FileInputStream.GetChannel: channel open (number 1)
0 of 1 tests failed
gnu.testlet.java.io.FileOutputStream.write
----
PASS: gnu.testlet.java.io.FileOutputStream.write: FileDescriptor (number 1)
PASS: gnu.testlet.java.io.FileOutputStream.write: data read (number 1)
0 of 2 tests failed
gnu.testlet.java.io.FileOutputStream.GetChannel
----
PASS: gnu.testlet.java.io.FileOutputStream.GetChannel: channel open (number 1)
0 of 1 tests failed
gnu.testlet.java.io.FilePermission.Tests
----
PASS: gnu.testlet.java.io.FilePermission.Tests: path 1 (number 1)
PASS: gnu.testlet.java.io.FilePermission.Tests: path 2 (number 1)
FAIL: gnu.testlet.java.io.FilePermission.Tests: getActions (number 1)
got execute,read but expected read,execute
FAIL: gnu.testlet.java.io.FilePermission.Tests: implies 1 (number 1)
FAIL: gnu.testlet.java.io.FilePermission.Tests: implies 2 (number 1)
java.lang.StringIndexOutOfBoundsException: String index out of range: 23
   at java.lang.String.charAt (String.java:498)
   at java.io.FilePermission.implies (FilePermission.java:231)
   at gnu.testlet.java.io.FilePermission.Tests.test (Tests.java:49)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:219)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:312)
FAIL: gnu.testlet.java.io.FilePermission.Tests: implies 3 (number 1)
java.lang.StringIndexOutOfBoundsException: String index out of range: 27
   at java.lang.String.charAt (String.java:498)
   at java.io.FilePermission.implies (FilePermission.java:231)
   at gnu.testlet.java.io.FilePermission.Tests.test (Tests.java:62)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:219)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:312)
FAIL: gnu.testlet.java.io.FilePermission.Tests: implies 4 (number 1)
FAIL: gnu.testlet.java.io.FilePermission.Tests: implies 5 (number 1)
java.lang.StringIndexOutOfBoundsException: String index out of range: 10
   at java.lang.String.charAt (String.java:498)
   at java.io.FilePermission.implies (FilePermission.java:231)
   at gnu.testlet.java.io.FilePermission.Tests.test (Tests.java:79)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:219)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:312)
FAIL: gnu.testlet.java.io.FilePermission.Tests: equals 1 (number 1)
java.lang.StringIndexOutOfBoundsException: String index out of range: 9
   at java.lang.String.charAt (String.java:498)
   at java.io.FilePermission.equals (FilePermission.java:139)
   at gnu.testlet.java.io.FilePermission.Tests.test (Tests.java:91)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:219)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:312)
FAIL: gnu.testlet.java.io.FilePermission.Tests: equals 2 (number 1)
java.lang.StringIndexOutOfBoundsException: String index out of range: 9
   at java.lang.String.charAt (String.java:498)
   at java.io.FilePermission.equals (FilePermission.java:139)
   at gnu.testlet.java.io.FilePermission.Tests.test (Tests.java:100)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:219)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:312)
8 of 10 tests failed

As you can see, Classpath's FilePermission seems to have a number of
problems.

I'll be pressing on with java.io and the 1.4 spec.

David King


[-- Attachment #2: Type: text/plain, Size: 15355 bytes --]

diff -u -r -N mauve-orig/gnu/testlet/java/io/FileDescriptor/Test.java mauve/gnu/testlet/java/io/FileDescriptor/Test.java
--- mauve-orig/gnu/testlet/java/io/FileDescriptor/Test.java	1969-12-31 18:00:00.000000000 -0600
+++ mauve/gnu/testlet/java/io/FileDescriptor/Test.java	2002-12-16 09:32:22.000000000 -0600
@@ -0,0 +1,61 @@
+/*************************************************************************
+/* Test.java -- FileDescriptor tests.
+/*
+/* Copyright (c) 2002 Free Software Foundation, Inc.
+/* Written by David J. King (david_king@softhome.net)
+/*
+/* This program is free software; you can redistribute it and/or modify
+/* it under the terms of the GNU General Public License as published 
+/* by the Free Software Foundation, either version 2 of the License, or
+/* (at your option) any later version.
+/*
+/* This program is distributed in the hope that it will be useful, but
+/* WITHOUT ANY WARRANTY; without even the implied warranty of
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+/* GNU General Public License for more details.
+/*
+/* You should have received a copy of the GNU General Public License
+/* along with this program; if not, write to the Free Software Foundation
+/* Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
+/*************************************************************************/
+
+// Tags: JDK1.0
+
+package gnu.testlet.java.io.FileDescriptor;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import java.io.*;
+
+public class Test implements Testlet
+{
+public void test(TestHarness harness)
+{
+  /*
+   * Verify that the three standard descriptors are valid.
+   */
+  boolean pass = FileDescriptor.in.valid();
+  harness.check(pass);
+  pass = FileDescriptor.out.valid();
+  harness.check(pass);
+  pass = FileDescriptor.err.valid();
+  harness.check(pass);
+  /*
+   * Create a temporary file and see if sync() and close() work
+   * without causing an error.
+   */
+  pass = true;
+  try {
+    File tempFile = File.createTempFile("javaiofiledescriptor", "null");
+    FileOutputStream outputStream = new FileOutputStream(tempFile);
+    outputStream.write(32);
+    outputStream.getFD().sync();
+    outputStream.close();
+    tempFile.delete();
+  } catch (Exception e) {
+    pass = false;
+  }
+  harness.check(pass);
+}
+
+} //Test
diff -u -r -N mauve-orig/gnu/testlet/java/io/FileInputStream/GetChannel.java mauve/gnu/testlet/java/io/FileInputStream/GetChannel.java
--- mauve-orig/gnu/testlet/java/io/FileInputStream/GetChannel.java	1969-12-31 18:00:00.000000000 -0600
+++ mauve/gnu/testlet/java/io/FileInputStream/GetChannel.java	2002-12-16 09:32:50.000000000 -0600
@@ -0,0 +1,52 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Written by David J. King (david_king@softhome.net)
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.  */
+
+package gnu.testlet.java.io.FileInputStream;
+
+import java.io.*;
+import java.nio.channels.*;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+
+public class GetChannel implements Testlet
+{
+  public void test (TestHarness harness)
+  {
+    String tmpfile = harness.getTempDirectory()
+		     + File.separator + "mauve-filein.tst";
+    File f = new File(tmpfile);
+    try
+      {
+	f.createNewFile();
+	FileInputStream inputStream = new FileInputStream(tmpfile);
+	FileChannel fileChannel = inputStream.getChannel();
+	harness.check(fileChannel.isOpen(), "channel open");
+	inputStream.close();
+      }
+    catch (Throwable t)
+      {
+	harness.fail("Empty file created and opened");
+      }
+    f.delete();
+  }
+}
diff -u -r -N mauve-orig/gnu/testlet/java/io/FileInputStream/read.java mauve/gnu/testlet/java/io/FileInputStream/read.java
--- mauve-orig/gnu/testlet/java/io/FileInputStream/read.java	2002-10-28 14:05:59.000000000 -0600
+++ mauve/gnu/testlet/java/io/FileInputStream/read.java	2002-12-16 09:32:57.000000000 -0600
@@ -2,6 +2,7 @@
 
 // Copyright (C) 2002 Free Software Foundation, Inc.
 // Written by Mark Wielaard (mark@klomp.org)
+// Modified by David J. King (david_king@softhome.net)
 
 // This file is part of Mauve.
 
@@ -22,8 +23,7 @@
 
 package gnu.testlet.java.io.FileInputStream;
 
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.*;
 
 import gnu.testlet.Testlet;
 import gnu.testlet.TestHarness;
@@ -52,6 +52,56 @@
 	// Cleanup
 	f.delete();
       }
+    FileInputStream inputStream = null;
+    boolean pass = false;
+    try
+      {
+	inputStream = new FileInputStream(tmpfile);
+      }
+    catch (FileNotFoundException fe)
+      {
+	pass = true;
+      }
+    harness.check(pass, "Nonexistent file detected");
+    pass = true;
+    String testString = "Here is a 29-byte test string";
+    byte[] testBytes = testString.getBytes();
+    try
+      {
+	FileOutputStream outputStream = new FileOutputStream(f);
+	outputStream.write(testBytes);
+	outputStream.close();
+      }
+    catch (Throwable t)
+      {
+	pass = false;
+      }
+    harness.check(pass, "Nonempty file created");
+    try
+      {
+	inputStream = new FileInputStream(f);
+	harness.check(inputStream.available(), testBytes.length, "available");
+	long skipped = inputStream.skip(5);
+	harness.check(skipped, 5, "skip length");
+	harness.check(inputStream.available(), testBytes.length - 5, "available skipped");
+	byte[] inBuffer = new byte[testBytes.length - 5];
+	harness.check(inputStream.read(inBuffer, 0, testBytes.length - 5),
+		      testBytes.length - 5, "read length");
+	pass = true;
+	for (int i=0; i < testBytes.length - 5; i++)
+	  {
+	    if (inBuffer[i] != testBytes[i+5])
+	      pass = false;
+	  }
+	harness.check(pass, "read data match");
+	FileDescriptor descriptor = inputStream.getFD();
+        harness.check(descriptor.valid(), "descriptor");
+	inputStream.close();
+      }
+    catch (Throwable t)
+      {
+	harness.fail("Exception doing nonempty tests");
+      }
+      f.delete();
   }
 }
-
diff -u -r -N mauve-orig/gnu/testlet/java/io/FileOutputStream/GetChannel.java mauve/gnu/testlet/java/io/FileOutputStream/GetChannel.java
--- mauve-orig/gnu/testlet/java/io/FileOutputStream/GetChannel.java	1969-12-31 18:00:00.000000000 -0600
+++ mauve/gnu/testlet/java/io/FileOutputStream/GetChannel.java	2002-12-16 09:33:08.000000000 -0600
@@ -0,0 +1,51 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Written by David J. King (david_king@softhome.net)
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.  */
+
+package gnu.testlet.java.io.FileOutputStream;
+
+import java.io.*;
+import java.nio.channels.*;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+
+public class GetChannel implements Testlet
+{
+  public void test (TestHarness harness)
+  {
+    String tmpfile = harness.getTempDirectory()
+		     + File.separator + "mauve-fileout.tst";
+    File f = new File(tmpfile);
+    try
+      {
+	FileOutputStream outputStream = new FileOutputStream(tmpfile);
+	FileChannel fileChannel = outputStream.getChannel();
+	harness.check(fileChannel.isOpen(), "channel open");
+	outputStream.close();
+      }
+    catch (Throwable t)
+      {
+	harness.fail("Empty file created and opened");
+      }
+    f.delete();
+  }
+}
diff -u -r -N mauve-orig/gnu/testlet/java/io/FileOutputStream/write.java mauve/gnu/testlet/java/io/FileOutputStream/write.java
--- mauve-orig/gnu/testlet/java/io/FileOutputStream/write.java	2002-10-28 14:05:59.000000000 -0600
+++ mauve/gnu/testlet/java/io/FileOutputStream/write.java	2002-12-16 09:33:15.000000000 -0600
@@ -2,6 +2,7 @@
 
 // Copyright (C) 2002 Free Software Foundation, Inc.
 // Written by Mark Wielaard (mark@klomp.org)
+// Modified by David J. King (david_king@softhome.net)
 
 // This file is part of Mauve.
 
@@ -22,8 +23,7 @@
 
 package gnu.testlet.java.io.FileOutputStream;
 
-import java.io.File;
-import java.io.FileOutputStream;
+import java.io.*;
 
 import gnu.testlet.Testlet;
 import gnu.testlet.TestHarness;
@@ -34,21 +34,45 @@
   {
     String tmpfile = harness.getTempDirectory()
 	    + File.separator + "mauve-fileout.tst";
+    String testString = "Here is a 30-byte test string\n";
+    String targetString = testString + ' ' + "is";
+    byte[] testBytes = testString.getBytes();
+    byte[] targetBytes = targetString.getBytes();
+    FileOutputStream outputStream = null;
+    File file = new File(tmpfile);
+    file.delete();
     try
       {
-	new FileOutputStream(tmpfile).write(new byte[0]);
-	harness.check(new File(tmpfile).exists(), "empty byte[] write");
+	outputStream = new FileOutputStream(file);
+	outputStream.write(testBytes);
+	outputStream.flush();
+	outputStream.close();
+	outputStream = new FileOutputStream(tmpfile, true);
+	outputStream.write(32); // ASCII space
+	outputStream.write(testBytes, 5, 2);
+	FileDescriptor fileDescriptor = outputStream.getFD();
+	harness.check(fileDescriptor.valid(), "FileDescriptor");
+	outputStream.close();
+	FileInputStream inputStream = new FileInputStream(tmpfile);
+	byte[] inBuffer = new byte[targetBytes.length];
+	inputStream.read(inBuffer, 0, inBuffer.length);
+	boolean pass = true;
+	for (int i = 0; i < targetBytes.length; i++)
+	  {
+	    if (inBuffer[i] != targetBytes[i])
+	      pass = false;
+	  }
+	harness.check(pass, "data read");
       }
     catch(Throwable t)
       {
-	harness.fail("empty byte[] write");
+	harness.fail("stream operation");
 	harness.debug(t);
       }
     finally
       {
 	// Cleanup
-	File f = new File(tmpfile);
-	f.delete();
+	file.delete();
       }
   }
 }
diff -u -r -N mauve-orig/gnu/testlet/java/io/FilePermission/Tests.java mauve/gnu/testlet/java/io/FilePermission/Tests.java
--- mauve-orig/gnu/testlet/java/io/FilePermission/Tests.java	1969-12-31 18:00:00.000000000 -0600
+++ mauve/gnu/testlet/java/io/FilePermission/Tests.java	2002-12-16 09:33:33.000000000 -0600
@@ -0,0 +1,109 @@
+// Tags: JDK1.2
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Written by David J. King (david_king@softhome.net)
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.  */
+
+package gnu.testlet.java.io.FilePermission;
+
+import java.io.File;
+import java.io.FilePermission;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+
+public class Tests implements Testlet
+{
+
+public void test (TestHarness harness)
+{
+  // Make some permissions and see if they contain the right data
+  FilePermission permission1 = new FilePermission("*", "execute,read");
+  FilePermission permission2 = new FilePermission("file2", "execute");
+  harness.check(permission1.getName(), "*", "path 1");
+  harness.check(permission2.getName(), "file2", "path 2");
+  harness.check(permission1.getActions(), "read,execute", "getActions");
+  // Verify that read and execute of "*" implies execute of "file2"
+  harness.checkPoint("implies 1");
+  harness.check(permission1.implies(permission2));
+  // Verify that the reverse is not true
+  try
+    {
+      boolean pass = true;
+      if (permission2.implies(permission1))
+        pass = false;
+      harness.check(pass, "implies 2");
+  }
+  catch (Throwable t)
+    {
+      harness.fail("implies 2");
+      harness.debug(t);
+    }
+  // Verify that read,write,execute of file2 implies execute of file2
+  FilePermission permission3 = new FilePermission("file2", "read,write,execute");
+  try
+    {
+      harness.check(permission3.implies(permission2), "implies 3");
+    }
+  catch (Throwable t)
+    {
+      harness.fail("implies 3");
+      harness.debug(t);
+  }
+  // Verify that read,write of /tmp/* implies write of /tmp/file2
+  permission1 = new FilePermission(File.separatorChar + "tmp" + File.separatorChar + "*",
+                                   "write,read");
+  permission2 = new FilePermission(File.separatorChar + "tmp" + File.separatorChar + "file2",
+                                   "write");
+  harness.check(permission1.implies(permission2), "implies 4");
+  // Verify that read,write,execute,delete of <<ALL FILES>> implies write of /tmp/file2
+  permission1 = new FilePermission("<<ALL FILES>>", "read,write,execute,delete");
+  try
+    {
+      harness.check(permission1.implies(permission2), "implies 5");
+    }
+  catch (Throwable t)
+    {
+      harness.fail("implies 5");
+      harness.debug(t);
+    }
+  // Verify equals works, positively and negatively
+  permission3 = new FilePermission(File.separatorChar + "tmp" + File.separatorChar + "file",
+                                   "write");
+  try
+    {
+      harness.check(permission3.equals(permission2), "equals 1");
+    }
+  catch (Throwable t)
+    {
+      harness.fail("equals 1");
+      harness.debug(t);
+    }
+  try
+    {
+      harness.check(! permission3.equals(permission1), "equals 2");
+    }
+  catch (Throwable t)
+    {
+      harness.fail("equals 2");
+      harness.debug(t);
+    }
+}
+
+}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: More tests for 4 java.io classes
  2002-12-16  7:58 More tests for 4 java.io classes David King
@ 2002-12-19 19:10 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2002-12-19 19:10 UTC (permalink / raw)
  To: David King; +Cc: mauve-discuss

>>>>> "David" == David King <david_king@softhome.net> writes:

David> Attached are new tests for java.io.FileDescriptor and
David> java.io.FilePermission, and updated tests for
David> java.io.FileInputStream and java.io.FileOutputStream.  I
David> believe that all of the methods for 1.4 are now tested for
David> these classes.

Hi David.  I'm not ignoring this email, but my time is very limited
this week (I'm leaving for the holidays soon).  If nobody has dealt
with this while I'm gone, I'll have a look when I get back.

Also, if these tests look good I'll send you info on getting write
access.  Or, if somebody else looks at the tests they can do that too.
Thanks.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-12-20  3:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-16  7:58 More tests for 4 java.io classes David King
2002-12-19 19:10 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).