1 package be
.nikiroo
.utils
.test
;
3 import be
.nikiroo
.utils
.Version
;
4 import be
.nikiroo
.utils
.serial
.ConnectActionServer
;
5 import be
.nikiroo
.utils
.serial
.Exporter
;
6 import be
.nikiroo
.utils
.serial
.Importer
;
7 import be
.nikiroo
.utils
.serial
.Server
;
9 class SerialTest
extends TestLauncher
{
10 private void not_used() {
11 // TODO: test Server ; but this will at least help dependency checking
13 Server server
= new Server(null, 0, false) {
15 protected Object
onRequest(ConnectActionServer action
,
16 Version clientVersion
, Object data
) throws Exception
{
20 } catch (Exception e
) {
24 private SerialTest() {
25 super("Serial test", null);
28 public SerialTest(String
[] args
) {
29 super("Serial test", args
);
31 addTest(new TestCase("Simple class Import/Export") {
33 public void test() throws Exception
{
34 Data data
= new Data(42);
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") {
47 public void test() throws Exception
{
48 Data data
= new DataObject(new Data(21));
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"));
59 addTest(new TestCase("Import/Export with nested objects forming a loop") {
61 public void test() throws Exception
{
62 DataLoop data
= new DataLoop("looping");
63 data
.next
= new DataLoop("level 2");
64 data
.next
.next
= data
;
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 in Object Import/Export") {
78 public void test() throws Exception
{
79 Object data
= new DataArray();// 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("Array Import/Export") {
92 public void test() throws Exception
{
93 Object data
= new String
[] { "un", "deux" };
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"));
104 addTest(new TestCase("Enum Import/Export") {
106 public void test() throws Exception
{
107 Object data
= EnumToSend
.FANFAN
;
108 String encoded
= new Exporter().append(data
).toString(false);
109 Object redata
= new Importer().read(encoded
).getValue();
110 String reencoded
= new Exporter().append(redata
)
113 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
114 reencoded
.replaceAll("@[0-9]*", "@REF"));
120 public String
[] data
= new String
[] { "un", "deux" };
123 @SuppressWarnings("unused")
130 public Data(int value
) {
135 @SuppressWarnings("unused")
136 class DataObject
extends Data
{
139 @SuppressWarnings("synthetic-access")
140 private DataObject() {
143 @SuppressWarnings("synthetic-access")
144 public DataObject(Data data
) {
149 @SuppressWarnings("unused")
150 class DataLoop
extends Data
{
151 public DataLoop next
;
152 private String value
;
154 @SuppressWarnings("synthetic-access")
158 @SuppressWarnings("synthetic-access")
159 public DataLoop(String value
) {