From 5d1ac920fdaef5d4ec8f66bb734488cd9660b024 Mon Sep 17 00:00:00 2001 From: jeffhao Date: Thu, 29 Sep 2011 17:41:15 -0700 Subject: Adding old unit tests to test suite. These tests are copied straight over. They'll still run, but they're using the old system. Change-Id: If494519e52ddf858a9febfc55bdae830468cb3c8 --- test/069-field-type/expected.txt | 4 ++++ test/069-field-type/info.txt | 4 ++++ test/069-field-type/src/Blah.java | 9 +++++++++ test/069-field-type/src/Holder.java | 7 +++++++ test/069-field-type/src/Main.java | 34 ++++++++++++++++++++++++++++++++++ test/069-field-type/src2/Blah.java | 10 ++++++++++ 6 files changed, 68 insertions(+) create mode 100644 test/069-field-type/expected.txt create mode 100644 test/069-field-type/info.txt create mode 100644 test/069-field-type/src/Blah.java create mode 100644 test/069-field-type/src/Holder.java create mode 100644 test/069-field-type/src/Main.java create mode 100644 test/069-field-type/src2/Blah.java (limited to 'test/069-field-type') diff --git a/test/069-field-type/expected.txt b/test/069-field-type/expected.txt new file mode 100644 index 0000000000..88281780f3 --- /dev/null +++ b/test/069-field-type/expected.txt @@ -0,0 +1,4 @@ +Assignment was allowed +Got expected IncompatibleClassChangeError +In compareTo +Done diff --git a/test/069-field-type/info.txt b/test/069-field-type/info.txt new file mode 100644 index 0000000000..6e3a22fd48 --- /dev/null +++ b/test/069-field-type/info.txt @@ -0,0 +1,4 @@ +This tests to see if the VM allows you to store a reference to an +inappropriate object type in an instance field. By compiling two +versions of the field-holder class we can bypass the compiler's type +safety. diff --git a/test/069-field-type/src/Blah.java b/test/069-field-type/src/Blah.java new file mode 100644 index 0000000000..fd98336461 --- /dev/null +++ b/test/069-field-type/src/Blah.java @@ -0,0 +1,9 @@ + +/** + * Trivial class; must implement an interesting interface. + */ +public class Blah implements Runnable { + public void run() { + System.out.println("run"); + } +} diff --git a/test/069-field-type/src/Holder.java b/test/069-field-type/src/Holder.java new file mode 100644 index 0000000000..e3c9f8936b --- /dev/null +++ b/test/069-field-type/src/Holder.java @@ -0,0 +1,7 @@ + +/** + * Simple class with one field. + */ +public class Holder { + public Runnable mValue; +} diff --git a/test/069-field-type/src/Main.java b/test/069-field-type/src/Main.java new file mode 100644 index 0000000000..f9885e64b2 --- /dev/null +++ b/test/069-field-type/src/Main.java @@ -0,0 +1,34 @@ + +/** + * Create some objects and store them into an instance field. + */ +public class Main { + /** + * Entry point. + */ + public static void main(String[] args) { + Holder holder = new Holder(); + + Blah blah = new Blah(); + + /* strictly speaking, this should fail */ + holder.mValue = blah; + + System.out.println("Assignment was allowed"); + + /* try to use the reference; should fail */ + try { + holder.mValue.run(); + System.err.println("ERROR: did not get expected ICCE"); + } catch (IncompatibleClassChangeError icce) { + System.out.println("Got expected IncompatibleClassChangeError"); + } + + /* for fun, verify that it's the "alternate" type */ + //Comparable cmpx = holder.mValue; /* compiler rejects */ + Comparable cmp = (Comparable) holder.mValue; + cmp.compareTo(cmp); + + System.out.println("Done"); + } +} diff --git a/test/069-field-type/src2/Blah.java b/test/069-field-type/src2/Blah.java new file mode 100644 index 0000000000..1bffff6c40 --- /dev/null +++ b/test/069-field-type/src2/Blah.java @@ -0,0 +1,10 @@ + +/** + * Trivial class; must implement an interesting interface. + */ +public class Blah implements Comparable { + public int compareTo(Object another) { + System.out.println("In compareTo"); + return 0; + } +} -- cgit v1.2.3