Mercurial > hg > orthanc
annotate UnitTestsSources/LuaTests.cpp @ 2840:f4c232bba1eb
bgra32 to grayscale conversion
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 Sep 2018 10:17:59 +0200 |
parents | 878b59270859 |
children | 11f8d72f366f |
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 |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2386
diff
changeset
|
5 * Copyright (C) 2017-2018 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 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
34 #include "PrecompiledHeadersUnitTests.h" |
386 | 35 #include "gtest/gtest.h" |
36 | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
37 #include "../Core/OrthancException.h" |
1051 | 38 #include "../Core/Toolbox.h" |
386 | 39 #include "../Core/Lua/LuaFunctionCall.h" |
40 | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
41 #include <boost/lexical_cast.hpp> |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
42 |
1051 | 43 #if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS) |
1532 | 44 #error "Please set UNIT_TESTS_WITH_HTTP_CONNEXIONS to 0 or 1" |
1051 | 45 #endif |
46 | |
386 | 47 |
712 | 48 TEST(Lua, Json) |
386 | 49 { |
397
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(Orthanc::EmbeddedResources::LUA_TOOLBOX); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
52 lua.Execute("a={}"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
53 lua.Execute("a['x'] = 10"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
54 lua.Execute("a['y'] = {}"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
55 lua.Execute("a['y'][1] = 20"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
56 lua.Execute("a['y'][2] = 20"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
57 lua.Execute("PrintRecursive(a)"); |
386 | 58 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
59 lua.Execute("function f(a) print(a.bool) return a.bool,20,30,40,50,60 end"); |
386 | 60 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
61 Json::Value v, vv, o; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
62 //v["a"] = "b"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
63 v.append("hello"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
64 v.append("world"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
65 v.append("42"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
66 vv.append("sub"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
67 vv.append("set"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
68 v.append(vv); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
69 o = Json::objectValue; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
70 o["x"] = 10; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
71 o["y"] = 20; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
72 o["z"] = 20.5f; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
73 v.append(o); |
386 | 74 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
75 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
76 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
77 f.PushJson(v); |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
78 f.Execute(); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
79 } |
386 | 80 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
81 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
82 Orthanc::LuaFunctionCall f(lua, "f"); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
83 f.PushJson(o); |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
84 ASSERT_THROW(f.ExecutePredicate(), Orthanc::OrthancException); |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
85 } |
386 | 86 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
87 o["bool"] = false; |
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); |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
92 ASSERT_FALSE(f.ExecutePredicate()); |
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"] = true; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
96 |
386 | 97 { |
397
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_TRUE(f.ExecutePredicate()); |
386 | 101 } |
102 } | |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
103 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
104 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
105 TEST(Lua, Existing) |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
106 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
107 Orthanc::LuaContext lua; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
108 lua.Execute("a={}"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
109 lua.Execute("function f() end"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
110 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
111 ASSERT_TRUE(lua.IsExistingFunction("f")); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
112 ASSERT_FALSE(lua.IsExistingFunction("a")); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
113 ASSERT_FALSE(lua.IsExistingFunction("Dummy")); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
114 } |
712 | 115 |
116 | |
117 TEST(Lua, Simple) | |
118 { | |
119 Orthanc::LuaContext lua; | |
120 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); | |
121 | |
122 { | |
123 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
124 f.PushString("hello"); | |
125 f.Execute(); | |
126 } | |
127 | |
128 { | |
129 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
130 f.PushBoolean(true); | |
131 f.Execute(); | |
132 } | |
133 | |
134 { | |
135 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
136 f.PushInteger(42); | |
137 f.Execute(); | |
138 } | |
139 | |
140 { | |
141 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
142 f.PushDouble(3.1415); | |
143 f.Execute(); | |
144 } | |
145 } | |
997
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 TEST(Lua, ReturnJson) |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
149 { |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
150 Json::Value b = Json::objectValue; |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
151 b["a"] = 42; |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
152 b["b"] = 44.37; |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
153 b["c"] = -43; |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
154 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
155 Json::Value c = Json::arrayValue; |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
156 c.append("test3"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
157 c.append("test1"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
158 c.append("test2"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
159 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
160 Json::Value a = Json::objectValue; |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
161 a["Hello"] = "World"; |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
162 a["List"] = Json::arrayValue; |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
163 a["List"].append(b); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
164 a["List"].append(c); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
165 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
166 Orthanc::LuaContext lua; |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
167 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
168 // 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
|
169 lua.Execute("function identity(a) return a end"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
170 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
171 { |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
172 Orthanc::LuaFunctionCall f(lua, "identity"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
173 f.PushJson("hello"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
174 Json::Value v; |
1659 | 175 f.ExecuteToJson(v, false); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
176 ASSERT_EQ("hello", v.asString()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
177 } |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
178 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
179 { |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
180 Orthanc::LuaFunctionCall f(lua, "identity"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
181 f.PushJson(42.25); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
182 Json::Value v; |
1659 | 183 f.ExecuteToJson(v, false); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
184 ASSERT_FLOAT_EQ(42.25f, v.asFloat()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
185 } |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
186 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
187 { |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
188 Orthanc::LuaFunctionCall f(lua, "identity"); |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
189 f.PushJson(-42); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
190 Json::Value v; |
1659 | 191 f.ExecuteToJson(v, false); |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
192 ASSERT_EQ(-42, v.asInt()); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
193 } |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
194 |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
195 { |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
196 Orthanc::LuaFunctionCall f(lua, "identity"); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
197 Json::Value vv = Json::arrayValue; |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
198 f.PushJson(vv); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
199 Json::Value v; |
1659 | 200 f.ExecuteToJson(v, false); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
201 ASSERT_EQ(Json::arrayValue, v.type()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
202 } |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
203 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
204 { |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
205 Orthanc::LuaFunctionCall f(lua, "identity"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
206 Json::Value vv = Json::objectValue; |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
207 f.PushJson(vv); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
208 Json::Value v; |
1659 | 209 f.ExecuteToJson(v, false); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
210 // 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
|
211 ASSERT_EQ(Json::arrayValue, v.type()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
212 } |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
213 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
214 { |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
215 Orthanc::LuaFunctionCall f(lua, "identity"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
216 f.PushJson(b); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
217 Json::Value v; |
1659 | 218 f.ExecuteToJson(v, false); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
219 ASSERT_EQ(Json::objectValue, v.type()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
220 ASSERT_FLOAT_EQ(42.0f, v["a"].asFloat()); |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
221 ASSERT_FLOAT_EQ(44.37f, v["b"].asFloat()); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
222 ASSERT_FLOAT_EQ(-43.0f, v["c"].asFloat()); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
223 } |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
224 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
225 { |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
226 Orthanc::LuaFunctionCall f(lua, "identity"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
227 f.PushJson(c); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
228 Json::Value v; |
1659 | 229 f.ExecuteToJson(v, false); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
230 ASSERT_EQ(Json::arrayValue, v.type()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
231 ASSERT_EQ("test3", v[0].asString()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
232 ASSERT_EQ("test1", v[1].asString()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
233 ASSERT_EQ("test2", v[2].asString()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
234 } |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
235 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
236 { |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
237 Orthanc::LuaFunctionCall f(lua, "identity"); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
238 f.PushJson(a); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
239 Json::Value v; |
1659 | 240 f.ExecuteToJson(v, false); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
241 ASSERT_EQ("World", v["Hello"].asString()); |
1659 | 242 ASSERT_EQ(Json::intValue, v["List"][0]["a"].type()); |
243 ASSERT_EQ(Json::realValue, v["List"][0]["b"].type()); | |
244 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
|
245 ASSERT_EQ(42, v["List"][0]["a"].asInt()); |
1659 | 246 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
|
247 ASSERT_EQ(44, v["List"][0]["b"].asInt()); |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
248 ASSERT_EQ(-43, v["List"][0]["c"].asInt()); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
249 ASSERT_EQ("test3", v["List"][1][0].asString()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
250 ASSERT_EQ("test1", v["List"][1][1].asString()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
251 ASSERT_EQ("test2", v["List"][1][2].asString()); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
252 } |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
253 |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
254 { |
1659 | 255 Orthanc::LuaFunctionCall f(lua, "identity"); |
256 f.PushJson(a); | |
257 Json::Value v; | |
258 f.ExecuteToJson(v, true); | |
259 ASSERT_EQ("World", v["Hello"].asString()); | |
260 ASSERT_EQ(Json::stringValue, v["List"][0]["a"].type()); | |
261 ASSERT_EQ(Json::stringValue, v["List"][0]["b"].type()); | |
262 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
|
263 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
|
264 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
|
265 ASSERT_FLOAT_EQ(-43.0f, boost::lexical_cast<float>(v["List"][0]["c"].asString())); |
1659 | 266 ASSERT_EQ("test3", v["List"][1][0].asString()); |
267 ASSERT_EQ("test1", v["List"][1][1].asString()); | |
268 ASSERT_EQ("test2", v["List"][1][2].asString()); | |
269 } | |
270 | |
271 { | |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
272 Orthanc::LuaFunctionCall f(lua, "DumpJson"); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
273 f.PushJson(a); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
274 std::string s; |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
275 f.ExecuteToString(s); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
276 |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
277 Json::FastWriter writer; |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
278 std::string t = writer.write(a); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
279 |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
280 ASSERT_EQ(s, t); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
281 } |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
282 } |
1051 | 283 |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
284 |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1439
diff
changeset
|
285 |
1051 | 286 TEST(Lua, Http) |
287 { | |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
288 Orthanc::LuaContext lua; |
1051 | 289 |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
290 #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
|
291 // The "http://www.orthanc-server.com/downloads/third-party/" does |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
292 // not automatically redirect to HTTPS, so we cas use it even if the |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
293 // 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
|
294 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
|
295 |
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
296 lua.Execute("JSON = loadstring(HttpGet('" + BASE + "JSON.lua')) ()"); |
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
297 const std::string url(BASE + "Product.json"); |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
298 #endif |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
299 |
1051 | 300 std::string s; |
301 lua.Execute(s, "print(HttpGet({}))"); | |
1439 | 302 ASSERT_EQ("nil", Orthanc::Toolbox::StripSpaces(s)); |
1051 | 303 |
304 #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1 | |
305 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
|
306 ASSERT_LE(100, boost::lexical_cast<int>(Orthanc::Toolbox::StripSpaces(s))); |
1051 | 307 |
308 // Parse a JSON file | |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
309 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
|
310 ASSERT_EQ("OrthancClient", Orthanc::Toolbox::StripSpaces(s)); |
1051 | 311 |
1056 | 312 #if 0 |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
313 // 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
|
314 // Orthanc is running on the localhost |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
315 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
316 lua.Execute("modality = {}"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
317 lua.Execute("table.insert(modality, 'ORTHANC')"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
318 lua.Execute("table.insert(modality, 'localhost')"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
319 lua.Execute("table.insert(modality, 4242)"); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
320 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
321 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
|
322 ASSERT_EQ("hello world", Orthanc::Toolbox::StripSpaces(s)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
323 |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
324 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
|
325 ASSERT_EQ("42", Orthanc::Toolbox::StripSpaces(s)); |
1055
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
326 |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
327 // Add/remove a modality with Lua |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
328 Json::Value v; |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
329 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
|
330 ASSERT_EQ(0, Orthanc::Toolbox::StripSpaces(s).size()); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
331 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
|
332 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
|
333 ASSERT_TRUE(v.type() == Json::arrayValue); |
6f923d52a46c
call Web services from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1053
diff
changeset
|
334 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
|
335 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
|
336 ASSERT_EQ(0, Orthanc::Toolbox::StripSpaces(s).size()); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
337 #endif |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
338 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
339 #endif |
1051 | 340 } |