annotate OrthancFramework/UnitTestsSources/LuaTests.cpp @ 4327:9684a690ca63

fix link errors on wasm unit tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2020 20:53:21 +0100
parents bf7b9edf6b81
children 3af1d763763a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
1 /**
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1659
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1056
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
6 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * the License, or (at your option) any later version.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
11 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
12 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
15 * Lesser General Public License for more details.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * <http://www.gnu.org/licenses/>.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
20 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
21
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
22
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
23 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
24 // Must be the first to be sure to use the Orthanc framework shared library
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
25 # include <OrthancFramework.h>
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
26 #endif
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
27
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
28 #include <gtest/gtest.h>
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
4059
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
30 #include "../Sources/OrthancException.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
31 #include "../Sources/Toolbox.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
32 #include "../Sources/Lua/LuaFunctionCall.h"
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
33
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
34 #include <boost/lexical_cast.hpp>
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
35
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
36
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
37 TEST(Lua, Existing)
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
38 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
39 Orthanc::LuaContext lua;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
40 lua.Execute("a={}");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
41 lua.Execute("function f() end");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
42
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
43 ASSERT_TRUE(lua.IsExistingFunction("f"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
44 ASSERT_FALSE(lua.IsExistingFunction("a"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
45 ASSERT_FALSE(lua.IsExistingFunction("Dummy"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
46 }
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
47
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
48
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
49 TEST(Lua, ReturnJson)
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
50 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
51 Json::Value b = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
52 b["a"] = 42;
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
53 b["b"] = 44.37;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
54 b["c"] = -43;
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
55
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
56 Json::Value c = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
57 c.append("test3");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
58 c.append("test1");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
59 c.append("test2");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
60
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
61 Json::Value a = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
62 a["Hello"] = "World";
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
63 a["List"] = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
64 a["List"].append(b);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
65 a["List"].append(c);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
66
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
67 Orthanc::LuaContext lua;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
68
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
69 // This is the identity function (it simply returns its input)
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
70 lua.Execute("function identity(a) return a end");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
71
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
72 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
73 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
74 f.PushJson("hello");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
75 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
76 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
77 ASSERT_EQ("hello", v.asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
78 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
79
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
80 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
81 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
82 f.PushJson(42.25);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
83 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
84 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
85 ASSERT_FLOAT_EQ(42.25f, v.asFloat());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
86 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
87
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
88 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
89 Orthanc::LuaFunctionCall f(lua, "identity");
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
90 f.PushJson(-42);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
91 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
92 f.ExecuteToJson(v, false);
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
93 ASSERT_EQ(-42, v.asInt());
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
94 }
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
95
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
96 {
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
97 Orthanc::LuaFunctionCall f(lua, "identity");
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
98 Json::Value vv = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
99 f.PushJson(vv);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
100 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
101 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
102 ASSERT_EQ(Json::arrayValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
103 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
104
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
105 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
106 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
107 Json::Value vv = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
108 f.PushJson(vv);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
109 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
110 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
111 // Lua does not make the distinction between empty lists and empty objects
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
112 ASSERT_EQ(Json::arrayValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
113 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
114
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
115 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
116 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
117 f.PushJson(b);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
118 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
119 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
120 ASSERT_EQ(Json::objectValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
121 ASSERT_FLOAT_EQ(42.0f, v["a"].asFloat());
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
122 ASSERT_FLOAT_EQ(44.37f, v["b"].asFloat());
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
123 ASSERT_FLOAT_EQ(-43.0f, v["c"].asFloat());
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
124 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
125
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
126 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
127 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
128 f.PushJson(c);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
129 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
130 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
131 ASSERT_EQ(Json::arrayValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
132 ASSERT_EQ("test3", v[0].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
133 ASSERT_EQ("test1", v[1].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
134 ASSERT_EQ("test2", v[2].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
135 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
136
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
137 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
138 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
139 f.PushJson(a);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
140 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
141 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
142 ASSERT_EQ("World", v["Hello"].asString());
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
143 ASSERT_EQ(Json::intValue, v["List"][0]["a"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
144 ASSERT_EQ(Json::realValue, v["List"][0]["b"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
145 ASSERT_EQ(Json::intValue, v["List"][0]["c"].type());
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
146 ASSERT_EQ(42, v["List"][0]["a"].asInt());
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
147 ASSERT_FLOAT_EQ(44.37f, v["List"][0]["b"].asFloat());
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
148 ASSERT_EQ(44, v["List"][0]["b"].asInt());
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
149 ASSERT_EQ(-43, v["List"][0]["c"].asInt());
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
150 ASSERT_EQ("test3", v["List"][1][0].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
151 ASSERT_EQ("test1", v["List"][1][1].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
152 ASSERT_EQ("test2", v["List"][1][2].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
153 }
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
154
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
155 {
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
156 Orthanc::LuaFunctionCall f(lua, "identity");
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
157 f.PushJson(a);
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
158 Json::Value v;
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
159 f.ExecuteToJson(v, true);
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
160 ASSERT_EQ("World", v["Hello"].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
161 ASSERT_EQ(Json::stringValue, v["List"][0]["a"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
162 ASSERT_EQ(Json::stringValue, v["List"][0]["b"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
163 ASSERT_EQ(Json::stringValue, v["List"][0]["c"].type());
1966
8c506670f3cd fix unit tests for recent JsonCpp releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
164 ASSERT_FLOAT_EQ(42.0f, boost::lexical_cast<float>(v["List"][0]["a"].asString()));
8c506670f3cd fix unit tests for recent JsonCpp releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
165 ASSERT_FLOAT_EQ(44.37f, boost::lexical_cast<float>(v["List"][0]["b"].asString()));
8c506670f3cd fix unit tests for recent JsonCpp releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
166 ASSERT_FLOAT_EQ(-43.0f, boost::lexical_cast<float>(v["List"][0]["c"].asString()));
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
167 ASSERT_EQ("test3", v["List"][1][0].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
168 ASSERT_EQ("test1", v["List"][1][1].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
169 ASSERT_EQ("test2", v["List"][1][2].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
170 }
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
171
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
172 {
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
173 Orthanc::LuaFunctionCall f(lua, "DumpJson");
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
174 f.PushJson(a);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
175 std::string s;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
176 f.ExecuteToString(s);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
177
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
178 Json::FastWriter writer;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
179 std::string t = writer.write(a);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
180
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
181 ASSERT_EQ(s, t);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
182 }
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
183 }