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 * Required for Import/Export of objects.
14 public SerialTest(String
[] args
) {
15 super("Serial test", args
);
17 addTest(new TestCase("Simple class Import/Export") {
19 public void test() throws Exception
{
20 Data data
= new Data(42);
21 String encoded
= new Exporter().append(data
).toString(false);
22 Object redata
= new Importer().read(encoded
).getValue();
23 String reencoded
= new Exporter().append(redata
)
26 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
27 reencoded
.replaceAll("@[0-9]*", "@REF"));
31 addTest(new TestCase("Import/Export with nested objects") {
33 public void test() throws Exception
{
34 Data data
= new DataObject(new Data(21));
35 String encoded
= new Exporter().append(data
).toString(false);
36 Object redata
= new Importer().read(encoded
).getValue();
37 String reencoded
= new Exporter().append(redata
)
40 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
41 reencoded
.replaceAll("@[0-9]*", "@REF"));
45 addTest(new TestCase("Import/Export with nested objects forming a loop") {
47 public void test() throws Exception
{
48 DataLoop data
= new DataLoop("looping");
49 data
.next
= new DataLoop("level 2");
50 data
.next
.next
= data
;
52 String encoded
= new Exporter().append(data
).toString(false);
53 Object redata
= new Importer().read(encoded
).getValue();
54 String reencoded
= new Exporter().append(redata
)
57 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
58 reencoded
.replaceAll("@[0-9]*", "@REF"));
62 addTest(new TestCase("Array in Object Import/Export") {
64 public void test() throws Exception
{
65 Object data
= new DataArray();// new String[] { "un", "deux" };
66 String encoded
= new Exporter().append(data
).toString(false);
67 Object redata
= new Importer().read(encoded
).getValue();
68 String reencoded
= new Exporter().append(redata
)
71 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
72 reencoded
.replaceAll("@[0-9]*", "@REF"));
76 addTest(new TestCase("Array Import/Export") {
78 public void test() throws Exception
{
79 Object data
= new String
[] { "un", "deux" };
80 String encoded
= new Exporter().append(data
).toString(false);
81 Object redata
= new Importer().read(encoded
).getValue();
82 String reencoded
= new Exporter().append(redata
)
85 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
86 reencoded
.replaceAll("@[0-9]*", "@REF"));
90 addTest(new TestCase("Enum Import/Export") {
92 public void test() throws Exception
{
93 Object data
= EnumToSend
.FANFAN
;
94 String encoded
= new Exporter().append(data
).toString(false);
95 Object redata
= new Importer().read(encoded
).getValue();
96 String reencoded
= new Exporter().append(redata
)
99 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
100 reencoded
.replaceAll("@[0-9]*", "@REF"));
106 public String
[] data
= new String
[] { "un", "deux" };
109 @SuppressWarnings("unused")
116 public Data(int value
) {
121 @SuppressWarnings("unused")
122 class DataObject
extends Data
{
125 @SuppressWarnings("synthetic-access")
126 private DataObject() {
129 @SuppressWarnings("synthetic-access")
130 public DataObject(Data data
) {
135 @SuppressWarnings("unused")
136 class DataLoop
extends Data
{
137 public DataLoop next
;
138 private String value
;
140 @SuppressWarnings("synthetic-access")
144 @SuppressWarnings("synthetic-access")
145 public DataLoop(String value
) {