Mercurial > hg > orthanc
comparison UnitTestsSources/LuaTests.cpp @ 3992:f9863630ec7f
working on the shared library for Orthanc framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Jun 2020 16:07:01 +0200 |
parents | 94f4a18a79cc |
children | 27628b0f6ada |
comparison
equal
deleted
inserted
replaced
3991:5d2348b39392 | 3992:f9863630ec7f |
---|---|
29 * You should have received a copy of the GNU General Public License | 29 * You should have received a copy of the GNU General Public License |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31 **/ | 31 **/ |
32 | 32 |
33 | 33 |
34 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 | |
35 # include <OrthancFramework/OrthancFramework.h> | |
36 #endif | |
37 | |
34 #include "PrecompiledHeadersUnitTests.h" | 38 #include "PrecompiledHeadersUnitTests.h" |
35 #include "gtest/gtest.h" | 39 #include "gtest/gtest.h" |
36 | 40 |
37 #include "../Core/OrthancException.h" | 41 #include "../Core/OrthancException.h" |
38 #include "../Core/Toolbox.h" | 42 #include "../Core/Toolbox.h" |
46 | 50 |
47 | 51 |
48 TEST(Lua, Json) | 52 TEST(Lua, Json) |
49 { | 53 { |
50 Orthanc::LuaContext lua; | 54 Orthanc::LuaContext lua; |
55 | |
56 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK != 1 | |
51 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); | 57 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); |
58 #endif | |
59 | |
52 lua.Execute("a={}"); | 60 lua.Execute("a={}"); |
53 lua.Execute("a['x'] = 10"); | 61 lua.Execute("a['x'] = 10"); |
54 lua.Execute("a['y'] = {}"); | 62 lua.Execute("a['y'] = {}"); |
55 lua.Execute("a['y'][1] = 20"); | 63 lua.Execute("a['y'][1] = 20"); |
56 lua.Execute("a['y'][2] = 20"); | 64 lua.Execute("a['y'][2] = 20"); |
65 | |
66 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK != 1 | |
57 lua.Execute("PrintRecursive(a)"); | 67 lua.Execute("PrintRecursive(a)"); |
68 #endif | |
58 | 69 |
59 lua.Execute("function f(a) print(a.bool) return a.bool,20,30,40,50,60 end"); | 70 lua.Execute("function f(a) print(a.bool) return a.bool,20,30,40,50,60 end"); |
60 | 71 |
61 Json::Value v, vv, o; | 72 Json::Value v, vv, o; |
62 //v["a"] = "b"; | 73 //v["a"] = "b"; |
70 o["x"] = 10; | 81 o["x"] = 10; |
71 o["y"] = 20; | 82 o["y"] = 20; |
72 o["z"] = 20.5f; | 83 o["z"] = 20.5f; |
73 v.append(o); | 84 v.append(o); |
74 | 85 |
86 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK != 1 | |
75 { | 87 { |
76 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | 88 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); |
77 f.PushJson(v); | 89 f.PushJson(v); |
78 f.Execute(); | 90 f.Execute(); |
79 } | 91 } |
92 #endif | |
80 | 93 |
81 { | 94 { |
82 Orthanc::LuaFunctionCall f(lua, "f"); | 95 Orthanc::LuaFunctionCall f(lua, "f"); |
83 f.PushJson(o); | 96 f.PushJson(o); |
84 ASSERT_THROW(f.ExecutePredicate(), Orthanc::OrthancException); | 97 ASSERT_THROW(f.ExecutePredicate(), Orthanc::OrthancException); |
112 ASSERT_FALSE(lua.IsExistingFunction("a")); | 125 ASSERT_FALSE(lua.IsExistingFunction("a")); |
113 ASSERT_FALSE(lua.IsExistingFunction("Dummy")); | 126 ASSERT_FALSE(lua.IsExistingFunction("Dummy")); |
114 } | 127 } |
115 | 128 |
116 | 129 |
130 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK != 1 | |
117 TEST(Lua, Simple) | 131 TEST(Lua, Simple) |
118 { | 132 { |
119 Orthanc::LuaContext lua; | 133 Orthanc::LuaContext lua; |
120 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); | 134 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); |
121 | 135 |
141 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | 155 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); |
142 f.PushDouble(3.1415); | 156 f.PushDouble(3.1415); |
143 f.Execute(); | 157 f.Execute(); |
144 } | 158 } |
145 } | 159 } |
160 #endif | |
146 | 161 |
147 | 162 |
148 TEST(Lua, ReturnJson) | 163 TEST(Lua, ReturnJson) |
149 { | 164 { |
150 Json::Value b = Json::objectValue; | 165 Json::Value b = Json::objectValue; |