From 89cdd9d0d275554ea0369824e11186a3ec1bf887 Mon Sep 17 00:00:00 2001 From: Ben Limmer Date: Wed, 9 Nov 2011 13:18:04 -0700 Subject: [PATCH 1/6] Fixed bug where calling Process.destroy() on a PID that no longer exist kills all processes in Pgroup. --- classpath/java/lang/Runtime.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classpath/java/lang/Runtime.java b/classpath/java/lang/Runtime.java index bf80507deb..88c8ba71e3 100644 --- a/classpath/java/lang/Runtime.java +++ b/classpath/java/lang/Runtime.java @@ -149,7 +149,9 @@ public class Runtime { } public void destroy() { - kill(pid); + if (pid != 0) { + kill(pid); + } } public InputStream getInputStream() { From b3850ac76db7897a86e5cbac29e72092c8cc75e5 Mon Sep 17 00:00:00 2001 From: Ben Limmer Date: Wed, 28 Dec 2011 15:52:53 -0700 Subject: [PATCH 2/6] Initial attempt at resolving SWT3.7 missing operatons in Avian. Everything seems to be working except floatToIntBits, hence the test case failing. --- classpath/java/io/File.java | 4 ++++ classpath/java/lang/Float.java | 17 +++++++++++++++-- classpath/java/net/URL.java | 18 ++++++++++++++++++ test/Floats.java | 27 +++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/classpath/java/io/File.java b/classpath/java/io/File.java index 51e006e53f..9342627bd5 100644 --- a/classpath/java/io/File.java +++ b/classpath/java/io/File.java @@ -61,6 +61,10 @@ public class File implements Serializable { return isFile(path); } + public boolean isAbsolute() { + return path.equals(toAbsolutePath(path)); + } + private static native boolean canRead(String path); public boolean canRead() { diff --git a/classpath/java/lang/Float.java b/classpath/java/lang/Float.java index 1e2c62972b..d466cca2a3 100644 --- a/classpath/java/lang/Float.java +++ b/classpath/java/lang/Float.java @@ -12,8 +12,10 @@ package java.lang; public final class Float extends Number { public static final Class TYPE = Class.forCanonicalName("F"); - - private final float value; + private static final int EXP_BIT_MASK = 0x7F800000; + private static final int SIGNIF_BIT_MASK = 0x007FFFFF; + + private final float value; public Float(String value) { this.value = parseFloat(value); @@ -88,6 +90,17 @@ public final class Float extends Number { throw new NumberFormatException(s); } } + + public static int floatToIntBits(float value) { + int result = floatToRawIntBits(value); + + // Check for NaN based on values of bit fields, maximum + // exponent and nonzero significand. + if (((result & EXP_BIT_MASK) == EXP_BIT_MASK) && (result & SIGNIF_BIT_MASK) != 0) { + result = 0x7fc00000; + } + return result; + } public static native int floatToRawIntBits(float value); diff --git a/classpath/java/net/URL.java b/classpath/java/net/URL.java index 874eec964b..eb46c61860 100644 --- a/classpath/java/net/URL.java +++ b/classpath/java/net/URL.java @@ -19,6 +19,8 @@ public final class URL { private String host; private int port; private String file; + private String path; + private String query; private String ref; public URL(String s) throws MalformedURLException { @@ -55,6 +57,14 @@ public final class URL { public String getRef() { return ref; } + + public String getPath() { + return path; + } + + public String getQuery() { + return query; + } public URLConnection openConnection() throws IOException { return handler.openConnection(this); @@ -90,5 +100,13 @@ public final class URL { this.port = port; this.file = file; this.ref = ref; + + int q = file.lastIndexOf('?'); + if (q != -1) { + this.query = file.substring(q + 1); + this.path = file.substring(0, q); + } else { + this.path = file; + } } } diff --git a/test/Floats.java b/test/Floats.java index 38ae3121b1..e27e703d40 100644 --- a/test/Floats.java +++ b/test/Floats.java @@ -211,5 +211,32 @@ public class Floats { double d = (double) z; expect(d == 12345.0); } + + { + int NaN = 0x7F800001; + int result = Float.floatToIntBits(NaN); + int expected = 0x7fc00000; + System.out.println("NaN integer is: " + result + " and we were expecting it to be: " + expected); + expect(result == expected); + } + + { + int number = 0x00800001; + int result = Float.floatToIntBits(number); + System.out.println("Number1 is: " + result); + + expect(result == number); + + + } + + { + int number = 0x80800003; + int result = Float.floatToIntBits(number); + System.out.println("Number2 is: " + result); + expect(result == number); + + + } } } From f5a168f5841db6c0946e52a1a6c955187a3ad2d6 Mon Sep 17 00:00:00 2001 From: Seth Goings Date: Wed, 28 Dec 2011 23:58:33 -0700 Subject: [PATCH 3/6] Fixed tests for floatToIntBits. Probably want to add more comprehensive tests tomorrow (or today... as of 2 minutes) --- test/Floats.java | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/test/Floats.java b/test/Floats.java index e27e703d40..2494088b01 100644 --- a/test/Floats.java +++ b/test/Floats.java @@ -212,31 +212,26 @@ public class Floats { expect(d == 12345.0); } - { - int NaN = 0x7F800001; + { + int orig = 0x7f800001; + float NaN = Float.intBitsToFloat(orig); int result = Float.floatToIntBits(NaN); int expected = 0x7fc00000; - System.out.println("NaN integer is: " + result + " and we were expecting it to be: " + expected); expect(result == expected); } { - int number = 0x00800001; + int orig = 0x00800001; + float number = Float.intBitsToFloat(orig); int result = Float.floatToIntBits(number); - System.out.println("Number1 is: " + result); - - expect(result == number); - - + expect(result == orig); } { - int number = 0x80800003; + int orig = 0x80800003; + float number = Float.intBitsToFloat(orig); int result = Float.floatToIntBits(number); - System.out.println("Number2 is: " + result); - expect(result == number); - - + expect(result == orig); } } } From a0c12ad2595f9b52c3b2b82b81c2e17ed9bd9268 Mon Sep 17 00:00:00 2001 From: Seth Goings Date: Thu, 29 Dec 2011 09:51:44 -0700 Subject: [PATCH 4/6] Added another floatToIntBits test --- test/Floats.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/Floats.java b/test/Floats.java index 2494088b01..775b391ffd 100644 --- a/test/Floats.java +++ b/test/Floats.java @@ -211,7 +211,8 @@ public class Floats { double d = (double) z; expect(d == 12345.0); } - + + // Test floatToIntBits { int orig = 0x7f800001; float NaN = Float.intBitsToFloat(orig); @@ -220,6 +221,14 @@ public class Floats { expect(result == expected); } + { + int orig = 0x7f801001; + float NaN = Float.intBitsToFloat(orig); + int result = Float.floatToIntBits(NaN); + int expected = 0x7fc00000; + expect(result == expected); + } + { int orig = 0x00800001; float number = Float.intBitsToFloat(orig); From d76191d2bb9185ce8ed82e19b0caf77875d5e49c Mon Sep 17 00:00:00 2001 From: Ben Limmer Date: Thu, 29 Dec 2011 10:17:01 -0700 Subject: [PATCH 5/6] Adding unit tests for File.isAbsolute() method. --- test/Files.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/Files.java diff --git a/test/Files.java b/test/Files.java new file mode 100644 index 0000000000..6bf01dadaa --- /dev/null +++ b/test/Files.java @@ -0,0 +1,29 @@ +import java.io.File; + +public class Files { + private static void expect(boolean v) { + if (! v) throw new RuntimeException(); + } + + private static void isAbsoluteTest(boolean absolutePath) { + File file = new File("test.txt"); + if (absolutePath) { + file = file.getAbsoluteFile(); + } + + boolean isAbsolute = file.isAbsolute(); + + if (absolutePath) { + expect(isAbsolute); + } else { + expect(!isAbsolute); + } + + } + + public static void main(String[] args) { + isAbsoluteTest(true); + isAbsoluteTest(false); + } + +} From 51ae790e5492b9d18c10a61f0ca4e7eaee8ac3a1 Mon Sep 17 00:00:00 2001 From: Seth Goings Date: Thu, 29 Dec 2011 10:36:33 -0700 Subject: [PATCH 6/6] Added UrlTest.java to tests dir --- test/UrlTest.java | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/UrlTest.java diff --git a/test/UrlTest.java b/test/UrlTest.java new file mode 100644 index 0000000000..35281b367a --- /dev/null +++ b/test/UrlTest.java @@ -0,0 +1,42 @@ +import java.net.MalformedURLException; +import java.net.URL; + +public class UrlTest { + private static String query="var1=val1&var2=val2"; + private static String path="testpath"; + private static String domain="file://www.readytalk.com"; + private static String file=path + "?" + query; + private static URL url; + + private static void expect(boolean v) { + if (! v) throw new RuntimeException(); + } + + private static void setupURL() throws MalformedURLException { + StringBuilder builder = new StringBuilder(); + builder.append(domain); + builder.append("/"); + builder.append(file); + url = new URL(builder.toString()); + } + + private static void testGetPath() { + expect(url.getPath().equals(path)); + } + + private static void testGetFile() { + expect(url.getFile().equals(file)); + } + + private static void testGetQuery() { + expect(url.getQuery().equals(query)); + } + + public static void main(String[] args) throws MalformedURLException { + setupURL(); + testGetPath(); + testGetFile(); + testGetQuery(); + } + +}