summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-03-02 17:34:48 +0000
committermichelou <michelou@epfl.ch>2007-03-02 17:34:48 +0000
commit83d75b3bdbcd591fce7aa9953ad509b07552b5a4 (patch)
treefbe3c9570b616473d3fc0d801caee6d2748b97a9 /test/files
parent2357b792b4894325f2d878b4e49ae6d894a41f68 (diff)
downloadscala-83d75b3bdbcd591fce7aa9953ad509b07552b5a4.tar.gz
scala-83d75b3bdbcd591fce7aa9953ad509b07552b5a4.tar.bz2
scala-83d75b3bdbcd591fce7aa9953ad509b07552b5a4.zip
added @serializable annotation to ListBuffer
Diffstat (limited to 'test/files')
-rw-r--r--test/files/jvm/serialization.check8
-rw-r--r--test/files/jvm/serialization.scala288
2 files changed, 164 insertions, 132 deletions
diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check
index fa4022afc3..d5fd15919f 100644
--- a/test/files/jvm/serialization.check
+++ b/test/files/jvm/serialization.check
@@ -46,6 +46,10 @@ x = Set(0, 2)
y = Set(0, 2)
x equals y: true - y equals x: true
+x = ArrayBuffer(one,two)
+y = ArrayBuffer(one,two)
+x equals y: true - y equals x: true
+
x = Map(title -> 3, buffers -> 20, layers -> 2)
y = Map(title -> 3, buffers -> 20, layers -> 2)
x equals y: true - y equals x: true
@@ -70,6 +74,10 @@ x = Stack(20,2,3)
y = Stack(20,2,3)
x equals y: true - y equals x: true
+x = ListBuffer(white,black)
+y = ListBuffer(white,black)
+x equals y: true - y equals x: true
+
x = <html><title>title</title><body></body></html>
y = <html><title>title</title><body></body></html>
x equals y: true - y equals x: true
diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala
index 4780da8c02..9a5280557a 100644
--- a/test/files/jvm/serialization.scala
+++ b/test/files/jvm/serialization.scala
@@ -3,29 +3,32 @@
//############################################################################
// $Id$
-import java.lang.System;
+import java.lang.System
object EqualityTest {
def check[A, B](x: A, y: B): Unit = {
- System.out.println("x = " + x);
- System.out.println("y = " + y);
+ System.out.println("x = " + x)
+ System.out.println("y = " + y)
System.out.println(
"x equals y: " + (x equals y) + " - y equals x: " + (y equals x));
- System.out.println();
+ System.out.println()
}
}
object Serialize {
- def write[A](o: A): Array[Byte] = { // throws Exception
- val ba = new java.io.ByteArrayOutputStream(512);
- val out = new java.io.ObjectOutputStream(ba);
- out.writeObject(o);
- out.close();
+ @throws(classOf[java.io.IOException])
+ def write[A](o: A): Array[Byte] = {
+ val ba = new java.io.ByteArrayOutputStream(512)
+ val out = new java.io.ObjectOutputStream(ba)
+ out.writeObject(o)
+ out.close()
ba.toByteArray()
}
- def read[A](buffer: Array[Byte]): A = { // throws Exception
+ @throws(classOf[java.io.IOException])
+ @throws(classOf[ClassNotFoundException])
+ def read[A](buffer: Array[Byte]): A = {
val in =
- new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer));
+ new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer))
in.readObject().asInstanceOf[A]
}
}
@@ -46,89 +49,92 @@ object Test1_scala {
val x4 = { x: Int => 2 * x }
try {
- val y1: List[Nothing] = Serialize.read(Serialize.write(x1));
- val y2: Option[Nothing] = Serialize.read(Serialize.write(x2));
- val y3: Array[Int] = Serialize.read(Serialize.write(x3));
- val y4: Function[Int, Int] = Serialize.read(Serialize.write(x4));
-
- System.out.println("x1 = " + x1);
- System.out.println("y1 = " + y1);
- System.out.println("x1 eq y1: " + (x1 eq y1) + " - y1 eq x1: " + (y1 eq x1));
- System.out.println();
- System.out.println("x2 = " + x2);
- System.out.println("y2 = " + y2);
- System.out.println("x2 eq y2: " + (x2 eq y2) + " - y2 eq x2: " + (y2 eq x2));
- System.out.println();
- System.out.println("x3 = " + arrayToString(x3));
- System.out.println("y3 = " + arrayToString(y3));
- System.out.println("arrayEquals(x3, y3): " + arrayEquals(x3, y3));
- System.out.println();
- System.out.println("x4 = <na>");
- System.out.println("y4 = <na>");
- System.out.println("x4(2): " + x4(2) + " - y4(2): " + y4(2));
- System.out.println();
+ val y1: List[Nothing] = Serialize.read(Serialize.write(x1))
+ val y2: Option[Nothing] = Serialize.read(Serialize.write(x2))
+ val y3: Array[Int] = Serialize.read(Serialize.write(x3))
+ val y4: Function[Int, Int] = Serialize.read(Serialize.write(x4))
+
+ System.out.println("x1 = " + x1)
+ System.out.println("y1 = " + y1)
+ System.out.println("x1 eq y1: " + (x1 eq y1) + " - y1 eq x1: " + (y1 eq x1))
+ System.out.println()
+ System.out.println("x2 = " + x2)
+ System.out.println("y2 = " + y2)
+ System.out.println("x2 eq y2: " + (x2 eq y2) + " - y2 eq x2: " + (y2 eq x2))
+ System.out.println()
+ System.out.println("x3 = " + arrayToString(x3))
+ System.out.println("y3 = " + arrayToString(y3))
+ System.out.println("arrayEquals(x3, y3): " + arrayEquals(x3, y3))
+ System.out.println()
+ System.out.println("x4 = <na>")
+ System.out.println("y4 = <na>")
+ System.out.println("x4(2): " + x4(2) + " - y4(2): " + y4(2))
+ System.out.println()
}
catch {
case e: Exception =>
- e.printStackTrace();
- System.out.println("Error in Test1_scala: " + e);
+ e.printStackTrace()
+ System.out.println("Error in Test1_scala: " + e)
}
}
//############################################################################
// Test classes in package "scala.collection.immutable"
+
@serializable
object Test2_immutable {
- import scala.collection.immutable.{BitSet,ListMap,ListSet,Queue,Stack,
- TreeSet,TreeMap};
+ import scala.collection.immutable.{
+ BitSet, ListMap, ListSet, Queue, Stack, TreeSet, TreeMap}
val x1 = List(
Pair("buffers", 20),
Pair("layers", 2),
Pair("title", 3)
- );
+ )
val x2 = new ListMap[String, Int]
.incl(Pair("buffers", 20))
.incl(Pair("layers", 2))
.incl(Pair("title", 3));
- val x3 = { val bs = new collection.mutable.BitSet(); bs += 2; bs += 3;
- bs.toImmutable;
- };
+ val x3 = {
+ val bs = new collection.mutable.BitSet()
+ bs += 2; bs += 3;
+ bs.toImmutable;
+ }
- val x4 = new ListSet[Int]().incl(3).incl(5);
+ val x4 = new ListSet[Int]().incl(3).incl(5)
- val x5 = new Queue("a", "b", "c");
+ val x5 = new Queue("a", "b", "c")
- val x6 = new Stack().push("a", "b", "c");
+ val x6 = new Stack().push("a", "b", "c")
- val x7 = new TreeMap[Int, String] + 42 -> "FortyTwo";
+ val x7 = new TreeMap[Int, String] + 42 -> "FortyTwo"
- val x8 = new TreeSet[Int]().incl(2).incl(0);
+ val x8 = new TreeSet[Int]().incl(2).incl(0)
try {
- val y1: List[Pair[String, Int]] = Serialize.read(Serialize.write(x1));
- val y2: ListMap[String, Int] = Serialize.read(Serialize.write(x2));
- val y3: BitSet = Serialize.read(Serialize.write(x3));
- val y4: ListSet[Int] = Serialize.read(Serialize.write(x4));
- val y5: Queue[String] = Serialize.read(Serialize.write(x5));
- val y6: Stack[String] = Serialize.read(Serialize.write(x6));
- val y7: TreeMap[Int, String] = Serialize.read(Serialize.write(x7));
- val y8: TreeSet[Int] = Serialize.read(Serialize.write(x8));
-
- EqualityTest.check(x1, y1);
- EqualityTest.check(x2, y2);
- EqualityTest.check(x3, y3);
- EqualityTest.check(x4, y4);
- EqualityTest.check(x5, y5);
- EqualityTest.check(x6, y6);
- EqualityTest.check(x7, y7);
- EqualityTest.check(x8, y8);
+ val y1: List[Pair[String, Int]] = Serialize.read(Serialize.write(x1))
+ val y2: ListMap[String, Int] = Serialize.read(Serialize.write(x2))
+ val y3: BitSet = Serialize.read(Serialize.write(x3))
+ val y4: ListSet[Int] = Serialize.read(Serialize.write(x4))
+ val y5: Queue[String] = Serialize.read(Serialize.write(x5))
+ val y6: Stack[String] = Serialize.read(Serialize.write(x6))
+ val y7: TreeMap[Int, String] = Serialize.read(Serialize.write(x7))
+ val y8: TreeSet[Int] = Serialize.read(Serialize.write(x8))
+
+ EqualityTest.check(x1, y1)
+ EqualityTest.check(x2, y2)
+ EqualityTest.check(x3, y3)
+ EqualityTest.check(x4, y4)
+ EqualityTest.check(x5, y5)
+ EqualityTest.check(x6, y6)
+ EqualityTest.check(x7, y7)
+ EqualityTest.check(x8, y8)
}
catch {
case e: Exception =>
- System.out.println("Error in Test2_immutable: " + e);
+ System.out.println("Error in Test2_immutable: " + e)
throw e
}
}
@@ -137,47 +143,65 @@ object Test2_immutable {
// Test classes in package "scala.collection.mutable"
object Test3_mutable {
- import scala.collection.mutable.{BitSet,HashMap,HashSet,LinkedList,
- Queue,Stack};
+ import scala.collection.mutable.{
+ ArrayBuffer, BitSet, HashMap, HashSet, History, LinkedList, ListBuffer,
+ Publisher, Queue, RevertableHistory, Stack}
+
+ val x0 = new ArrayBuffer[String]
+ x0 ++= List("one", "two")
+
+ val x2 = new BitSet()
+ x2 += 0
+ x2 += 8
+ x2 += 9
- val x1 = new HashMap[String, Int];
- x1 ++= Test2_immutable.x1;
+ val x1 = new HashMap[String, Int]
+ x1 ++= Test2_immutable.x1
+
+ val x3 = new HashSet[String]
+ x3 ++= Test2_immutable.x1.map(p => p._1)
+
+ @serializable
+ class Feed extends Publisher[String, Feed]
- val x2 = new BitSet();
- x2 += 0;
- x2 += 8;
- x2 += 9;
+ val x8 = new History[String, Feed]
- val x3 = new HashSet[String];
- x3 ++= Test2_immutable.x1.map(p => p._1);
+ val x4 = new LinkedList[Int](2, null)
+ x4.append(new LinkedList(3, null))
- val x4 = new LinkedList[Int](2, null);
- x4.append(new LinkedList(3, null));
+ val x7 = new ListBuffer[String]
+ x7 ++= List("white", "black")
- val x5 = new Queue[Int];
- x5 ++= Test2_immutable.x1.map(p => p._2);
+ val x5 = new Queue[Int]
+ x5 ++= Test2_immutable.x1.map(p => p._2)
- val x6 = new Stack[Int];
- x6 ++= x5;
+ val x6 = new Stack[Int]
+ x6 ++= x5
try {
- val y1: HashMap[String, Int] = Serialize.read(Serialize.write(x1));
- val y2: BitSet = Serialize.read(Serialize.write(x2));
- val y3: HashSet[String] = Serialize.read(Serialize.write(x3));
- val y4: LinkedList[Int] = Serialize.read(Serialize.write(x4));
- val y5: Queue[Int] = Serialize.read(Serialize.write(x5));
- val y6: Stack[Int] = Serialize.read(Serialize.write(x6));
-
- EqualityTest.check(x1, y1);
- EqualityTest.check(x2, y2);
- EqualityTest.check(x3, y3);
- EqualityTest.check(x4, y4);
- EqualityTest.check(x5, y5);
- EqualityTest.check(x6, y6);
+ val y0: ArrayBuffer[String] = Serialize.read(Serialize.write(x0))
+ val y1: HashMap[String, Int] = Serialize.read(Serialize.write(x1))
+ val y2: BitSet = Serialize.read(Serialize.write(x2))
+ val y3: HashSet[String] = Serialize.read(Serialize.write(x3))
+ val y4: LinkedList[Int] = Serialize.read(Serialize.write(x4))
+ val y5: Queue[Int] = Serialize.read(Serialize.write(x5))
+ val y6: Stack[Int] = Serialize.read(Serialize.write(x6))
+ val y7: ListBuffer[String] = Serialize.read(Serialize.write(x7))
+ val y8: History[String, Feed] = Serialize.read(Serialize.write(x8))
+
+ EqualityTest.check(x0, y0)
+ EqualityTest.check(x1, y1)
+ EqualityTest.check(x2, y2)
+ EqualityTest.check(x3, y3)
+ EqualityTest.check(x4, y4)
+ EqualityTest.check(x5, y5)
+ EqualityTest.check(x6, y6)
+ EqualityTest.check(x7, y7)
+ //EqualityTest.check(x8, y8) //todo
}
catch {
case e: Exception =>
- System.out.println("Error in Test3_mutable: " + e);
+ System.out.println("Error in Test3_mutable: " + e)
}
}
@@ -185,14 +209,14 @@ object Test3_mutable {
// Test classes in package "scala.xml"
object Test4_xml {
- import scala.xml.{Elem};
+ import scala.xml.Elem
val x1 = <html><title>title</title><body></body></html>;
- case class Person(name: String, age: Int);
+ case class Person(name: String, age: Int)
class AddressBook(a: Person*) {
- private val people: List[Person] = a.toList;
+ private val people: List[Person] = a.toList
def toXHTML =
<table cellpadding="2" cellspacing="0">
<tr>
@@ -210,7 +234,7 @@ object Test4_xml {
val people = new AddressBook(
Person("Tom", 20),
Person("Bob", 22),
- Person("James", 19));
+ Person("James", 19))
val x2 =
<html>
@@ -220,15 +244,15 @@ object Test4_xml {
</html>;
try {
- val y1: scala.xml.Elem = Serialize.read(Serialize.write(x1));
- val y2: scala.xml.Elem = Serialize.read(Serialize.write(x2));
+ val y1: scala.xml.Elem = Serialize.read(Serialize.write(x1))
+ val y2: scala.xml.Elem = Serialize.read(Serialize.write(x2))
- EqualityTest.check(x1, y1);
- EqualityTest.check(x2, y2);
+ EqualityTest.check(x1, y1)
+ EqualityTest.check(x2, y2)
}
catch {
case e: Exception =>
- System.out.println("Error in Test4_xml: " + e);
+ System.out.println("Error in Test4_xml: " + e)
}
}
@@ -237,35 +261,35 @@ object Test4_xml {
@serializable
class Person(_name: String) {
- private var name = _name;
- override def toString() = name;
+ private var name = _name
+ override def toString() = name
override def equals(that: Any): Boolean =
that.isInstanceOf[Person] &&
- (name == that.asInstanceOf[Person].name);
+ (name == that.asInstanceOf[Person].name)
}
@serializable
class Employee(_name: String) {
- private var name = _name;
- override def toString() = name;
+ private var name = _name
+ override def toString() = name
}
@serializable
-object bob extends Employee("Bob");
+object bob extends Employee("Bob")
object Test5 {
- val x1 = new Person("Tim");
- val x2 = bob;
+ val x1 = new Person("Tim")
+ val x2 = bob
try {
- val y1: Person = Serialize.read(Serialize.write(x1));
- val y2: Employee = Serialize.read(Serialize.write(x2));
+ val y1: Person = Serialize.read(Serialize.write(x1))
+ val y2: Employee = Serialize.read(Serialize.write(x2))
- EqualityTest.check(x1, y1);
- EqualityTest.check(x2, y2);
+ EqualityTest.check(x1, y1)
+ EqualityTest.check(x2, y2)
}
catch {
case e: Exception =>
- System.out.println("Error in Test5: " + e);
+ System.out.println("Error in Test5: " + e)
}
}
@@ -276,28 +300,28 @@ object Test5 {
object Test6 {
@serializable
object bill extends Employee("Bill") {
- val x = paul;
+ val x = paul
}
@serializable
object paul extends Person("Paul") {
val x = 4; // bill; => StackOverflowException !!!
}
- val x1 = new Person("John");
- val x2 = bill;
- val x3 = paul;
+ val x1 = new Person("John")
+ val x2 = bill
+ val x3 = paul
try {
- val y1: Person = Serialize.read(Serialize.write(x1));
- val y2: Employee = Serialize.read(Serialize.write(x2));
- val y3: Person = Serialize.read(Serialize.write(x3));
+ val y1: Person = Serialize.read(Serialize.write(x1))
+ val y2: Employee = Serialize.read(Serialize.write(x2))
+ val y3: Person = Serialize.read(Serialize.write(x3))
- EqualityTest.check(x1, y1);
- EqualityTest.check(x2, y2);
- EqualityTest.check(x3, y3);
+ EqualityTest.check(x1, y1)
+ EqualityTest.check(x2, y2)
+ EqualityTest.check(x3, y3)
}
catch {
case e: Exception =>
- System.out.println("Error in Test6: " + e);
+ System.out.println("Error in Test6: " + e)
}
}
@@ -305,12 +329,12 @@ object Test6 {
// Test code
object Test {
- def main(args: Array[String]): Unit = {
- Test1_scala;
- Test2_immutable;
- Test3_mutable;
- Test4_xml;
- Test5;
+ def main(args: Array[String]) {
+ Test1_scala
+ Test2_immutable
+ Test3_mutable
+ Test4_xml
+ Test5
Test6
}
}