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 @SuppressWarnings("unused")
11 private void not_used() {
12 // TODO: test Server ; but this will at least help dependency checking
14 Server server
= new Server(0, false) {
16 protected Object
onRequest(ConnectActionServer action
,
17 Version clientVersion
, Object data
) throws Exception
{
21 } catch (Exception e
) {
25 private SerialTest() {
26 super("Serial test", null);
29 public SerialTest(String
[] args
) {
30 super("Serial test", args
);
32 addTest(new TestCase("Simple class Import/Export") {
34 public void test() throws Exception
{
35 Data data
= new Data(42);
36 String encoded
= new Exporter().append(data
).toString(false);
37 Object redata
= new Importer().read(encoded
).getValue();
38 String reencoded
= new Exporter().append(redata
)
41 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
42 reencoded
.replaceAll("@[0-9]*", "@REF"));
46 addTest(new TestCase("Import/Export with nested objects") {
48 public void test() throws Exception
{
49 Data data
= new DataObject(new Data(21));
50 String encoded
= new Exporter().append(data
).toString(false);
51 Object redata
= new Importer().read(encoded
).getValue();
52 String reencoded
= new Exporter().append(redata
)
55 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
56 reencoded
.replaceAll("@[0-9]*", "@REF"));
60 addTest(new TestCase("Import/Export with nested objects forming a loop") {
62 public void test() throws Exception
{
63 DataLoop data
= new DataLoop("looping");
64 data
.next
= new DataLoop("level 2");
65 data
.next
.next
= data
;
67 String encoded
= new Exporter().append(data
).toString(false);
68 Object redata
= new Importer().read(encoded
).getValue();
69 String reencoded
= new Exporter().append(redata
)
72 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
73 reencoded
.replaceAll("@[0-9]*", "@REF"));
77 addTest(new TestCase("Array in Object Import/Export") {
79 public void test() throws Exception
{
80 Object data
= new DataArray();// new String[] { "un", "deux" };
81 String encoded
= new Exporter().append(data
).toString(false);
82 Object redata
= new Importer().read(encoded
).getValue();
83 String reencoded
= new Exporter().append(redata
)
86 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
87 reencoded
.replaceAll("@[0-9]*", "@REF"));
91 addTest(new TestCase("Array Import/Export") {
93 public void test() throws Exception
{
94 Object data
= new String
[] { "un", "deux" };
95 String encoded
= new Exporter().append(data
).toString(false);
96 Object redata
= new Importer().read(encoded
).getValue();
97 String reencoded
= new Exporter().append(redata
)
100 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
101 reencoded
.replaceAll("@[0-9]*", "@REF"));
105 addTest(new TestCase("Enum Import/Export") {
107 public void test() throws Exception
{
108 Object data
= EnumToSend
.FANFAN
;
109 String encoded
= new Exporter().append(data
).toString(false);
110 Object redata
= new Importer().read(encoded
).getValue();
111 String reencoded
= new Exporter().append(redata
)
114 assertEquals(encoded
.replaceAll("@[0-9]*", "@REF"),
115 reencoded
.replaceAll("@[0-9]*", "@REF"));
121 public String
[] data
= new String
[] { "un", "deux" };
124 @SuppressWarnings("unused")
131 public Data(int value
) {
136 @SuppressWarnings("unused")
137 class DataObject
extends Data
{
140 @SuppressWarnings("synthetic-access")
141 private DataObject() {
144 @SuppressWarnings("synthetic-access")
145 public DataObject(Data data
) {
150 @SuppressWarnings("unused")
151 class DataLoop
extends Data
{
152 public DataLoop next
;
153 private String value
;
155 @SuppressWarnings("synthetic-access")
159 @SuppressWarnings("synthetic-access")
160 public DataLoop(String value
) {