Mercurial > hg > orthanc
comparison UnitTestsSources/LuaTests.cpp @ 1785:c131566b8252 dcmtk-3.6.1
integration mainline->dcmtk-3.6.1
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Nov 2015 10:16:21 +0100 |
parents | 87a606265de8 |
children | b1291df2f780 |
comparison
equal
deleted
inserted
replaced
1639:1b82bb0446d2 | 1785:c131566b8252 |
---|---|
169 | 169 |
170 { | 170 { |
171 Orthanc::LuaFunctionCall f(lua, "identity"); | 171 Orthanc::LuaFunctionCall f(lua, "identity"); |
172 f.PushJson("hello"); | 172 f.PushJson("hello"); |
173 Json::Value v; | 173 Json::Value v; |
174 f.ExecuteToJson(v); | 174 f.ExecuteToJson(v, false); |
175 ASSERT_EQ("hello", v.asString()); | 175 ASSERT_EQ("hello", v.asString()); |
176 } | 176 } |
177 | 177 |
178 { | 178 { |
179 Orthanc::LuaFunctionCall f(lua, "identity"); | 179 Orthanc::LuaFunctionCall f(lua, "identity"); |
180 f.PushJson(42.25); | 180 f.PushJson(42.25); |
181 Json::Value v; | 181 Json::Value v; |
182 f.ExecuteToJson(v); | 182 f.ExecuteToJson(v, false); |
183 ASSERT_FLOAT_EQ(42.25f, v.asFloat()); | 183 ASSERT_FLOAT_EQ(42.25f, v.asFloat()); |
184 } | 184 } |
185 | 185 |
186 { | 186 { |
187 Orthanc::LuaFunctionCall f(lua, "identity"); | 187 Orthanc::LuaFunctionCall f(lua, "identity"); |
188 f.PushJson(-42); | 188 f.PushJson(-42); |
189 Json::Value v; | 189 Json::Value v; |
190 f.ExecuteToJson(v); | 190 f.ExecuteToJson(v, false); |
191 ASSERT_EQ(-42, v.asInt()); | 191 ASSERT_EQ(-42, v.asInt()); |
192 } | 192 } |
193 | 193 |
194 { | 194 { |
195 Orthanc::LuaFunctionCall f(lua, "identity"); | 195 Orthanc::LuaFunctionCall f(lua, "identity"); |
196 Json::Value vv = Json::arrayValue; | 196 Json::Value vv = Json::arrayValue; |
197 f.PushJson(vv); | 197 f.PushJson(vv); |
198 Json::Value v; | 198 Json::Value v; |
199 f.ExecuteToJson(v); | 199 f.ExecuteToJson(v, false); |
200 ASSERT_EQ(Json::arrayValue, v.type()); | 200 ASSERT_EQ(Json::arrayValue, v.type()); |
201 } | 201 } |
202 | 202 |
203 { | 203 { |
204 Orthanc::LuaFunctionCall f(lua, "identity"); | 204 Orthanc::LuaFunctionCall f(lua, "identity"); |
205 Json::Value vv = Json::objectValue; | 205 Json::Value vv = Json::objectValue; |
206 f.PushJson(vv); | 206 f.PushJson(vv); |
207 Json::Value v; | 207 Json::Value v; |
208 f.ExecuteToJson(v); | 208 f.ExecuteToJson(v, false); |
209 // Lua does not make the distinction between empty lists and empty objects | 209 // Lua does not make the distinction between empty lists and empty objects |
210 ASSERT_EQ(Json::arrayValue, v.type()); | 210 ASSERT_EQ(Json::arrayValue, v.type()); |
211 } | 211 } |
212 | 212 |
213 { | 213 { |
214 Orthanc::LuaFunctionCall f(lua, "identity"); | 214 Orthanc::LuaFunctionCall f(lua, "identity"); |
215 f.PushJson(b); | 215 f.PushJson(b); |
216 Json::Value v; | 216 Json::Value v; |
217 f.ExecuteToJson(v); | 217 f.ExecuteToJson(v, false); |
218 ASSERT_EQ(Json::objectValue, v.type()); | 218 ASSERT_EQ(Json::objectValue, v.type()); |
219 ASSERT_FLOAT_EQ(42.0f, v["a"].asFloat()); | 219 ASSERT_FLOAT_EQ(42.0f, v["a"].asFloat()); |
220 ASSERT_FLOAT_EQ(44.37f, v["b"].asFloat()); | 220 ASSERT_FLOAT_EQ(44.37f, v["b"].asFloat()); |
221 ASSERT_FLOAT_EQ(-43.0f, v["c"].asFloat()); | 221 ASSERT_FLOAT_EQ(-43.0f, v["c"].asFloat()); |
222 } | 222 } |
223 | 223 |
224 { | 224 { |
225 Orthanc::LuaFunctionCall f(lua, "identity"); | 225 Orthanc::LuaFunctionCall f(lua, "identity"); |
226 f.PushJson(c); | 226 f.PushJson(c); |
227 Json::Value v; | 227 Json::Value v; |
228 f.ExecuteToJson(v); | 228 f.ExecuteToJson(v, false); |
229 ASSERT_EQ(Json::arrayValue, v.type()); | 229 ASSERT_EQ(Json::arrayValue, v.type()); |
230 ASSERT_EQ("test3", v[0].asString()); | 230 ASSERT_EQ("test3", v[0].asString()); |
231 ASSERT_EQ("test1", v[1].asString()); | 231 ASSERT_EQ("test1", v[1].asString()); |
232 ASSERT_EQ("test2", v[2].asString()); | 232 ASSERT_EQ("test2", v[2].asString()); |
233 } | 233 } |
234 | 234 |
235 { | 235 { |
236 Orthanc::LuaFunctionCall f(lua, "identity"); | 236 Orthanc::LuaFunctionCall f(lua, "identity"); |
237 f.PushJson(a); | 237 f.PushJson(a); |
238 Json::Value v; | 238 Json::Value v; |
239 f.ExecuteToJson(v); | 239 f.ExecuteToJson(v, false); |
240 ASSERT_EQ("World", v["Hello"].asString()); | 240 ASSERT_EQ("World", v["Hello"].asString()); |
241 ASSERT_EQ(Json::intValue, v["List"][0]["a"].type()); | |
242 ASSERT_EQ(Json::realValue, v["List"][0]["b"].type()); | |
243 ASSERT_EQ(Json::intValue, v["List"][0]["c"].type()); | |
241 ASSERT_EQ(42, v["List"][0]["a"].asInt()); | 244 ASSERT_EQ(42, v["List"][0]["a"].asInt()); |
245 ASSERT_FLOAT_EQ(44.37f, v["List"][0]["b"].asFloat()); | |
242 ASSERT_EQ(44, v["List"][0]["b"].asInt()); | 246 ASSERT_EQ(44, v["List"][0]["b"].asInt()); |
243 ASSERT_EQ(-43, v["List"][0]["c"].asInt()); | 247 ASSERT_EQ(-43, v["List"][0]["c"].asInt()); |
248 ASSERT_EQ("test3", v["List"][1][0].asString()); | |
249 ASSERT_EQ("test1", v["List"][1][1].asString()); | |
250 ASSERT_EQ("test2", v["List"][1][2].asString()); | |
251 } | |
252 | |
253 { | |
254 Orthanc::LuaFunctionCall f(lua, "identity"); | |
255 f.PushJson(a); | |
256 Json::Value v; | |
257 f.ExecuteToJson(v, true); | |
258 ASSERT_EQ("World", v["Hello"].asString()); | |
259 ASSERT_EQ(Json::stringValue, v["List"][0]["a"].type()); | |
260 ASSERT_EQ(Json::stringValue, v["List"][0]["b"].type()); | |
261 ASSERT_EQ(Json::stringValue, v["List"][0]["c"].type()); | |
262 ASSERT_EQ("42", v["List"][0]["a"].asString()); | |
263 ASSERT_EQ("44.37", v["List"][0]["b"].asString()); | |
264 ASSERT_EQ("-43", v["List"][0]["c"].asString()); | |
244 ASSERT_EQ("test3", v["List"][1][0].asString()); | 265 ASSERT_EQ("test3", v["List"][1][0].asString()); |
245 ASSERT_EQ("test1", v["List"][1][1].asString()); | 266 ASSERT_EQ("test1", v["List"][1][1].asString()); |
246 ASSERT_EQ("test2", v["List"][1][2].asString()); | 267 ASSERT_EQ("test2", v["List"][1][2].asString()); |
247 } | 268 } |
248 | 269 |