comparison Resources/CodeGeneration/Graveyard/test_stonegen.ts @ 495:6405435480ae bgo-commands-codegen

Fixed template to add dump capabilities + started work on an integrated TS/WASM test
author bgo-osimis
date Sat, 23 Feb 2019 14:14:32 +0100
parents Resources/CodeGeneration/test_stonegen.ts@fc17251477d6
children
comparison
equal deleted inserted replaced
494:fc17251477d6 495:6405435480ae
1 import * as VsolMessages from "./VsolMessages_generated";
2
3 function TEST_StoneGen_SerializeComplex() {
4 let msg1_0 = new VsolMessages.Message1();
5 msg1_0.a = 42;
6 msg1_0.b = "Benjamin";
7 msg1_0.c = VsolMessages.EnumMonth0.January;
8 msg1_0.d = true;
9 let msg1_1 = new VsolMessages.Message1();
10 msg1_1.a = 43;
11 msg1_1.b = "Sandrine";
12 msg1_1.c = VsolMessages.EnumMonth0.March;
13 msg1_0.d = false;
14 let result1_0 = msg1_0.StoneSerialize();
15 let resultStr1_0 = JSON.stringify(result1_0);
16 let result1_1 = msg1_1.StoneSerialize();
17 let resultStr1_1 = JSON.stringify(result1_1);
18 // std::string toto;
19 // std::vector<Message1> tata;
20 // std::vector<std::string> tutu;
21 // std::map<int32_t, std::string> titi;
22 // std::map<int32_t, Message1> lulu;
23 let msg2_0 = new VsolMessages.Message2();
24 msg2_0.toto = "Prout zizi";
25 msg2_0.tata.push(msg1_0);
26 msg2_0.tata.push(msg1_1);
27 msg2_0.tutu.push("Mercadet");
28 msg2_0.tutu.push("Poisson");
29 msg2_0.titi["44"] = "key 44";
30 msg2_0.titi["45"] = "key 45";
31 msg2_0.lulu["54"] = msg1_1;
32 msg2_0.lulu["55"] = msg1_0;
33 let result2 = msg2_0.StoneSerialize();
34 let resultStr2 = JSON.stringify(result2);
35 let refResult2 = `{
36 "type" : "VsolMessages.Message2",
37 "value" :
38 {
39 "lulu" :
40 {
41 "54" :
42 {
43 "a" : 43,
44 "b" : "Sandrine",
45 "c" : 2,
46 "d" : true
47 },
48 "55" :
49 {
50 "a" : 42,
51 "b" : "Benjamin",
52 "c" : 0,
53 "d" : false
54 }
55 },
56 "tata" :
57 [
58 {
59 "a" : 42,
60 "b" : "Benjamin",
61 "c" : 0,
62 "d" : false
63 },
64 {
65 "a" : 43,
66 "b" : "Sandrine",
67 "c" : 2,
68 "d" : true
69 }
70 ],
71 "titi" :
72 {
73 "44" : "key 44",
74 "45" : "key 45"
75 },
76 "toto" : "Prout zizi",
77 "tutu" :
78 [
79 "Mercadet",
80 "Poisson"
81 ]
82 }
83 }
84 `;
85 let refResult2Obj = JSON.parse(refResult2);
86 let resultStr2Obj = JSON.parse(resultStr2);
87 if (false) {
88 if (refResult2Obj !== resultStr2Obj) {
89 console.log("Results are different!");
90 console.log(`refResult2Obj['value']['lulu']['54'] = ${refResult2Obj['value']['lulu']['54']}`);
91 console.log(`refResult2Obj['value']['lulu']['54']['a'] = ${refResult2Obj['value']['lulu']['54']['a']}`);
92 console.log("************************************************************");
93 console.log("** REFERENCE OBJ **");
94 console.log("************************************************************");
95 console.log(refResult2Obj);
96 console.log("************************************************************");
97 console.log("** ACTUAL OBJ **");
98 console.log("************************************************************");
99 console.log(resultStr2Obj);
100 console.log("************************************************************");
101 console.log("** REFERENCE **");
102 console.log("************************************************************");
103 console.log(refResult2);
104 console.log("************************************************************");
105 console.log("** ACTUAL **");
106 console.log("************************************************************");
107 console.log(resultStr2);
108 throw new Error("Wrong serialization");
109 }
110 }
111 let refResultValue = JSON.parse(resultStr2);
112 console.log(refResultValue);
113 }
114 class MyDispatcher {
115 message1: VsolMessages.Message1;
116 message2: VsolMessages.Message2;
117
118 HandleMessage1(value: VsolMessages.Message1) {
119 this.message1 = value;
120 return true;
121 }
122 HandleMessage2(value: VsolMessages.Message2) {
123 this.message2 = value;
124 return true;
125 }
126 HandleA(value) {
127 return true;
128 }
129 HandleB(value) {
130 return true;
131 }
132 HandleC(value) {
133 return true;
134 }
135 }
136 ;
137 function TEST_StoneGen_DeserializeOkAndNok() {
138 let serializedMessage = `{
139 "type" : "VsolMessages.Message2",
140 "value" :
141 {
142 "lulu" :
143 {
144 "54" :
145 {
146 "a" : 43,
147 "b" : "Sandrine",
148 "c" : 2,
149 "d" : true
150 },
151 "55" :
152 {
153 "a" : 42,
154 "b" : "Benjamin",
155 "c" : 0,
156 "d" : false
157 }
158 },
159 "tata" :
160 [
161 {
162 "a" : 42,
163 "b" : "Benjamin",
164 "c" : 0,
165 "d" : false
166 },
167 {
168 "a" : 43,
169 "b" : "Sandrine",
170 "c" : 2,
171 "d" : true
172 }
173 ],
174 "titi" :
175 {
176 "44" : "key 44",
177 "45" : "key 45"
178 },
179 "toto" : "Prout zizi",
180 "tutu" :
181 [
182 "Mercadet",
183 "Poisson"
184 ]
185 }
186 }`;
187 let myDispatcher = new MyDispatcher();
188 let ok = VsolMessages.StoneDispatchToHandler(serializedMessage, myDispatcher);
189 if (!ok) {
190 throw Error("Error when dispatching message!");
191 }
192 if (myDispatcher.message1 != undefined) {
193 throw Error("(myDispatcher.Message1 != undefined)");
194 }
195 if (myDispatcher.message2 == undefined) {
196 throw Error("(myDispatcher.Message2 == undefined)");
197 }
198 console.log("TEST_StoneGen_DeserializeOkAndNok: OK!");
199 }
200 function main() {
201 console.log("Entering main()");
202 TEST_StoneGen_SerializeComplex();
203 TEST_StoneGen_DeserializeOkAndNok();
204 return 0;
205 }
206 console.log(`Exit code is: ${main()}`);