This is the mail archive of the mauve-discuss@sources.redhat.com mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: using configure to tune tests?


Brian Jones <cbj@gnu.org> writes:

> This is an idea (not a patch I want applied at the moment) that uses
> configure to determine some property of the host environment and tunes
> a specific test for that host.  Is this acceptable?  I didn't include
> an updated configure here, nor the things autogenerated by
> aclocal;autoheader, etc.  Why are those even checked into mauve?

Okay, so I've gone ahead and used this to write a java.io.File test
that covers basic Java 1.1 functionality.  In writing this, I have
discovered that Sun's JDK 1.3 File class behaves unexpectedly when you
use renameTo(File).  It appears that Sun does not change the path of
the File object that makes the renameTo call, and subsequently they
fail 4 of the 48 included tests.  

I should write a ChangeLog entry for this diff and probably verify
that it is a working diff for my changes.
-- 
Brian Jones <cbj@gnu.org>

diff -uNr mauve.orig/acinclude.m4 mauve/acinclude.m4
--- mauve.orig/acinclude.m4	Wed Dec 31 19:00:00 1969
+++ mauve/acinclude.m4	Thu Feb  8 23:46:53 2001
@@ -0,0 +1,31 @@
+dnl -----------------------------------------------------------
+dnl Original by Mark Elbrecht <snowball3@bigfoot.com> 
+dnl Modified by Brian Jones <cbj@gnu.org> for Mauve
+dnl acx_check_pathname_style.m4 
+dnl http://research.cys.de/autoconf-archive/
+
+AC_DEFUN(ACX_CHECK_PATHNAME_STYLE_DOS,
+[AC_MSG_CHECKING(for Windows and DOS and OS/2 style pathnames)
+AC_CACHE_VAL(acx_cv_pathname_style_dos, 
+  [AC_REQUIRE([AC_CANONICAL_HOST])
+  acx_cv_pathname_style_dos="no"
+  case ${host_os} in
+    *djgpp | *mingw32* | *emx*) acx_cv_pathname_style_dos="yes" ;;
+  esac
+  ])
+AC_MSG_RESULT($acx_cv_pathname_style_dos)
+if test "$acx_cv_pathname_style_dos" = "yes"; then
+  AC_DEFINE(HAVE_PATHNAME_STYLE_DOS,,[defined if running on a system with dos style paths])
+  PATH_SEPARATOR=';'
+  FILE_SEPARATOR='\\'
+  AC_SUBST(PATH_SEPARATOR)
+  AC_SUBST(FILE_SEPARATOR)
+else
+  PATH_SEPARATOR=':'
+  FILE_SEPARATOR='/'
+  AC_SUBST(PATH_SEPARATOR)
+  AC_SUBST(FILE_SEPARATOR)
+fi
+])
+
+dnl -----------------------------------------------------------
diff -uNr mauve.orig/aclocal.m4 mauve/aclocal.m4
--- mauve.orig/aclocal.m4	Fri May  7 09:34:19 1999
+++ mauve/aclocal.m4	Thu Feb 22 23:56:01 2001
@@ -10,6 +10,38 @@
 dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 dnl PARTICULAR PURPOSE.
 
+dnl -----------------------------------------------------------
+dnl Original by Mark Elbrecht <snowball3@bigfoot.com> 
+dnl Modified by Brian Jones <cbj@gnu.org> for Mauve
+dnl acx_check_pathname_style.m4 
+dnl http://research.cys.de/autoconf-archive/
+
+AC_DEFUN(ACX_CHECK_PATHNAME_STYLE_DOS,
+[AC_MSG_CHECKING(for Windows and DOS and OS/2 style pathnames)
+AC_CACHE_VAL(acx_cv_pathname_style_dos, 
+  [AC_REQUIRE([AC_CANONICAL_HOST])
+  acx_cv_pathname_style_dos="no"
+  case ${host_os} in
+    *djgpp | *mingw32* | *emx*) acx_cv_pathname_style_dos="yes" ;;
+  esac
+  ])
+AC_MSG_RESULT($acx_cv_pathname_style_dos)
+if test "$acx_cv_pathname_style_dos" = "yes"; then
+  AC_DEFINE(HAVE_PATHNAME_STYLE_DOS,,[defined if running on a system with dos style paths])
+  PATH_SEPARATOR=';'
+  FILE_SEPARATOR='\\'
+  AC_SUBST(PATH_SEPARATOR)
+  AC_SUBST(FILE_SEPARATOR)
+else
+  PATH_SEPARATOR=':'
+  FILE_SEPARATOR='/'
+  AC_SUBST(PATH_SEPARATOR)
+  AC_SUBST(FILE_SEPARATOR)
+fi
+])
+
+dnl -----------------------------------------------------------
+
 # Do all the work for Automake.  This macro actually does too much --
 # some checks are only needed if your package does certain things.
 # But this isn't really a big deal.
