diff options
author | Ian Rogers <irogers@google.com> | 2012-02-17 14:48:16 -0800 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2012-02-17 14:56:26 -0800 |
commit | 1441f6f3ea53ce07d119b32eadaf322f71e07676 (patch) | |
tree | 90f3c146943282d01dad3acbb1b49fab8ede1895 /test | |
parent | 55b16ceff1068cce61c86f2c9ca011a97c869bd4 (diff) | |
download | art-1441f6f3ea53ce07d119b32eadaf322f71e07676.zip art-1441f6f3ea53ce07d119b32eadaf322f71e07676.tar.gz art-1441f6f3ea53ce07d119b32eadaf322f71e07676.tar.bz2 |
Test Class.forName and serialization on inner classes
Change-Id: Ib8e5e5df02818ca05d46d866f60a59c07a843d51
Diffstat (limited to 'test')
-rw-r--r-- | test/042-new-instance/expected.txt | 2 | ||||
-rw-r--r-- | test/042-new-instance/src/Main.java | 28 | ||||
-rw-r--r-- | test/093-serialization/expected.txt | 1 | ||||
-rw-r--r-- | test/093-serialization/src/Main.java | 18 |
4 files changed, 48 insertions, 1 deletions
diff --git a/test/042-new-instance/expected.txt b/test/042-new-instance/expected.txt index bb1b80c..7d843d1 100644 --- a/test/042-new-instance/expected.txt +++ b/test/042-new-instance/expected.txt @@ -4,6 +4,8 @@ LocalClass3 succeeded Got expected InstantationError Cons LocalClass failed as expected Cons LocalClass2 succeeded +Cons InnerClass succeeded +Cons StaticInnerClass succeeded Cons got expected PackageAccess complaint Cons got expected InstantationException Cons got expected PackageAccess2 complaint diff --git a/test/042-new-instance/src/Main.java b/test/042-new-instance/src/Main.java index e43c5a5..b0a5fd4 100644 --- a/test/042-new-instance/src/Main.java +++ b/test/042-new-instance/src/Main.java @@ -92,6 +92,28 @@ public class Main { ex.printStackTrace(); } + // should succeed + try { + Class c = Class.forName("Main$InnerClass"); + Constructor cons = c.getDeclaredConstructor(new Class<?>[]{Main.class}); + Object obj = cons.newInstance(new Main()); + System.out.println("Cons InnerClass succeeded"); + } catch (Exception ex) { + System.err.println("Cons InnerClass failed"); + ex.printStackTrace(); + } + + // should succeed + try { + Class c = Class.forName("Main$StaticInnerClass"); + Constructor cons = c.getDeclaredConstructor((Class[]) null); + Object obj = cons.newInstance(); + System.out.println("Cons StaticInnerClass succeeded"); + } catch (Exception ex) { + System.err.println("Cons StaticInnerClass failed"); + ex.printStackTrace(); + } + // should fail try { Class c = Class.forName("otherpackage.PackageAccess"); @@ -135,6 +157,12 @@ public class Main { } } + + class InnerClass { + } + + static class StaticInnerClass { + } } class LocalClass { diff --git a/test/093-serialization/expected.txt b/test/093-serialization/expected.txt index 60c64f8..c9bc1c3 100644 --- a/test/093-serialization/expected.txt +++ b/test/093-serialization/expected.txt @@ -1 +1,2 @@ one=true two=2 three=three four=4.0 five=5.0 six=6 seven=7 eight=8 nine=9 thing=X +x=cafef00d diff --git a/test/093-serialization/src/Main.java b/test/093-serialization/src/Main.java index ca3dc9f..3cb98be 100644 --- a/test/093-serialization/src/Main.java +++ b/test/093-serialization/src/Main.java @@ -47,6 +47,8 @@ public class Main { Sub sub = new Sub('X'); objStream.writeObject(sub); + Inner inner = new Inner(0xCAFEF00D); + objStream.writeObject(inner); byte[] bytes = byteStream.toByteArray(); objStream.close(); @@ -59,8 +61,10 @@ public class Main { ObjectInputStream objStream = new ObjectInputStream(byteStream); Sub sub; + Inner inner; try { sub = (Sub) objStream.readObject(); + inner = (Inner) objStream.readObject(); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } @@ -69,6 +73,19 @@ public class Main { byteStream.close(); sub.check(); + inner.check(); + } + + static class Inner implements Serializable { + private static final long serialVersionUID = 319009; + private final int x; + public Inner (int x) { + this.x = x; + } + + public void check() { + System.out.println("x=" + Integer.toHexString(x)); + } } } @@ -113,4 +130,3 @@ class Sub extends Base { + " thing=" + thing); } } - |