Mercurial > hg > orthanc
comparison UnitTestsSources/Lua.cpp @ 632:17815b9d4280
rename the UnitTests directory to avoid clashes in filenames
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 28 Oct 2013 16:26:51 +0100 |
parents | UnitTests/Lua.cpp@941ea46e9e26 |
children | 9e3f21441903 |
comparison
equal
deleted
inserted
replaced
631:fc6ad5b97219 | 632:17815b9d4280 |
---|---|
1 #include "gtest/gtest.h" | |
2 | |
3 #include "../Core/Lua/LuaFunctionCall.h" | |
4 | |
5 | |
6 TEST(Lua, Simple) | |
7 { | |
8 Orthanc::LuaContext lua; | |
9 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); | |
10 lua.Execute("a={}"); | |
11 lua.Execute("a['x'] = 10"); | |
12 lua.Execute("a['y'] = {}"); | |
13 lua.Execute("a['y'][1] = 20"); | |
14 lua.Execute("a['y'][2] = 20"); | |
15 lua.Execute("PrintRecursive(a)"); | |
16 | |
17 lua.Execute("function f(a) print(a.bool) return a.bool,20,30,40,50,60 end"); | |
18 | |
19 Json::Value v, vv, o; | |
20 //v["a"] = "b"; | |
21 v.append("hello"); | |
22 v.append("world"); | |
23 v.append("42"); | |
24 vv.append("sub"); | |
25 vv.append("set"); | |
26 v.append(vv); | |
27 o = Json::objectValue; | |
28 o["x"] = 10; | |
29 o["y"] = 20; | |
30 o["z"] = 20.5f; | |
31 v.append(o); | |
32 | |
33 { | |
34 Orthanc::LuaFunctionCall f(lua, "PrintRecursive"); | |
35 f.PushJSON(v); | |
36 f.Execute(); | |
37 } | |
38 | |
39 { | |
40 Orthanc::LuaFunctionCall f(lua, "f"); | |
41 f.PushJSON(o); | |
42 ASSERT_THROW(f.ExecutePredicate(), Orthanc::LuaException); | |
43 } | |
44 | |
45 o["bool"] = false; | |
46 | |
47 { | |
48 Orthanc::LuaFunctionCall f(lua, "f"); | |
49 f.PushJSON(o); | |
50 ASSERT_FALSE(f.ExecutePredicate()); | |
51 } | |
52 | |
53 o["bool"] = true; | |
54 | |
55 { | |
56 Orthanc::LuaFunctionCall f(lua, "f"); | |
57 f.PushJSON(o); | |
58 ASSERT_TRUE(f.ExecutePredicate()); | |
59 } | |
60 } | |
61 | |
62 | |
63 TEST(Lua, Existing) | |
64 { | |
65 Orthanc::LuaContext lua; | |
66 lua.Execute("a={}"); | |
67 lua.Execute("function f() end"); | |
68 | |
69 ASSERT_TRUE(lua.IsExistingFunction("f")); | |
70 ASSERT_FALSE(lua.IsExistingFunction("a")); | |
71 ASSERT_FALSE(lua.IsExistingFunction("Dummy")); | |
72 } |