annotate OrthancFramework/UnitTestsSources/LuaTests.cpp @ 4059:e241e5f3f088 framework

moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 14:12:07 +0200
parents OrthancServer/UnitTestsSources/LuaTests.cpp@05b8fd21089c
children 0953b3dc3261
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
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
35 # include <OrthancFramework.h>
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
36 #endif
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
37
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "gtest/gtest.h"
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
4059
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
40 #include "../Sources/OrthancException.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
41 #include "../Sources/Toolbox.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
42 #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
43
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
44 #include <boost/lexical_cast.hpp>
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
45
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
46
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
47 TEST(Lua, Existing)
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
48 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
49 Orthanc::LuaContext lua;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
50 lua.Execute("a={}");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
51 lua.Execute("function f() end");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
52
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
53 ASSERT_TRUE(lua.IsExistingFunction("f"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
54 ASSERT_FALSE(lua.IsExistingFunction("a"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
55 ASSERT_FALSE(lua.IsExistingFunction("Dummy"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
56 }
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
57
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
58
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
59 TEST(Lua, ReturnJson)
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 b = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
62 b["a"] = 42;
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
63 b["b"] = 44.37;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
64 b["c"] = -43;
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
65
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
66 Json::Value c = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
67 c.append("test3");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
68 c.append("test1");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
69 c.append("test2");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
70
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
71 Json::Value a = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
72 a["Hello"] = "World";
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
73 a["List"] = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
74 a["List"].append(b);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
75 a["List"].append(c);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
76
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
77 Orthanc::LuaContext lua;
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 // 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
80 lua.Execute("function identity(a) return a end");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
81
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 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
84 f.PushJson("hello");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
85 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
86 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
87 ASSERT_EQ("hello", v.asString());
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
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 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
92 f.PushJson(42.25);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
93 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
94 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
95 ASSERT_FLOAT_EQ(42.25f, v.asFloat());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
96 }
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 Orthanc::LuaFunctionCall f(lua, "identity");
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
100 f.PushJson(-42);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
101 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
102 f.ExecuteToJson(v, false);
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
103 ASSERT_EQ(-42, v.asInt());
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
104 }
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 Orthanc::LuaFunctionCall f(lua, "identity");
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
108 Json::Value vv = Json::arrayValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
109 f.PushJson(vv);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
110 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
111 f.ExecuteToJson(v, false);
997
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 Json::Value vv = Json::objectValue;
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
118 f.PushJson(vv);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
119 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
120 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
121 // 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
122 ASSERT_EQ(Json::arrayValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
123 }
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 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
127 f.PushJson(b);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
128 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
129 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
130 ASSERT_EQ(Json::objectValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
131 ASSERT_FLOAT_EQ(42.0f, v["a"].asFloat());
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
132 ASSERT_FLOAT_EQ(44.37f, v["b"].asFloat());
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
133 ASSERT_FLOAT_EQ(-43.0f, v["c"].asFloat());
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
134 }
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 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
138 f.PushJson(c);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
139 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
140 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
141 ASSERT_EQ(Json::arrayValue, v.type());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
142 ASSERT_EQ("test3", v[0].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
143 ASSERT_EQ("test1", v[1].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
144 ASSERT_EQ("test2", v[2].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
145 }
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 Orthanc::LuaFunctionCall f(lua, "identity");
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
149 f.PushJson(a);
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
150 Json::Value v;
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
151 f.ExecuteToJson(v, false);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
152 ASSERT_EQ("World", v["Hello"].asString());
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
153 ASSERT_EQ(Json::intValue, v["List"][0]["a"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
154 ASSERT_EQ(Json::realValue, v["List"][0]["b"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
155 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
156 ASSERT_EQ(42, v["List"][0]["a"].asInt());
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
157 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
158 ASSERT_EQ(44, v["List"][0]["b"].asInt());
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
159 ASSERT_EQ(-43, v["List"][0]["c"].asInt());
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
160 ASSERT_EQ("test3", v["List"][1][0].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
161 ASSERT_EQ("test1", v["List"][1][1].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
162 ASSERT_EQ("test2", v["List"][1][2].asString());
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
163 }
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
164
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
165 {
1659
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
166 Orthanc::LuaFunctionCall f(lua, "identity");
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
167 f.PushJson(a);
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
168 Json::Value v;
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
169 f.ExecuteToJson(v, true);
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
170 ASSERT_EQ("World", v["Hello"].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
171 ASSERT_EQ(Json::stringValue, v["List"][0]["a"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
172 ASSERT_EQ(Json::stringValue, v["List"][0]["b"].type());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
173 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
174 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
175 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
176 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
177 ASSERT_EQ("test3", v["List"][1][0].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
178 ASSERT_EQ("test1", v["List"][1][1].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
179 ASSERT_EQ("test2", v["List"][1][2].asString());
87a606265de8 fix tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
180 }
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 {
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
183 Orthanc::LuaFunctionCall f(lua, "DumpJson");
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
184 f.PushJson(a);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
185 std::string s;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
186 f.ExecuteToString(s);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
187
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
188 Json::FastWriter writer;
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
189 std::string t = writer.write(a);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
190
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
191 ASSERT_EQ(s, t);
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
192 }
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
193 }