annotate OrthancServer/UnitTestsSources/LuaServerTests.cpp @ 4704:f0038043fb97 openssl-3.x

removed OpenSSL license exception, as OpenSSL 3.0 was relicensed under Apache 2.0
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Jun 2021 07:37:20 +0200
parents 97d103b57cd1
children 2e71a08eea15
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
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
5 * Copyright (C) 2017-2021 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 * 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
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
15 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
16 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
17 * 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
18 * 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
19 **/
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
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 827
diff changeset
22 #include "PrecompiledHeadersUnitTests.h"
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
23 #include <gtest/gtest.h>
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
25 #include "../../OrthancFramework/Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
26 #include "../../OrthancFramework/Sources/Toolbox.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
27 #include "../../OrthancFramework/Sources/Lua/LuaFunctionCall.h"
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
4032
058b5ade8acd renaming embedded resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4031
diff changeset
29 #include <OrthancServerResources.h>
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
30
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
31 #include <boost/lexical_cast.hpp>
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
32
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
33 #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
34 # error "Please set UNIT_TESTS_WITH_HTTP_CONNEXIONS to 0 or 1"
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
35 #endif
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
36
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
38 TEST(Lua, Json)
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
40 Orthanc::LuaContext lua;
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
41
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
42 {
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
43 std::string command;
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
44 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
45 lua.Execute(command);
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
46 }
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
47
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
48 lua.Execute("a={}");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
49 lua.Execute("a['x'] = 10");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
50 lua.Execute("a['y'] = {}");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
51 lua.Execute("a['y'][1] = 20");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
52 lua.Execute("a['y'][2] = 20");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
53 lua.Execute("PrintRecursive(a)");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
54 lua.Execute("function f(a) print(a.bool) return a.bool,20,30,40,50,60 end");
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
56 Json::Value v, vv, o;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
57 //v["a"] = "b";
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
58 v.append("hello");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
59 v.append("world");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
60 v.append("42");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
61 vv.append("sub");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
62 vv.append("set");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
63 v.append(vv);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
64 o = Json::objectValue;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
65 o["x"] = 10;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
66 o["y"] = 20;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
67 o["z"] = 20.5f;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
68 v.append(o);
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
70 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
71 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
72 f.PushJson(v);
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
73 f.Execute();
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
74 }
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
76 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
77 Orthanc::LuaFunctionCall f(lua, "f");
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
78 f.PushJson(o);
1583
9ea3d082b064 got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1532
diff changeset
79 ASSERT_THROW(f.ExecutePredicate(), Orthanc::OrthancException);
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
80 }
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
82 o["bool"] = false;
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
84 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
85 Orthanc::LuaFunctionCall f(lua, "f");
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
86 f.PushJson(o);
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
87 ASSERT_FALSE(f.ExecutePredicate());
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
88 }
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
90 o["bool"] = true;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
91
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
93 Orthanc::LuaFunctionCall f(lua, "f");
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
94 f.PushJson(o);
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
95 ASSERT_TRUE(f.ExecutePredicate());
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
98
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
99
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
100 TEST(Lua, Simple)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
101 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
102 Orthanc::LuaContext lua;
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
103
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
104 {
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
105 std::string command;
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
106 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
107 lua.Execute(command);
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
108 }
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
109
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
110 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
111 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
112 f.PushString("hello");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
113 f.Execute();
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
114 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
115
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
116 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
117 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
118 f.PushBoolean(true);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
119 f.Execute();
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
120 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
121
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
122 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
123 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
124 f.PushInteger(42);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
125 f.Execute();
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
126 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
127
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
128 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
129 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
130 f.PushDouble(3.1415);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
131 f.Execute();
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
132 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
133 }
1448
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
134
3f7722179467 refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1439
diff changeset
135
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
136 TEST(Lua, Http)
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
137 {
1055
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
138 Orthanc::LuaContext lua;
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
139
2363
f8ef157f2d73 fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
140 #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
141 // 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
142 // 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
143 // 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
144 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
145
2947
11f8d72f366f Lua 5.3.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
146 #if LUA_VERSION_NUM >= 502
11f8d72f366f Lua 5.3.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
147 // Since Lua >= 5.2.0, the function "loadstring" has been replaced by "load"
11f8d72f366f Lua 5.3.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
148 lua.Execute("JSON = load(HttpGet('" + BASE + "JSON.lua')) ()");
11f8d72f366f Lua 5.3.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
149 #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
150 lua.Execute("JSON = loadstring(HttpGet('" + BASE + "JSON.lua')) ()");
2947
11f8d72f366f Lua 5.3.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
151 #endif
11f8d72f366f Lua 5.3.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
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 const std::string url(BASE + "Product.json");
1055
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
154 #endif
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
155
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
156 std::string s;
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
157 lua.Execute(s, "print(HttpGet({}))");
1439
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1396
diff changeset
158 ASSERT_EQ("nil", Orthanc::Toolbox::StripSpaces(s));
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
159
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
160 #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
161 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
162 ASSERT_LE(100, boost::lexical_cast<int>(Orthanc::Toolbox::StripSpaces(s)));
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
163
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
164 // Parse a JSON file
1055
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
165 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
166 ASSERT_EQ("OrthancClient", Orthanc::Toolbox::StripSpaces(s));
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
167
1056
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1055
diff changeset
168 #if 0
1055
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
169 // 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
170 // Orthanc is running on the localhost
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
171
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
172 lua.Execute("modality = {}");
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
173 lua.Execute("table.insert(modality, 'ORTHANC')");
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
174 lua.Execute("table.insert(modality, 'localhost')");
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
175 lua.Execute("table.insert(modality, 4242)");
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
176
1052
cc4ff680e2a0 http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1051
diff changeset
177 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
178 ASSERT_EQ("hello world", Orthanc::Toolbox::StripSpaces(s));
cc4ff680e2a0 http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1051
diff changeset
179
1055
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
180 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
181 ASSERT_EQ("42", Orthanc::Toolbox::StripSpaces(s));
1055
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
182
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
183 // Add/remove a modality with Lua
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
184 Json::Value v;
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
185 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
186 ASSERT_EQ(0, Orthanc::Toolbox::StripSpaces(s).size());
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
187 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
188 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
189 ASSERT_TRUE(v.type() == Json::arrayValue);
6f923d52a46c call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
190 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
191 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
192 ASSERT_EQ(0, Orthanc::Toolbox::StripSpaces(s).size());
1052
cc4ff680e2a0 http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1051
diff changeset
193 #endif
cc4ff680e2a0 http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1051
diff changeset
194
cc4ff680e2a0 http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1051
diff changeset
195 #endif
1051
92f4bf2c5d73 HTTP GET in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
196 }