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
{
7 public SerialTest(String
[] args
) {
8 super("Serial test", args
);
10 addTest(new TestCase("Simple class Import/Export") {
12 public void test() throws Exception
{
13 Data data
= new Data(42);
14 String encoded
= new Exporter().append(data
).toString(false);
15 Object redata
= new Importer().read(encoded
).getValue();
16 String reencoded
= new Exporter().append(redata
)
19 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
20 reencoded
.replaceAll("@[0-9]*", "@REF"));
24 addTest(new TestCase("Import/Export with nested objects") {
26 public void test() throws Exception
{
27 Data data
= new DataObject(new Data(21));
28 String encoded
= new Exporter().append(data
).toString(false);
29 Object redata
= new Importer().read(encoded
).getValue();
30 String reencoded
= new Exporter().append(redata
)
33 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
34 reencoded
.replaceAll("@[0-9]*", "@REF"));
38 addTest(new TestCase("Import/Export with nested objects forming a loop") {
40 public void test() throws Exception
{
41 DataLoop data
= new DataLoop("looping");
42 data
.next
= new DataLoop("level 2");
43 data
.next
.next
= data
;
45 String encoded
= new Exporter().append(data
).toString(false);
46 Object redata
= new Importer().read(encoded
).getValue();
47 String reencoded
= new Exporter().append(redata
)
50 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
51 reencoded
.replaceAll("@[0-9]*", "@REF"));
55 addTest(new TestCase("Array in Object Import/Export") {
57 public void test() throws Exception
{
58 Object data
= new DataArray();// new String[] { "un", "deux" };
59 String encoded
= new Exporter().append(data
).toString(false);
60 Object redata
= new Importer().read(encoded
).getValue();
61 String reencoded
= new Exporter().append(redata
)
64 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
65 reencoded
.replaceAll("@[0-9]*", "@REF"));
69 addTest(new TestCase("Array Import/Export") {
71 public void test() throws Exception
{
72 Object data
= new String
[] { "un", "deux" };
73 String encoded
= new Exporter().append(data
).toString(false);
74 Object redata
= new Importer().read(encoded
).getValue();
75 String reencoded
= new Exporter().append(redata
)
78 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
79 reencoded
.replaceAll("@[0-9]*", "@REF"));
83 addTest(new TestCase("Enum Import/Export") {
85 public void test() throws Exception
{
86 Object data
= EnumToSend
.FANFAN
;
87 String encoded
= new Exporter().append(data
).toString(false);
88 Object redata
= new Importer().read(encoded
).getValue();
89 String reencoded
= new Exporter().append(redata
)
92 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
93 reencoded
.replaceAll("@[0-9]*", "@REF"));
99 public String
[] data
= new String
[] { "un", "deux" };
102 @SuppressWarnings("unused")
109 public Data(int value
) {
114 @SuppressWarnings("unused")
115 class DataObject
extends Data
{
118 @SuppressWarnings("synthetic-access")
119 private DataObject() {
122 @SuppressWarnings("synthetic-access")
123 public DataObject(Data data
) {
128 @SuppressWarnings("unused")
129 class DataLoop
extends Data
{
130 public DataLoop next
;
131 private String value
;
133 @SuppressWarnings("synthetic-access")
137 @SuppressWarnings("synthetic-access")
138 public DataLoop(String value
) {