Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts @ 690:f185cfcb72a0 am-dev
CodeGen: tests improvements
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 16 May 2019 19:10:38 +0200 |
parents | 342f3e04bfa9 |
children |
comparison
equal
deleted
inserted
replaced
688:8c0b073efda8 | 690:f185cfcb72a0 |
---|---|
1 var SendMessageToCpp: Function = null; | 1 var SendMessageToCpp: Function = null; |
2 export var TestWasmIntegratedModule : any; | 2 export var TestWasmIntegratedModule : any; |
3 | |
4 import * as TestStoneCodeGen from './build-wasm/TestStoneCodeGen_generated' | |
3 | 5 |
4 /* | 6 /* |
5 +--------------------------------------------------+ | 7 +--------------------------------------------------+ |
6 | install emscripten handlers | | 8 | install emscripten handlers | |
7 +--------------------------------------------------+ | 9 +--------------------------------------------------+ |
105 setCppOutputValue(getCppOutputValue() + "\n" + txt); | 107 setCppOutputValue(getCppOutputValue() + "\n" + txt); |
106 return ""; | 108 return ""; |
107 } | 109 } |
108 (<any> window).SendFreeTextFromCpp = SendFreeTextFromCpp; | 110 (<any> window).SendFreeTextFromCpp = SendFreeTextFromCpp; |
109 | 111 |
112 var referenceMessages = Array<any>(); | |
113 | |
114 function testTsCppTs() { | |
115 var r = new TestStoneCodeGen.Message2(); | |
116 r.memberEnumMovieType = TestStoneCodeGen.MovieType.RomCom; | |
117 r.memberStringWithDefault = "overriden"; | |
118 r.memberMapEnumFloat[TestStoneCodeGen.CrispType.CreamAndChives] = 0.5; | |
119 r.memberString = "reference-messsage2-test1"; | |
120 | |
121 referenceMessages[r.memberString] = r; | |
122 var strMsg2 = r.StoneSerialize(); | |
123 let SendMessageToCppForEchoLocal = (<any> window).Module.cwrap('SendMessageToCppForEcho', 'string', ['string']); | |
124 SendMessageToCppForEchoLocal(strMsg2); | |
125 } | |
126 | |
127 class MyEchoHandler implements TestStoneCodeGen.IHandler | |
128 { | |
129 public HandleMessage2(value: TestStoneCodeGen.Message2): boolean | |
130 { | |
131 if (value.memberString in referenceMessages) { | |
132 let r = referenceMessages[value.memberString]; | |
133 let equals = (value.memberStringWithDefault == r.memberStringWithDefault); | |
134 if (TestStoneCodeGen.CrispType.CreamAndChives in r.memberMapEnumFloat) { | |
135 equals == equals && r.memberMapEnumFloat[TestStoneCodeGen.CrispType.CreamAndChives] == value.memberMapEnumFloat[TestStoneCodeGen.CrispType.CreamAndChives]; | |
136 } | |
137 // TODO continue comparison | |
138 | |
139 if (equals) { | |
140 console.log("objects are equals after round trip"); | |
141 return true; | |
142 } | |
143 } | |
144 console.log("problem after round trip"); | |
145 return true; | |
146 } | |
147 } | |
148 | |
149 function SendMessageFromCpp(txt: string):string | |
150 { | |
151 setCppOutputValue(getCppOutputValue() + "\n" + txt); | |
152 TestStoneCodeGen.StoneDispatchToHandler(txt, new MyEchoHandler()); | |
153 return ""; | |
154 } | |
155 (<any> window).SendMessageFromCpp = SendMessageFromCpp; | |
156 | |
157 | |
110 | 158 |
111 function ButtonClick(buttonName: string) { | 159 function ButtonClick(buttonName: string) { |
112 if (buttonName.startsWith('Test ')) { | 160 if (buttonName.startsWith('Test ')) { |
113 setSerializedInputValue(stockSerializedMessages[buttonName]); | 161 setSerializedInputValue(stockSerializedMessages[buttonName]); |
162 } | |
163 else if (buttonName == "Test-ts-cpp-ts") { | |
164 testTsCppTs(); | |
114 } | 165 } |
115 else if(buttonName == 'Trigger') | 166 else if(buttonName == 'Trigger') |
116 { | 167 { |
117 let serializedInputValue:string = getSerializedInputValue(); | 168 let serializedInputValue:string = getSerializedInputValue(); |
118 | 169 |