annotate OrthancFramework/UnitTestsSources/LuaTests.cpp @ 4074:7116e34221fe framework

merge
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Jun 2020 17:22:19 +0200
parents e00f3d089991
children bf7b9edf6b81
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
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
8 * modify it under the terms of the GNU General Public License as
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
10 * License, or (at your option) any later version.
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 * In addition, as a special exception, the copyright holders of this
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
13 * program give permission to link the code of its release with the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
16 * the linked executables. You must obey the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
20 * you do not wish to do so, delete this exception statement from your
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
21 * version. If you delete this exception statement from all source files
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
22 * in the program, then also delete it here.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
23 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
24 * 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
25 * 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
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
27 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
28 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
29 * You should have received a copy of the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
31 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
32
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
33
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
34 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
35 // 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
36 # include <OrthancFramework.h>
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
37 #endif
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
38
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
39 #include <gtest/gtest.h>
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
4059
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
41 #include "../Sources/OrthancException.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
42 #include "../Sources/Toolbox.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
43 #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
44
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
45 #include <boost/lexical_cast.hpp>
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
46
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
47
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
48 TEST(Lua, Existing)
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
49 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
50 Orthanc::LuaContext lua;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
51 lua.Execute("a={}");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
52 lua.Execute("function f() end");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
53
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
54 ASSERT_TRUE(lua.IsExistingFunction("f"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
55 ASSERT_FALSE(lua.IsExistingFunction("a"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
56 ASSERT_FALSE(lua.IsExistingFunction("Dummy"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
57 }
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
58
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
59
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
60 TEST(Lua, ReturnJson)
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
61 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
62 Json::Value b = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
63 b["a"] = 42;
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
64 b["b"] = 44.37;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
65 b["c"] = -43;
997
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 Json::Value c = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
68 c.append("test3");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
69 c.append("test1");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
70 c.append("test2");
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 Json::Value a = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
73 a["Hello"] = "World";
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
74 a["List"] = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
75 a["List"].append(b);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
76 a["List"].append(c);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
77
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
78 Orthanc::LuaContext lua;
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 // 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
81 lua.Execute("function identity(a) return a end");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
82
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
83 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
84 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
85 f.PushJson("hello");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
86 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
87 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
88 ASSERT_EQ("hello", v.asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
89 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
90
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
91 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
92 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
93 f.PushJson(42.25);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
94 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
95 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
96 ASSERT_FLOAT_EQ(42.25f, v.asFloat());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
97 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
98
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
99 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
100 Orthanc::LuaFunctionCall f(lua, "identity");
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
101 f.PushJson(-42);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
102 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
103 f.ExecuteToJson(v, false);
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
104 ASSERT_EQ(-42, v.asInt());
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
105 }
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
106
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
107 {
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
108 Orthanc::LuaFunctionCall f(lua, "identity");
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
109 Json::Value vv = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
110 f.PushJson(vv);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
111 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
112 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
113 ASSERT_EQ(Json::arrayValue, v.type());
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 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
117 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
118 Json::Value vv = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
119 f.PushJson(vv);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
120 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
121 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
122 // 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
123 ASSERT_EQ(Json::arrayValue, v.type());
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(b);
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::objectValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
132 ASSERT_FLOAT_EQ(42.0f, v["a"].asFloat());
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
133 ASSERT_FLOAT_EQ(44.37f, v["b"].asFloat());
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
134 ASSERT_FLOAT_EQ(-43.0f, v["c"].asFloat());
997
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(c);
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(Json::arrayValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
143 ASSERT_EQ("test3", v[0].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
144 ASSERT_EQ("test1", v[1].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
145 ASSERT_EQ("test2", v[2].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
146 }
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
147
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
148 {
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
149 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
150 f.PushJson(a);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
151 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
152 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
153 ASSERT_EQ("World", v["Hello"].asString());
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
154 ASSERT_EQ(Json::intValue, v["List"][0]["a"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
155 ASSERT_EQ(Json::realValue, v["List"][0]["b"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
156 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
157 ASSERT_EQ(42, v["List"][0]["a"].asInt());
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
158 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
159 ASSERT_EQ(44, v["List"][0]["b"].asInt());
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
160 ASSERT_EQ(-43, v["List"][0]["c"].asInt());
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
161 ASSERT_EQ("test3", v["List"][1][0].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
162 ASSERT_EQ("test1", v["List"][1][1].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
163 ASSERT_EQ("test2", v["List"][1][2].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
164 }
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
165
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
166 {
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
167 Orthanc::LuaFunctionCall f(lua, "identity");
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
168 f.PushJson(a);
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
169 Json::Value v;
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
170 f.ExecuteToJson(v, true);
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
171 ASSERT_EQ("World", v["Hello"].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
172 ASSERT_EQ(Json::stringValue, v["List"][0]["a"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
173 ASSERT_EQ(Json::stringValue, v["List"][0]["b"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
174 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
175 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
176 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
177 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
178 ASSERT_EQ("test3", v["List"][1][0].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
179 ASSERT_EQ("test1", v["List"][1][1].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
180 ASSERT_EQ("test2", v["List"][1][2].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
181 }
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
182
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
183 {
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
184 Orthanc::LuaFunctionCall f(lua, "DumpJson");
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
185 f.PushJson(a);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
186 std::string s;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
187 f.ExecuteToString(s);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
188
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
189 Json::FastWriter writer;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
190 std::string t = writer.write(a);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
191
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
192 ASSERT_EQ(s, t);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
193 }
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
194 }