annotate UnitTestsSources/LuaTests.cpp @ 967:dfc076546821

add suffix Tests to unit test sources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Jun 2014 15:36:38 +0200
parents UnitTestsSources/Lua.cpp@84513f2ee1f3
children 1b1d51e9f1a2
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
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
4 * Belgium
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
5 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
6 * 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
7 * 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
8 * 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
9 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
10 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
11 * 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
12 * 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
13 * 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
14 * 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
15 * 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
16 * 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
17 * 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
18 * 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
19 * 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
20 * 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
21 * in the program, then also delete it here.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
22 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
23 * 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
24 * 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
25 * 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
26 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
27 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
28 * 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
29 * 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
30 **/
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
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 827
diff changeset
33 #include "PrecompiledHeadersUnitTests.h"
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "gtest/gtest.h"
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../Core/Lua/LuaFunctionCall.h"
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
39 TEST(Lua, Json)
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
41 Orthanc::LuaContext lua;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
42 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
43 lua.Execute("a={}");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
44 lua.Execute("a['x'] = 10");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
45 lua.Execute("a['y'] = {}");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
46 lua.Execute("a['y'][1] = 20");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
47 lua.Execute("a['y'][2] = 20");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
48 lua.Execute("PrintRecursive(a)");
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
50 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
51
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
52 Json::Value v, vv, o;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
53 //v["a"] = "b";
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
54 v.append("hello");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
55 v.append("world");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
56 v.append("42");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
57 vv.append("sub");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
58 vv.append("set");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
59 v.append(vv);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
60 o = Json::objectValue;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
61 o["x"] = 10;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
62 o["y"] = 20;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
63 o["z"] = 20.5f;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
64 v.append(o);
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
66 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
67 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
68 f.PushJSON(v);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
69 f.Execute();
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
70 }
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
72 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
73 Orthanc::LuaFunctionCall f(lua, "f");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
74 f.PushJSON(o);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
75 ASSERT_THROW(f.ExecutePredicate(), Orthanc::LuaException);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
76 }
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
78 o["bool"] = false;
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
80 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
81 Orthanc::LuaFunctionCall f(lua, "f");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
82 f.PushJSON(o);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
83 ASSERT_FALSE(f.ExecutePredicate());
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
84 }
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
86 o["bool"] = true;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
87
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
89 Orthanc::LuaFunctionCall f(lua, "f");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
90 f.PushJSON(o);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
91 ASSERT_TRUE(f.ExecutePredicate());
386
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
7dec4f3c922c lua wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
94
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
95
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
96 TEST(Lua, Existing)
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::LuaContext lua;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
99 lua.Execute("a={}");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
100 lua.Execute("function f() end");
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
101
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
102 ASSERT_TRUE(lua.IsExistingFunction("f"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
103 ASSERT_FALSE(lua.IsExistingFunction("a"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
104 ASSERT_FALSE(lua.IsExistingFunction("Dummy"));
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
105 }
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
106
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
107
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
108 TEST(Lua, Simple)
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 Orthanc::LuaContext lua;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
111 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
112
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
113 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
114 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
115 f.PushString("hello");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
116 f.Execute();
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
117 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
118
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
119 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
120 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
121 f.PushBoolean(true);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
122 f.Execute();
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
123 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
124
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
125 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
126 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
127 f.PushInteger(42);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
128 f.Execute();
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
129 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
130
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
131 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
132 Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
133 f.PushDouble(3.1415);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
134 f.Execute();
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
135 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
136 }