1 package be
.nikiroo
.utils
.test
;
3 import be
.nikiroo
.utils
.serial
.Exporter
;
4 import be
.nikiroo
.utils
.serial
.Importer
;
6 class SerialTest
extends TestLauncher
{
8 super("Serial test", null);
11 public SerialTest(String
[] args
) {
12 super("Serial test", args
);
14 addTest(new TestCase("Simple class Import/Export") {
16 public void test() throws Exception
{
17 Data data
= new Data(42);
18 String encoded
= new Exporter().append(data
).toString(false);
19 Object redata
= new Importer().read(encoded
).getValue();
20 String reencoded
= new Exporter().append(redata
)
23 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
24 reencoded
.replaceAll("@[0-9]*", "@REF"));
28 addTest(new TestCase("Import/Export with nested objects") {
30 public void test() throws Exception
{
31 Data data
= new DataObject(new Data(21));
32 String encoded
= new Exporter().append(data
).toString(false);
33 Object redata
= new Importer().read(encoded
).getValue();
34 String reencoded
= new Exporter().append(redata
)
37 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
38 reencoded
.replaceAll("@[0-9]*", "@REF"));
42 addTest(new TestCase("Import/Export with nested objects forming a loop") {
44 public void test() throws Exception
{
45 DataLoop data
= new DataLoop("looping");
46 data
.next
= new DataLoop("level 2");
47 data
.next
.next
= data
;
49 String encoded
= new Exporter().append(data
).toString(false);
50 Object redata
= new Importer().read(encoded
).getValue();
51 String reencoded
= new Exporter().append(redata
)
54 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
55 reencoded
.replaceAll("@[0-9]*", "@REF"));
60 @SuppressWarnings("unused")
67 public Data(int value
) {
72 @SuppressWarnings("unused")
73 class DataObject
extends Data
{
76 @SuppressWarnings("synthetic-access")
77 private DataObject() {
80 @SuppressWarnings("synthetic-access")
81 public DataObject(Data data
) {
86 @SuppressWarnings("unused")
87 class DataLoop
extends Data
{
91 @SuppressWarnings("synthetic-access")
95 @SuppressWarnings("synthetic-access")
96 public DataLoop(String value
) {