diff -uNr mauve.orig/configure.in mauve/configure.in
--- mauve.orig/configure.in	Mon Jul  5 11:31:54 1999
+++ mauve/configure.in	Thu Feb 22 23:51:10 2001
@@ -2,6 +2,9 @@
 AC_INIT(gnu/testlet/Testlet.java)
 AM_INIT_AUTOMAKE(mauve, 0.0)
 
+dnl Check path and file separator types
+ACX_CHECK_PATHNAME_STYLE_DOS
+
 AC_ARG_WITH(gcj,
 [  --with-gcj                       Use gcj to compile .class files])
 AM_CONDITIONAL(USE_GCJ, test "$with_gcj" = yes)
@@ -59,4 +62,5 @@
   mkdir gnu/testlet
 fi
 
-AC_OUTPUT(Makefile gnu/testlet/config.java)
+AC_OUTPUT(Makefile 
+gnu/testlet/config.java)
diff -uNr mauve.orig/gnu/testlet/CVS/Entries.Log mauve/gnu/testlet/CVS/Entries.Log
--- mauve.orig/gnu/testlet/CVS/Entries.Log	Thu Feb  8 23:50:13 2001
+++ mauve/gnu/testlet/CVS/Entries.Log	Wed Dec 31 19:00:00 1969
@@ -1 +0,0 @@
-A D/java////
Binary files mauve.orig/gnu/testlet/ResourceNotFoundException.class and mauve/gnu/testlet/ResourceNotFoundException.class differ
Binary files mauve.orig/gnu/testlet/SimpleTestHarness.class and mauve/gnu/testlet/SimpleTestHarness.class differ
diff -uNr mauve.orig/gnu/testlet/SimpleTestHarness.java mauve/gnu/testlet/SimpleTestHarness.java
--- mauve.orig/gnu/testlet/SimpleTestHarness.java	Thu Feb  8 06:27:46 2001
+++ mauve/gnu/testlet/SimpleTestHarness.java	Fri Feb 23 00:03:07 2001
@@ -29,7 +29,7 @@
 
 public class SimpleTestHarness 
     extends TestHarness 
