Mercurial > hg > orthanc
annotate OrthancServer/UnitTestsSources/LuaServerTests.cpp @ 4870:43e613a7756b
upgrade to year 2022
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jan 2022 11:15:42 +0100 |
parents | 7053502fbf97 |
children | 6eff25f70121 |
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 | 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 |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
7 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
12 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * 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
|
17 * 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
|
18 * 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
|
19 * 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
|
20 * 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
|
21 * 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
|
22 * 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
|
23 * in the program, then also delete it here. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
24 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
25 * 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
|
26 * 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
|
27 * 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
|
28 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
29 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
30 * 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
|
31 * 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
|
32 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
33 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
712
diff
changeset
|
34 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
35 #include "PrecompiledHeadersUnitTests.h" |
4062 | 36 #include <gtest/gtest.h> |
386 | 37 |
4045 | 38 #include "../../OrthancFramework/Sources/OrthancException.h" |
39 #include "../../OrthancFramework/Sources/Toolbox.h" | |
40 #include "../../OrthancFramework/Sources/Lua/LuaFunctionCall.h" | |
386 | 41 |
4032
058b5ade8acd
renaming embedded resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4031
diff
changeset
|
42 #include <OrthancServerResources.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 |
1051 | 46 #if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS) |
4059
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
47 # error "Please set UNIT_TESTS_WITH_HTTP_CONNEXIONS to 0 or 1" |
1051 | 48 #endif |
49 | |
386 | 50 |
712 | 51 TEST(Lua, Json) |
386 | 52 { |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
53 Orthanc::LuaContext lua; |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
54 |
4031
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
55 { |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
56 std::string command; |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
57 Orthanc::ServerResources::GetFileResource(command, Orthanc::ServerResources::LUA_TOOLBOX); |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
58 lua.Execute(command); |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
59 } |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
60 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
61 lua.Execute("a={}"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
62 lua.Execute("a['x'] = 10"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
63 lua.Execute("a['y'] = {}"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
64 lua.Execute("a['y'][1] = 20"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
65 lua.Execute("a['y'][2] = 20"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
66 lua.Execute("PrintRecursive(a)"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
67 lua.Execute("function f(a) print(a.bool) return a.bool,20,30,40,50,60 end"); |
386 | 68 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
69 Json::Value v, vv, o; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
70 //v["a"] = "b"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
71 v.append("hello"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
72 v.append("world"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
73 v.append("42"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
74 vv.append("sub"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
75 vv.append("set"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
76 v.append(vv); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
77 o = Json::objectValue; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
78 o["x"] = 10; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
79 o["y"] = 20; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
80 o["z"] = 20.5f; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
81 v.append(o); |
386 | 82 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
83 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
84 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
85 f.PushJson(v); |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
86 f.Execute(); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
87 } |
386 | 88 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
89 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
90 Orthanc::LuaFunctionCall f(lua, "f"); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
91 f.PushJson(o); |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
92 ASSERT_THROW(f.ExecutePredicate(), Orthanc::OrthancException); |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
93 } |
386 | 94 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
95 o["bool"] = false; |
386 | 96 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
97 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
98 Orthanc::LuaFunctionCall f(lua, "f"); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
99 f.PushJson(o); |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
100 ASSERT_FALSE(f.ExecutePredicate()); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
101 } |
386 | 102 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
103 o["bool"] = true; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
104 |
386 | 105 { |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
106 Orthanc::LuaFunctionCall f(lua, "f"); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
107 f.PushJson(o); |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
108 ASSERT_TRUE(f.ExecutePredicate()); |
386 | 109 } |
110 } | |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
111 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
112 |
712 | 113 TEST(Lua, Simple) |
114 { | |
115 Orthanc::LuaContext lua; | |
4031
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
116 |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
117 { |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
118 std::string command; |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
119 Orthanc::ServerResources::GetFileResource(command, Orthanc::ServerResources::LUA_TOOLBOX); |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
120 lua.Execute(command); |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
121 } |
712 | 122 |
123 { | |
124 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
125 f.PushString("hello"); | |
126 f.Execute(); | |
127 } | |
128 | |
129 { | |
130 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
131 f.PushBoolean(true); | |
132 f.Execute(); | |
133 } | |
134 | |
135 { | |
136 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
137 f.PushInteger(42); | |
138 f.Execute(); | |
139 } | |
140 | |
141 { | |
142 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
143 f.PushDouble(3.1415); | |
144 f.Execute(); | |
145 } | |
146 } | |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
147 |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
148 |
1051 | 149 TEST(Lua, Http) |
150 { | |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
151 Orthanc::LuaContext lua; |
1051 | 152 |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
153 #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1 |
2386
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
154 // The "http://www.orthanc-server.com/downloads/third-party/" does |
4505
97d103b57cd1
removed cached dicom summary from DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
155 // not automatically redirect to HTTPS, so we use it even if the |
2386
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
156 // OpenSSL/HTTPS support is disabled in curl |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
157 const std::string BASE = "http://www.orthanc-server.com/downloads/third-party/"; |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
158 |
2947 | 159 #if LUA_VERSION_NUM >= 502 |
160 // Since Lua >= 5.2.0, the function "loadstring" has been replaced by "load" | |
161 lua.Execute("JSON = load(HttpGet('" + BASE + "JSON.lua')) ()"); | |
162 #else | |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
163 lua.Execute("JSON = loadstring(HttpGet('" + BASE + "JSON.lua')) ()"); |
2947 | 164 #endif |
165 | |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
166 const std::string url(BASE + "Product.json"); |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
167 #endif |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
168 |
1051 | 169 std::string s; |
170 lua.Execute(s, "print(HttpGet({}))"); | |
1439 | 171 ASSERT_EQ("nil", Orthanc::Toolbox::StripSpaces(s)); |
1051 | 172 |
173 #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1 | |
174 lua.Execute(s, "print(string.len(HttpGet(\"" + url + "\")))"); | |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
175 ASSERT_LE(100, boost::lexical_cast<int>(Orthanc::Toolbox::StripSpaces(s))); |
1051 | 176 |
177 // Parse a JSON file | |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
178 lua.Execute(s, "print(JSON:decode(HttpGet(\"" + url + "\")) ['Product'])"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
179 ASSERT_EQ("OrthancClient", Orthanc::Toolbox::StripSpaces(s)); |
1051 | 180 |
1056 | 181 #if 0 |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
182 // This part of the test can only be executed if one instance of |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
183 // Orthanc is running on the localhost |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
184 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
185 lua.Execute("modality = {}"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
186 lua.Execute("table.insert(modality, 'ORTHANC')"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
187 lua.Execute("table.insert(modality, 'localhost')"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
188 lua.Execute("table.insert(modality, 4242)"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
189 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
190 lua.Execute(s, "print(HttpPost(\"http://localhost:8042/tools/execute-script\", \"print('hello world')\"))"); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
191 ASSERT_EQ("hello world", Orthanc::Toolbox::StripSpaces(s)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
192 |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
193 lua.Execute(s, "print(JSON:decode(HttpPost(\"http://localhost:8042/tools/execute-script\", \"print('[10,42,1000]')\")) [2])"); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
194 ASSERT_EQ("42", Orthanc::Toolbox::StripSpaces(s)); |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
195 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
196 // Add/remove a modality with Lua |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
197 Json::Value v; |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
198 lua.Execute(s, "print(HttpGet('http://localhost:8042/modalities/lua'))"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
199 ASSERT_EQ(0, Orthanc::Toolbox::StripSpaces(s).size()); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
200 lua.Execute(s, "print(HttpPut('http://localhost:8042/modalities/lua', JSON:encode(modality)))"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
201 lua.Execute(v, "print(HttpGet('http://localhost:8042/modalities/lua'))"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
202 ASSERT_TRUE(v.type() == Json::arrayValue); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
203 lua.Execute(s, "print(HttpDelete('http://localhost:8042/modalities/lua'))"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
204 lua.Execute(s, "print(HttpGet('http://localhost:8042/modalities/lua'))"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
205 ASSERT_EQ(0, Orthanc::Toolbox::StripSpaces(s).size()); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
206 #endif |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
207 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
208 #endif |
1051 | 209 } |