Mercurial > hg > orthanc
annotate UnitTestsSources/Lua.cpp @ 727:52b5316a2517
disable test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 19 Feb 2014 12:43:12 +0100 |
parents | 9e3f21441903 |
children | 3d6f9b7d0add |
rev | line source |
---|---|
386 | 1 #include "gtest/gtest.h" |
2 | |
3 #include "../Core/Lua/LuaFunctionCall.h" | |
4 | |
5 | |
712 | 6 TEST(Lua, Json) |
386 | 7 { |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
8 Orthanc::LuaContext lua; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
9 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
10 lua.Execute("a={}"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
11 lua.Execute("a['x'] = 10"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
12 lua.Execute("a['y'] = {}"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
13 lua.Execute("a['y'][1] = 20"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
14 lua.Execute("a['y'][2] = 20"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
15 lua.Execute("PrintRecursive(a)"); |
386 | 16 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
17 lua.Execute("function f(a) print(a.bool) return a.bool,20,30,40,50,60 end"); |
386 | 18 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
19 Json::Value v, vv, o; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
20 //v["a"] = "b"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
21 v.append("hello"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
22 v.append("world"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
23 v.append("42"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
24 vv.append("sub"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
25 vv.append("set"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
26 v.append(vv); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
27 o = Json::objectValue; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
28 o["x"] = 10; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
29 o["y"] = 20; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
30 o["z"] = 20.5f; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
31 v.append(o); |
386 | 32 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
33 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
34 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
35 f.PushJSON(v); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
36 f.Execute(); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
37 } |
386 | 38 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
39 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
40 Orthanc::LuaFunctionCall f(lua, "f"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
41 f.PushJSON(o); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
42 ASSERT_THROW(f.ExecutePredicate(), Orthanc::LuaException); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
43 } |
386 | 44 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
45 o["bool"] = false; |
386 | 46 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
47 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
48 Orthanc::LuaFunctionCall f(lua, "f"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
49 f.PushJSON(o); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
50 ASSERT_FALSE(f.ExecutePredicate()); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
51 } |
386 | 52 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
53 o["bool"] = true; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
54 |
386 | 55 { |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
56 Orthanc::LuaFunctionCall f(lua, "f"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
57 f.PushJSON(o); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
58 ASSERT_TRUE(f.ExecutePredicate()); |
386 | 59 } |
60 } | |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
61 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
62 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
63 TEST(Lua, Existing) |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
64 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
65 Orthanc::LuaContext lua; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
66 lua.Execute("a={}"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
67 lua.Execute("function f() end"); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
68 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
69 ASSERT_TRUE(lua.IsExistingFunction("f")); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
70 ASSERT_FALSE(lua.IsExistingFunction("a")); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
71 ASSERT_FALSE(lua.IsExistingFunction("Dummy")); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
386
diff
changeset
|
72 } |
712 | 73 |
74 | |
75 TEST(Lua, Simple) | |
76 { | |
77 Orthanc::LuaContext lua; | |
78 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); | |
79 | |
80 { | |
81 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
82 f.PushString("hello"); | |
83 f.Execute(); | |
84 } | |
85 | |
86 { | |
87 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
88 f.PushBoolean(true); | |
89 f.Execute(); | |
90 } | |
91 | |
92 { | |
93 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
94 f.PushInteger(42); | |
95 f.Execute(); | |
96 } | |
97 | |
98 { | |
99 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
100 f.PushDouble(3.1415); | |
101 f.Execute(); | |
102 } | |
103 } |