-    implements gnu.testlet.config
+    implements config
 {
   private int count = 0;
   private int failures = 0;
Binary files mauve.orig/gnu/testlet/TestHarness.class and mauve/gnu/testlet/TestHarness.class differ
diff -uNr mauve.orig/gnu/testlet/TestHarness.java mauve/gnu/testlet/TestHarness.java
--- mauve.orig/gnu/testlet/TestHarness.java	Tue Mar 16 04:42:10 1999
+++ mauve/gnu/testlet/TestHarness.java	Fri Feb 23 00:02:33 2001
@@ -23,7 +23,7 @@
 import java.io.Reader;
 import java.io.InputStream;
 
-public abstract class TestHarness
+public abstract class TestHarness implements config
 {
   // These methods are used to determine whether a test has passed.
   public abstract void check (boolean result);
Binary files mauve.orig/gnu/testlet/Testlet.class and mauve/gnu/testlet/Testlet.class differ
Binary files mauve.orig/gnu/testlet/config.class and mauve/gnu/testlet/config.class differ
diff -uNr mauve.orig/gnu/testlet/config.java.in mauve/gnu/testlet/config.java.in
--- mauve.orig/gnu/testlet/config.java.in	Tue Mar 30 13:46:25 1999
+++ mauve/gnu/testlet/config.java.in	Thu Feb 22 23:50:21 2001
@@ -24,7 +24,9 @@
 {	
   public static final String srcdir = "@SRCDIR@";
   public static final String tmpdir = "@TMPDIR@";
-
+  public static final String pathSeparator = "@PATH_SEPARATOR@";
+  public static final String separator = "@FILE_SEPARATOR@";
+	
   public abstract String getSourceDirectory ();
   public abstract String getTempDirectory ();
 }
diff -uNr mauve.orig/gnu/testlet/java/io/File/DocFilter.java mauve/gnu/testlet/java/io/File/DocFilter.java
--- mauve.orig/gnu/testlet/java/io/File/DocFilter.java	Wed Dec 31 19:00:00 1969
+++ mauve/gnu/testlet/java/io/File/DocFilter.java	Fri Mar  9 00:11:09 2001
@@ -0,0 +1,14 @@
+package gnu.testlet.java.io.File;
+
+import java.io.FilenameFilter;
+import java.io.File;
+
+public class DocFilter implements FilenameFilter
+{
+  public boolean accept (File dir, String name)
+  {
+    if (name.endsWith (".doc"))
+      return true;
+    return false;
+  }
+}
diff -uNr mauve.orig/gnu/testlet/java/io/File/jdk11.java mauve/gnu/testlet/java/io/File/jdk11.java
--- mauve.orig/gnu/testlet/java/io/File/jdk11.java	Wed Dec 31 19:00:00 1969
+++ mauve/gnu/testlet/java/io/File/jdk11.java	Sat Mar 10 01:04:58 2001
@@ -0,0 +1,312 @@
+/*************************************************************************
+/* constructors.java -- File constructor test
+/*
+/* Copyright (c) 2001 Free Software Foundation, Inc.
+/*
+/* 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.1
+
+package gnu.testlet.java.io.File;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import gnu.testlet.SimpleTestHarness;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.util.Date;
+
+public class jdk11 implements Testlet
+{
+  
+  public void test (TestHarness testharness)
+  {
+    SimpleTestHarness harness = null;
+    try 
+      {
+	harness = (SimpleTestHarness)testharness;
+      } 
+    catch (ClassCastException cce)
+      {
+	harness.fail ("Harness not an instance of SimpleTestHarness");
+	return;
+      }
+
+    String srcdirstr = harness.getSourceDirectory ();
+    String tmpdirstr = harness.getTempDirectory ();
+
+    // File (String)
+    File srcdir = new File (srcdirstr);
+    File tmpdir = new File (tmpdirstr);
+    String THIS_FILE = new String ("gnu" + 
+				   File.separator + "testlet" +
+				   File.separator + "java" + 
+				   File.separator + "io" + 
+				   File.separator + "File" + 
+				   File.separator + "tmp");
+
+    // File (File, String)
+    File cons = new File (srcdir, THIS_FILE);
+    // File (String, String)
+    File cons2 = new File (srcdirstr, THIS_FILE);
+
+
+    // mkdir ()
+    harness.check (cons.mkdir (), "mkdir ()");
+
+    // canRead ()
+    harness.check (cons.canRead (), "canRead ()");
+    // equals (Object)
+    harness.check (cons.equals (cons2), "equals ()");
+    // isDirectory ()
+    harness.check (srcdir.isDirectory (), "isDirectory ()");
+    harness.check (tmpdir.isDirectory (), "isDirectory ()");
+
+    String TMP_FILENAME = "File.tst";
+    String TMP_FILENAME2 = "Good.doc";
+    String TMP_FILENAME3 = "File.doc";
+
+    // create empty file
+    File tmp = new File (cons, TMP_FILENAME);
+    try 
+      {
+	FileOutputStream fos = new FileOutputStream (tmp);
+	fos.close ();
+      } 
+    catch (FileNotFoundException fne) { }
+    catch (IOException ioe) { }
+
+    // create empty file
+    File tmp2 = new File (cons, TMP_FILENAME2);
+    try 
+      {
+	FileOutputStream fos = new FileOutputStream (tmp2);
+	fos.close ();
+      } 
+    catch (FileNotFoundException fne) { }
+    catch (IOException ioe) { }
+
+    File tmp3 = new File (cons, TMP_FILENAME3);
+
+    // canWrite ()
+    harness.check (tmp.canWrite (), "canWrite()");
+    // exists ()
+    harness.check (tmp.exists (), "exists ()");
+    // isFile ()
+    harness.check (tmp.isFile (), "isFile ()");
+    // length ()
+    harness.check (tmp.length (), 0L, "length ()");
+    byte[] b = new byte[2001];
+    try 
+      {
+	FileOutputStream fos = new FileOutputStream (tmp);
+	fos.write (b);
+	fos.close ();
+      } 
+    catch (FileNotFoundException fne) { }
+    catch (IOException ioe) { }
+    harness.check (tmp.length (), b.length, "length ()");
+
+    // toString ();
+    String tmpstr = new String (srcdirstr + File.separator 
+				+ THIS_FILE + File.separator 
+				+ TMP_FILENAME);
+    harness.debug (tmp.toString () + " =? " + tmpstr);
+    harness.check (tmp.toString ().equals (tmpstr), "toString ()");
+
+    // list ();
+    String [] tmpdirlist = cons.list ();
+    String [] expectedlist = new String[] {TMP_FILENAME, TMP_FILENAME2};
+//      for (int ll=0; ll<tmpdirlist.length; ll++)
+//        System.err.println (tmpdirlist[ll]);
+    harness.check (compareStringArray (tmpdirlist, expectedlist), "list ()");
+    
+    // list (FilenameFilter);
+    tmpdirlist = cons.list (new DocFilter ());
+    expectedlist = new String[] {TMP_FILENAME2};
+//      for (int ll=0; ll<tmpdirlist.length; ll++)
+//        System.err.println (tmpdirlist[ll]);
+    harness.check (compareStringArray (tmpdirlist, expectedlist), "list (FilenameFilter)");
+
+    // renameTo (File);
+    if (tmp3.exists ())
+      tmp3.delete ();
+    harness.check (tmp.renameTo (tmp3), "renameTo (File)");
+    harness.check (tmp3.exists (), "renameTo (File)");
+
+    // check delete of directory with something in it fails
+    if (tmp.exists ())
+      harness.check (tmp.delete (), "delete ()");
+    if (tmp2.exists ())
+      harness.check (tmp2.delete (), "delete ()");
+    if (tmp3.exists ())
+      harness.check (tmp3.delete (), "delete ()");
+    harness.check (!tmp.exists (), "delete ()");
+    harness.check (!tmp2.exists (), "delete ()");
+    harness.check (!tmp3.exists (), "delete ()");
+    
+    // mkdir ();
+    harness.check (tmp.mkdir (), "mkdir ()");
+    harness.check (tmp.exists () && tmp.isDirectory (), "mkdir ()");
+    
+    // mkdirs ();
+    File mkdirstest = new File (tmpdirstr, new String ("one" + File.separator
+						       + "two" + File.separator
+						       + "three"));
+    harness.check (mkdirstest.mkdirs (), "mkdirs ()");
+    harness.check (mkdirstest.exists () && mkdirstest.isDirectory (), "mkdirs ()");
+    File mkdirstest2 = new File (tmpdirstr, new String ("one" + File.separator 
+							+ "two"));
+    harness.check (mkdirstest2.exists () && mkdirstest2.isDirectory (), "mkdirs ()");
+    File mkdirstest1 = new File (tmpdirstr, new String ("one"));
+    harness.check (mkdirstest1.exists () && mkdirstest1.isDirectory (), "mkdirs ()");
+
+    harness.check (mkdirstest.delete (), "delete () of a directory");
+    harness.check (!mkdirstest.exists (), "delete () of a directory");
+
+    // negative test case
+    harness.check (!mkdirstest1.delete (), "delete () of a directory");
+
+    harness.check (mkdirstest2.delete (), "delete () of a directory");
+    harness.check (!mkdirstest2.exists (), "delete () of a directory");
+
+    harness.check (mkdirstest1.delete (), "delete () of a directory");
+    harness.check (!mkdirstest1.exists (), "delete () of a directory");
+    
+    // check delete of an empty directory
+    harness.check (tmp.delete (), "delete () of a directory");
+    harness.check (!tmp.exists (), "delete () of a directory");
+
+    harness.check (cons.delete (), "delete () of a directory");
+    harness.check (!cons.exists (), "delete () of a directory");
+
+    harness.check (File.pathSeparator.equals (harness.pathSeparator), "pathSeparator");
+    harness.check (new Character (File.pathSeparatorChar).toString ().equals (harness.pathSeparator), "pathSeparatorChar");
+
+    harness.check (File.separator.equals (harness.separator), "separator");
+    harness.check (new Character (File.separatorChar).toString ().equals (harness.separator), "separatorChar");
+    
+    // getAbsolutePath ();
+    harness.debug ("tmp.getAbsolutePath () = " + tmp.getAbsolutePath ());
+    harness.check (tmp.getAbsolutePath ().equals (srcdirstr
+						  + File.separator
+						  + THIS_FILE
+						  + File.separator
+						  + TMP_FILENAME3), "getAbsolutePath ()");
+
+    // getCanonicalPath ();
+
+    try 
+      {
+	harness.debug ("tmp.getCanonicalPath () = " + tmp.getCanonicalPath ());
+	harness.debug ("equals? " + srcdirstr + File.separator 
+		       + THIS_FILE + File.separator
+		       + TMP_FILENAME3);
+	harness.check (tmp.getCanonicalPath ().equals (srcdirstr
+						       + File.separator 
+						       + THIS_FILE
+						       + File.separator
+						       + TMP_FILENAME3), "getCanonicalPath ()");
+      } 
+    catch (IOException ioe)
+      {
+	harness.check (false, "getCanonicalPath ()");
+      }
+
+    // getName ();
+    harness.debug ("tmp.getName () = " + tmp.getName ());
+    harness.check (tmp.getName ().equals (TMP_FILENAME3), "getName ()");
+
+    // getParent ();
+    harness.check (tmp.getParent ().equals (srcdirstr 
+					    + File.separator 
+					    + THIS_FILE), "getParent ()");
+
+    // getPath ();
+    harness.debug ("tmp.getPath () = " + tmp.getPath ());
+    harness.check (tmp.getPath ().equals (srcdirstr 
+					  + File.separator
+					  + THIS_FILE
+					  + File.separator
+					  + TMP_FILENAME3), "getPath ()");
+
+    // hashCode ();
+    
+    // isAbsolute ();
+    harness.check (tmp.isAbsolute (), "isAbsolute ()");
+
+    // lastModified ();
+    File lastmod = new File (tmpdir, "lastmod");
+    if (lastmod.exists ())
+      lastmod.delete ();
+    Date now = new Date ();
+    long time = now.getTime ();
+    try 
+      {
+	Thread.sleep (1000);
+      }
+    catch (InterruptedException ie) { }
+    try 
+      {
+	FileOutputStream fos = new FileOutputStream (lastmod);
+	fos.close ();
+      } 
+    catch (FileNotFoundException fne) { }
+    catch (IOException ioe) { }
+    harness.debug (lastmod.lastModified () + " >= " + time);
+    if (lastmod.lastModified () >= time)
+      harness.check (true, "lastModified ()");
+    else
+      harness.check (false, "lastModified ()");
+    if (lastmod.exists ())
+      lastmod.delete ();
+  }
+
+  /**
+   * Compare two String arrays, and if of the same length compare
+   * contents for equality, order does not matter.
+   */
+  private boolean compareStringArray (String[] x, String[] y)
+  {
+    if (x.length != y.length)
+      return false;
+
+    boolean[] test = new boolean[y.length];
+    for (int i = 0; i < test.length; i++)
+      test[i] = true;
+
+    for (int i = 0; i < x.length; i++)
+      {
+	boolean nomatch = true;
+	for (int j = 0; j < y.length; j++)
+	  {
+	    if (test[j])
+	      if (x[i].equals (y[j]))
+		{
+		  test[j] = false;
+		  nomatch = false;
+		  break;
+		}
+	  }
+	if (nomatch)
+	  return false;
+      }
+    return true;
+  }
+}
+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]