annotate UnitTestsSources/PlustacheTests.cpp @ 1072:1dffa9f44a94

conformance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 Jul 2014 13:31:35 +0200
parents a93867a94011
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1024
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
1 /**
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
4 * Belgium
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
5 *
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
6 * This program is free software: you can redistribute it and/or
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
7 * modify it under the terms of the GNU General Public License as
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
9 * License, or (at your option) any later version.
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
10 *
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
11 * In addition, as a special exception, the copyright holders of this
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
12 * program give permission to link the code of its release with the
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
15 * the linked executables. You must obey the GNU General Public License
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
19 * you do not wish to do so, delete this exception statement from your
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
20 * version. If you delete this exception statement from all source files
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
21 * in the program, then also delete it here.
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
22 *
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
23 * This program is distributed in the hope that it will be useful, but
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
26 * General Public License for more details.
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
27 *
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
28 * You should have received a copy of the GNU General Public License
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
30 **/
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
31
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
32
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
33 #include "PrecompiledHeadersUnitTests.h"
823
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "gtest/gtest.h"
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1024
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
36 #if ORTHANC_PLUSTACHE_ENABLED == 1
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
37
823
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <include/template.hpp>
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
825
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
40 class OrthancPlustache : public Plustache::template_t
823
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
825
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
42 public:
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
43 protected:
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
44 virtual std::string get_template(const std::string& tmpl)
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
45 {
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
46 //printf("OK [%s]\n", tmpl.c_str());
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
47 return Plustache::template_t::get_template(tmpl);
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
48 }
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
49
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
50 virtual std::string get_partial(const std::string& partial) const
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
51 {
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
52 //printf("OK2 [%s]\n", partial.c_str());
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
53 //return Plustache::template_t::get_partial(partial);
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
54 return "<li>{{name}}</li>";
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
55 }
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
56 };
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
57
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
58
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
59 TEST(Plustache, Basic1)
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
60 {
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
61 PlustacheTypes::ObjectType ctx;
823
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 ctx["title"] = "About";
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
825
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
64 OrthancPlustache t;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
65 ASSERT_EQ("<h1>About</h1>", t.render("<h1>{{title}}</h1>", ctx));
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
66 }
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
67
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
68
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
69 TEST(Plustache, Basic2)
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
70 {
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
71 Plustache::Context ctx;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
72 ctx.add("title", "About");
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
73
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
74 OrthancPlustache t;
823
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ASSERT_EQ("<h1>About</h1>", t.render("<h1>{{title}}</h1>", ctx));
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
da4c30a8bcdd plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
825
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
78
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
79 TEST(Plustache, Context)
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
80 {
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
81 PlustacheTypes::ObjectType a;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
82 a["name"] = "Orthanc";
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
83
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
84 PlustacheTypes::ObjectType b;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
85 b["name"] = "Jodogne";
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
86
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
87 PlustacheTypes::CollectionType c;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
88 c.push_back(a);
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
89 c.push_back(b);
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
90
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
91 Plustache::Context ctx;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
92 ctx.add("items", c);
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
93
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
94 OrthancPlustache t;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
95 ASSERT_EQ("<ul><li>Orthanc</li><li>Jodogne</li></ul>",
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
96 t.render("<ul>{{#items}}<li>{{name}}</li>{{/items}}</ul>", ctx));
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
97 }
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
98
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
99
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
100 TEST(Plustache, Partials)
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
101 {
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
102 PlustacheTypes::ObjectType a;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
103 a["name"] = "Orthanc";
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
104
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
105 PlustacheTypes::ObjectType b;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
106 b["name"] = "Jodogne";
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
107
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
108 PlustacheTypes::CollectionType c;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
109 c.push_back(a);
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
110 c.push_back(b);
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
111
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
112 Plustache::Context ctx;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
113 ctx.add("items", c);
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
114
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
115 OrthancPlustache t;
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
116 ASSERT_EQ("<ul><li>Orthanc</li><li>Jodogne</li></ul>",
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
117 t.render("<ul>{{#items}}{{>partial}}{{/items}}</ul>", ctx));
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
118 }
d8f5de5b9517 partials
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 823
diff changeset
119
1024
a93867a94011 smoother integration of plustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 825
diff changeset
120 #endif