1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
package com.esotericsoftware.kryo;
import java.util.ArrayList;
public class CopyTest extends KryoTestCase {
protected void setUp () throws Exception {
super.setUp();
kryo.setRegistrationRequired(false);
}
public void testBasic () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
test.add("three");
ArrayList copy = kryo.copy(test);
assertTrue(test != copy);
assertEquals(test, copy);
}
public void testNested () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
test.add("three");
ArrayList test2 = new ArrayList();
test2.add(1);
test2.add(2f);
test2.add(3d);
test2.add((byte)4);
test2.add((short)5);
test.add(test2);
ArrayList copy = kryo.copy(test);
assertTrue(test != copy);
assertTrue(test.get(3) != copy.get(3));
assertEquals(test, copy);
}
public void testReferences () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
test.add("three");
ArrayList test2 = new ArrayList();
test2.add(1);
test2.add(2f);
test2.add(3d);
test2.add((byte)4);
test2.add((short)5);
test.add(test2);
test.add(test2);
test.add(test2);
ArrayList copy = kryo.copy(test);
assertTrue(test != copy);
assertEquals(test, copy);
assertTrue(test.get(3) != copy.get(4));
assertTrue(copy.get(3) == copy.get(4));
assertTrue(copy.get(3) == copy.get(5));
}
public void testCircularReferences () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
test.add("three");
test.add(test);
ArrayList copy = kryo.copy(test);
assertTrue(test != copy);
assertEquals(copy.get(0), "one");
assertEquals(copy.get(1), "two");
assertEquals(copy.get(2), "three");
assertTrue(copy.get(3) == copy);
Moo root = new Moo();
Moo moo1 = new Moo();
Moo moo2 = new Moo();
Moo moo3 = new Moo();
root.moo = moo1;
moo1.moo = moo2;
moo2.moo = moo3;
moo3.moo = root;
Moo root2 = kryo.copy(root);
assertTrue(root != root2);
assertTrue(root.moo != root2.moo);
assertTrue(root.moo.moo != root2.moo.moo);
assertTrue(root.moo.moo.moo != root2.moo.moo.moo);
assertTrue(root.moo.moo.moo.moo != root2.moo.moo.moo.moo);
assertTrue(root.moo.moo.moo.moo == root);
assertTrue(root2.moo.moo.moo.moo == root2);
}
public void testShallow () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
test.add("three");
ArrayList test2 = new ArrayList();
test2.add(1);
test2.add(2f);
test2.add(3d);
test2.add((byte)4);
test2.add((short)5);
test.add(test2);
ArrayList copy = kryo.copyShallow(test);
assertTrue(test != copy);
assertTrue(test.get(3) == copy.get(3));
assertEquals(test, copy);
}
static public class Moo {
Moo moo;
}
}
|