|
ferencd@0
|
1 #include "gtest/gtest.h"
|
|
ferencd@0
|
2 #include "templater.h"
|
|
ferencd@0
|
3 #include <url_breaker.h>
|
|
ferencd@0
|
4 #include <cppdb.h>
|
|
ferencd@0
|
5 #include <time.h>
|
|
ferencd@0
|
6
|
|
ferencd@0
|
7 #include <common.h>
|
|
ferencd@0
|
8 #include <cppdb/cppdb.h>
|
|
ferencd@0
|
9 #include <tnt/httprequest.h>
|
|
ferencd@0
|
10 #include <tnt/httpreply.h>
|
|
ferencd@0
|
11 #include <tnt/tntnet.h>
|
|
ferencd@0
|
12
|
|
ferencd@0
|
13 #include <string>
|
|
ferencd@0
|
14
|
|
ferencd@0
|
15 TEST(StringTemplate,DISABLED_IncludeRootData)
|
|
ferencd@0
|
16 {
|
|
ferencd@0
|
17
|
|
ferencd@0
|
18 STRING_TEMPLATE(RootRequiredIncluded, "Testing {#str}");
|
|
ferencd@0
|
19 STRING_TEMPLATE(RootProviderIncTestStuff, "Testing <!--#include RootRequiredIncluded#-->");
|
|
ferencd@0
|
20
|
|
ferencd@0
|
21 std::string tf = templater<RootProviderIncTestStuff>().templatize("str" <is> 123 ).get();
|
|
ferencd@0
|
22
|
|
ferencd@0
|
23 ASSERT_STREQ(tf.c_str(), "Testing Testing 123");
|
|
ferencd@0
|
24 }
|
|
ferencd@0
|
25
|
|
ferencd@0
|
26 TEST(StringTemplate,DISABLED_IfEq)
|
|
ferencd@0
|
27 {
|
|
ferencd@0
|
28 STRING_TEMPLATE(IfElseStuff, "Testing<!--#eq {#str},blabla#-->blaa<!--#endeq#-->123");
|
|
ferencd@0
|
29 template_par<std::string> a("str", "blabla");
|
|
ferencd@0
|
30 std::string tf = templater<IfElseStuff>().templatize(a).get();
|
|
ferencd@0
|
31
|
|
ferencd@0
|
32 ASSERT_STREQ(tf.c_str(), "Testingblaa123");
|
|
ferencd@0
|
33 }
|
|
ferencd@0
|
34
|
|
ferencd@0
|
35 TEST(StringTemplate,DISABLED_ErrorSetter)
|
|
ferencd@0
|
36 {
|
|
ferencd@0
|
37 STRING_TEMPLATE(ErrorSetterTemplateTest, "Testing {#str}");
|
|
ferencd@0
|
38 auto t = templater<ErrorSetterTemplateTest>();
|
|
ferencd@0
|
39 t.set_error("Error", 123, ".");
|
|
ferencd@0
|
40 std::string err = t.get_error();
|
|
ferencd@0
|
41 ASSERT_STREQ("Error 123 .\n", err.c_str());
|
|
ferencd@0
|
42 }
|
|
ferencd@0
|
43
|
|
ferencd@0
|
44
|
|
ferencd@0
|
45 TEST(StringTemplate, DISABLED_TranslateIndependentString)
|
|
ferencd@0
|
46 {
|
|
ferencd@0
|
47 std::string s = "he<!--#translate language#-->oh";
|
|
ferencd@0
|
48 std::map<std::string, std::map<std::string, std::string> > translations;
|
|
ferencd@0
|
49 std::string translated = translator<void>::translate(s, "hu", translations);
|
|
ferencd@0
|
50 ASSERT_STREQ("henyelvoh", translated.c_str());
|
|
ferencd@0
|
51 }
|
|
ferencd@0
|
52
|
|
ferencd@0
|
53 TEST(StringTemplate, DISABLED_Translate)
|
|
ferencd@0
|
54 {
|
|
ferencd@0
|
55 STRING_TEMPLATE(ToTranslateTest, "he<!--#translate language#-->oh");
|
|
ferencd@0
|
56 std::string translated = translator<ToTranslateTest>().translate("hu");
|
|
ferencd@0
|
57 ASSERT_STREQ("henyelvoh", translated.c_str());
|
|
ferencd@0
|
58 }
|
|
ferencd@0
|
59
|
|
ferencd@0
|
60 TEST(StringTemplate, DISABLED_TranslateVar)
|
|
ferencd@0
|
61 {
|
|
ferencd@0
|
62 STRING_TEMPLATE(ToTranslateVarTest, "he<!--#translate {#str}#-->oh");
|
|
ferencd@0
|
63 std::string translated = translator<ToTranslateVarTest>().templatize("str" <is> "language").set().translate("hu");
|
|
ferencd@0
|
64 ASSERT_STREQ("he<span id='span_language'></span>oh", translated.c_str());
|
|
ferencd@0
|
65 }
|
|
ferencd@0
|
66
|
|
ferencd@0
|
67 TEST(StringTemplate, DISABLED_TranslatePythonOutput)
|
|
ferencd@0
|
68 {
|
|
ferencd@0
|
69 STRING_TEMPLATE(ToTranslateVarTest, "he<!--#translate <!--#init-script python#-->print('language')<!--#endscript#-->#-->oh");
|
|
ferencd@0
|
70 std::string translated = translator<ToTranslateVarTest>().templatize("str" <is> "language").set().translate("hu");
|
|
ferencd@0
|
71 ASSERT_STREQ("he<span id='span_language'></span>oh", translated.c_str());
|
|
ferencd@0
|
72 }
|
|
ferencd@0
|
73
|
|
ferencd@0
|
74 #include <tntdb.h>
|
|
ferencd@0
|
75
|
|
ferencd@0
|
76 TEST(StringTemplate, DISABLED_FoodFromDb)
|
|
ferencd@0
|
77 {
|
|
ferencd@0
|
78
|
|
ferencd@0
|
79 std::vector<template_struct> structs;
|
|
ferencd@0
|
80
|
|
ferencd@0
|
81 try {
|
|
ferencd@0
|
82 tntdb::Connection conn = tntdb::connect("sqlite:lang.db");
|
|
ferencd@0
|
83
|
|
ferencd@0
|
84 // TODO: prepared statement
|
|
ferencd@0
|
85
|
|
ferencd@0
|
86 std::string v = std::string("select * from food where type='") + "0" + "'";
|
|
ferencd@0
|
87 tntdb::Result result = conn.select(v);
|
|
ferencd@0
|
88 for (tntdb::Result::const_iterator it = result.begin(); it != result.end(); ++it)
|
|
ferencd@0
|
89 {
|
|
ferencd@0
|
90 std::string name_src = "";
|
|
ferencd@0
|
91 std::string img = "";
|
|
ferencd@0
|
92 std::string desc = "";
|
|
ferencd@0
|
93 int food_idx = -1;
|
|
ferencd@0
|
94 std::string type;
|
|
ferencd@0
|
95
|
|
ferencd@0
|
96 tntdb::Row row = *it;
|
|
ferencd@0
|
97
|
|
ferencd@0
|
98 row[0].get(food_idx);
|
|
ferencd@0
|
99 row[1].get(name_src);
|
|
ferencd@0
|
100 row[2].get(type);
|
|
ferencd@0
|
101 row[3].get(img);
|
|
ferencd@0
|
102 row[4].get(desc);
|
|
ferencd@0
|
103
|
|
ferencd@0
|
104 template_struct food("foods", "fooditem");
|
|
ferencd@0
|
105
|
|
ferencd@0
|
106 food["name"] = name_src;
|
|
ferencd@0
|
107 food["img"] = img;
|
|
ferencd@0
|
108 food["desc"] = desc;
|
|
ferencd@0
|
109
|
|
ferencd@0
|
110 structs.push_back(food);
|
|
ferencd@0
|
111 }
|
|
ferencd@0
|
112 }
|
|
ferencd@0
|
113 catch (std::exception& ex)
|
|
ferencd@0
|
114 {
|
|
ferencd@0
|
115 std::cerr << ex.what();
|
|
ferencd@0
|
116 }
|
|
ferencd@0
|
117
|
|
ferencd@0
|
118 STRING_TEMPLATE(ItSimpleStructTemplate, "<!--#struct fooditem(name,desc,img)#-->"
|
|
ferencd@0
|
119 "<!--#parameters foods:fooditem[]#-->"
|
|
ferencd@0
|
120 "Testing"
|
|
ferencd@0
|
121 "<!--#loop foods#-->"
|
|
ferencd@0
|
122 "{#foods.name}/{#foods.desc}/{#foods.img}"
|
|
ferencd@0
|
123 "<!--#endloop foods#-->");
|
|
ferencd@0
|
124
|
|
ferencd@0
|
125 template_vector_par tvp("foods", structs);
|
|
ferencd@0
|
126
|
|
ferencd@0
|
127 std::string s = templater<ItSimpleStructTemplate>().templatize(
|
|
ferencd@0
|
128 tvp
|
|
ferencd@0
|
129 ).get();
|
|
ferencd@0
|
130
|
|
ferencd@0
|
131 ASSERT_STREQ(s.c_str(), "Testing12");
|
|
ferencd@0
|
132
|
|
ferencd@0
|
133
|
|
ferencd@0
|
134 }
|
|
ferencd@0
|
135
|
|
ferencd@0
|
136
|
|
ferencd@0
|
137 TEST(StringTemplate, DISABLED_InitScript)
|
|
ferencd@0
|
138 {
|
|
ferencd@0
|
139 STRING_TEMPLATE(ScriptStuff, "Testing<!--#init-script python#-->"
|
|
ferencd@0
|
140 "def fun(s, c):\n"
|
|
ferencd@0
|
141 "\treturn s * c\n\n"
|
|
ferencd@0
|
142 "print(fun(str, 3))\n"
|
|
ferencd@0
|
143 "<!--#endscript#-->");
|
|
ferencd@0
|
144 template_par<std::string> a("str", "A");
|
|
ferencd@0
|
145 std::string tf = templater<ScriptStuff>().templatize(a).get();
|
|
ferencd@0
|
146
|
|
ferencd@0
|
147 ASSERT_STREQ(tf.c_str(), "TestingAAA");
|
|
ferencd@0
|
148 }
|
|
ferencd@0
|
149
|
|
ferencd@0
|
150 TEST(StringTemplate, DISABLED_InitScriptAndStandardScript)
|
|
ferencd@0
|
151 {
|
|
ferencd@0
|
152 STRING_TEMPLATE(ScriptStuff2Scripts, "Testing<!--#init-script python#-->"
|
|
ferencd@0
|
153 "def fun(s, c):\n"
|
|
ferencd@0
|
154 "\treturn s * c\n\n"
|
|
ferencd@0
|
155 "print(fun(str, 3))\n"
|
|
ferencd@0
|
156 "<!--#endscript#-->"
|
|
ferencd@0
|
157 "<!--#script python#-->"
|
|
ferencd@0
|
158 "def fun(s, c):\n"
|
|
ferencd@0
|
159 "\treturn s * c\n\n"
|
|
ferencd@0
|
160 "print(fun(str2, 3))\n"
|
|
ferencd@0
|
161 "<!--#endscript#-->");
|
|
ferencd@0
|
162 template_par<std::string> a("str", "C");
|
|
ferencd@0
|
163 template_par<std::string> b("str2", "D");
|
|
ferencd@0
|
164 std::string tf = templater<ScriptStuff2Scripts>().templatize(a,b).get();
|
|
ferencd@0
|
165
|
|
ferencd@0
|
166 ASSERT_STREQ(tf.c_str(), "TestingCCCDDD");
|
|
ferencd@0
|
167 }
|
|
ferencd@0
|
168
|
|
ferencd@0
|
169
|
|
ferencd@0
|
170 TEST(StringTemplate, DISABLED_InitScriptSetsVariables)
|
|
ferencd@0
|
171 {
|
|
ferencd@0
|
172 STRING_TEMPLATE(ScriptStuffSetsVar, "Testing{#str}<!--#init-script python#-->"
|
|
ferencd@0
|
173 "str='B'\n"
|
|
ferencd@0
|
174 "<!--#endscript#-->");
|
|
ferencd@0
|
175 template_par<std::string> a("str", "A");
|
|
ferencd@0
|
176 std::string tf = templater<ScriptStuffSetsVar>().templatize(a).get();
|
|
ferencd@0
|
177
|
|
ferencd@0
|
178 ASSERT_STREQ(tf.c_str(), "TestingB");
|
|
ferencd@0
|
179 }
|
|
ferencd@0
|
180
|
|
ferencd@0
|
181 TEST(StringTemplate,DISABLED_IfElse)
|
|
ferencd@0
|
182 {
|
|
ferencd@0
|
183 STRING_TEMPLATE(IfElseStuff, "<!--#define blaa#-->Testing<!--#if blaa#-->blaa<!--#else#-->{#str}<!--#endif blaa#-->123");
|
|
ferencd@0
|
184 template_par<std::string> a("str", "blabla");
|
|
ferencd@0
|
185 std::string tf = templater<IfElseStuff>().templatize(a).get();
|
|
ferencd@0
|
186
|
|
ferencd@0
|
187 ASSERT_STREQ(tf.c_str(), "Testingblaa123");
|
|
ferencd@0
|
188 }
|
|
ferencd@0
|
189
|
|
ferencd@0
|
190 TEST(StringTemplate,DISABLED_Defines)
|
|
ferencd@0
|
191 {
|
|
ferencd@0
|
192 STRING_TEMPLATE(DefineStuff, "<!--#define blaa#--><!--#if blaa#-->Testing {#str}<!--#endif blaa#-->");
|
|
ferencd@0
|
193 template_par<std::string> a("str", "blabla");
|
|
ferencd@0
|
194 std::string tf = templater<DefineStuff>().templatize(a).get();
|
|
ferencd@0
|
195
|
|
ferencd@0
|
196 ASSERT_STREQ(tf.c_str(), "Testing blabla");
|
|
ferencd@0
|
197 }
|
|
ferencd@0
|
198
|
|
ferencd@0
|
199 TEST(StringTemplate,DISABLED_NotSoDefines)
|
|
ferencd@0
|
200 {
|
|
ferencd@0
|
201 STRING_TEMPLATE(NotSoDefines, "<!--#define not_blaa#--><!--#if blaa#-->Testing {#str}<!--#endif blaa#-->");
|
|
ferencd@0
|
202 template_par<std::string> a("str", "blabla");
|
|
ferencd@0
|
203 std::string tf = templater<NotSoDefines>().templatize(a).get();
|
|
ferencd@0
|
204
|
|
ferencd@0
|
205 ASSERT_STREQ(tf.c_str(), "");
|
|
ferencd@0
|
206 }
|
|
ferencd@0
|
207
|
|
ferencd@0
|
208 TEST(StringTemplate,DISABLED_ValueDefines)
|
|
ferencd@0
|
209 {
|
|
ferencd@0
|
210 STRING_TEMPLATE(ValueDefines, "<!--#define blaa=bluu#-->Testing {#blaa}{#str}");
|
|
ferencd@0
|
211 template_par<std::string> a("str", "blabla");
|
|
ferencd@0
|
212 std::string tf = templater<ValueDefines>().templatize(a).get();
|
|
ferencd@0
|
213
|
|
ferencd@0
|
214 ASSERT_STREQ(tf.c_str(), "Testing bluublabla");
|
|
ferencd@0
|
215 }
|
|
ferencd@0
|
216
|
|
ferencd@0
|
217 TEST(StringTemplate,DISABLED_IfTest)
|
|
ferencd@0
|
218 {
|
|
ferencd@0
|
219 STRING_TEMPLATE(IfTestStuff, "Testing<!--#if str#-->:This is {#str}<!--#endif str#-->");
|
|
ferencd@0
|
220 template_par<std::string> a("str", "blabla");
|
|
ferencd@0
|
221 std::string tf = templater<IfTestStuff>().templatize(a).get();
|
|
ferencd@0
|
222 ASSERT_STREQ(tf.c_str(), "Testing:This is blabla");
|
|
ferencd@0
|
223
|
|
ferencd@0
|
224 template_par<std::string> b("str", "");
|
|
ferencd@0
|
225 std::string no_par = templater<IfTestStuff>().templatize(b).get();
|
|
ferencd@0
|
226 ASSERT_STREQ(no_par.c_str(), "Testing");
|
|
ferencd@0
|
227 }
|
|
ferencd@0
|
228
|
|
ferencd@0
|
229 TEST(StringTemplate,DISABLED_SimpleString)
|
|
ferencd@0
|
230 {
|
|
ferencd@0
|
231 STRING_TEMPLATE(TestStuff, "Testing {#str}");
|
|
ferencd@0
|
232
|
|
ferencd@0
|
233 template_par<std::string> a("str", "blabla");
|
|
ferencd@0
|
234 std::string tf = templater<TestStuff>().templatize(a).get();
|
|
ferencd@0
|
235
|
|
ferencd@0
|
236 ASSERT_STREQ(tf.c_str(), "Testing blabla");
|
|
ferencd@0
|
237 }
|
|
ferencd@0
|
238
|
|
ferencd@0
|
239 TEST(StringTemplate,DISABLED_SimpleNumber)
|
|
ferencd@0
|
240 {
|
|
ferencd@0
|
241 STRING_TEMPLATE(NumberTestStuff, "Testing {#str}");
|
|
ferencd@0
|
242
|
|
ferencd@0
|
243 auto x = "str" <is> 42;
|
|
ferencd@0
|
244
|
|
ferencd@0
|
245 std::string tf = templater<NumberTestStuff>().templatize(x).get();
|
|
ferencd@0
|
246
|
|
ferencd@0
|
247 ASSERT_STREQ(tf.c_str(), "Testing 42");
|
|
ferencd@0
|
248 }
|
|
ferencd@0
|
249
|
|
ferencd@0
|
250 TEST(StringTemplate,DISABLED_SimpleInclusion)
|
|
ferencd@0
|
251 {
|
|
ferencd@0
|
252 STRING_TEMPLATE(TestIncluded, "Testing {#str}");
|
|
ferencd@0
|
253 STRING_TEMPLATE(IncTestStuff, "Testing <!--#include TestIncluded(str=\"blaa\")#-->");
|
|
ferencd@0
|
254
|
|
ferencd@0
|
255 std::string tf = templater<IncTestStuff>().templatize().get();
|
|
ferencd@0
|
256
|
|
ferencd@0
|
257 ASSERT_STREQ(tf.c_str(), "Testing Testing blaa");
|
|
ferencd@0
|
258 }
|
|
ferencd@0
|
259
|
|
ferencd@0
|
260 TEST(StringTemplate,DISABLED_SimpleVariables)
|
|
ferencd@0
|
261 {
|
|
ferencd@0
|
262 STRING_TEMPLATE(TestVariables, "Testing {#str}{#str2}");
|
|
ferencd@0
|
263
|
|
ferencd@0
|
264 auto vars = templater<TestVariables>().variables(false);
|
|
ferencd@0
|
265
|
|
ferencd@0
|
266 ASSERT_STREQ(vars[0].c_str(), "str");
|
|
ferencd@0
|
267 ASSERT_STREQ(vars[1].c_str(), "str2");
|
|
ferencd@0
|
268 }
|
|
ferencd@0
|
269
|
|
ferencd@0
|
270 TEST(StringTemplate,DISABLED_IncludedVariables)
|
|
ferencd@0
|
271 {
|
|
ferencd@0
|
272 STRING_TEMPLATE(TestIncludedVariables, "Testing {#str}");
|
|
ferencd@0
|
273 STRING_TEMPLATE(TestVariableIncluder, "Testing <!--#include TestIncludedVariables#-->{#str2}");
|
|
ferencd@0
|
274
|
|
ferencd@0
|
275 auto vars = templater<TestVariableIncluder>().variables(true);
|
|
ferencd@0
|
276
|
|
ferencd@0
|
277 ASSERT_STREQ(vars[0].c_str(), "str");
|
|
ferencd@0
|
278 ASSERT_STREQ(vars[1].c_str(), "str2");
|
|
ferencd@0
|
279 }
|
|
ferencd@0
|
280
|
|
ferencd@0
|
281 TEST(StringTemplate,DISABLED_SimpleInclusionErroneous)
|
|
ferencd@0
|
282 {
|
|
ferencd@0
|
283 STRING_TEMPLATE(TestIncluded1, "Testing {#str}");
|
|
ferencd@0
|
284 STRING_TEMPLATE(IncTestStuff1, "Testing <!--#include TestIncluded(str=\"blaa)#-->");
|
|
ferencd@0
|
285
|
|
ferencd@0
|
286 std::string tf = templater<IncTestStuff1>().templatize().get();
|
|
ferencd@0
|
287
|
|
ferencd@0
|
288 ASSERT_STREQ(tf.c_str(), "Testing Testing blaa)#-->");
|
|
ferencd@0
|
289 }
|
|
ferencd@0
|
290
|
|
ferencd@0
|
291 TEST(StringTemplate,DISABLED_SimpleInclusion2)
|
|
ferencd@0
|
292 {
|
|
ferencd@0
|
293 STRING_TEMPLATE(TestIncluded2, "Testing");
|
|
ferencd@0
|
294 STRING_TEMPLATE(IncTestStuff2, "Testing <!--#include TestIncluded2#-->More");
|
|
ferencd@0
|
295
|
|
ferencd@0
|
296 std::string tf = templater<IncTestStuff2>().templatize().get();
|
|
ferencd@0
|
297
|
|
ferencd@0
|
298 ASSERT_STREQ(tf.c_str(), "Testing TestingMore");
|
|
ferencd@0
|
299 }
|
|
ferencd@0
|
300
|
|
ferencd@0
|
301 TEST(StringTemplate,DISABLED_DoubleInclusion)
|
|
ferencd@0
|
302 {
|
|
ferencd@0
|
303 STRING_TEMPLATE(DoubleTestIncluded, "Testing {#str}");
|
|
ferencd@0
|
304 STRING_TEMPLATE(DoubleIncTestStuff, "Testing <!--#include TestIncluded(str=\"blaa\")#--><!--#include TestIncluded(str=\"blee\")#-->");
|
|
ferencd@0
|
305
|
|
ferencd@0
|
306 std::string tf = templater<DoubleIncTestStuff>().templatize().get();
|
|
ferencd@0
|
307
|
|
ferencd@0
|
308 ASSERT_STREQ(tf.c_str(), "Testing Testing blaaTesting blee");
|
|
ferencd@0
|
309 }
|
|
ferencd@0
|
310
|
|
ferencd@0
|
311 TEST(StringTemplate,DISABLED_SimpleInclusionWithVariable)
|
|
ferencd@0
|
312 {
|
|
ferencd@0
|
313 STRING_TEMPLATE(VarTestIncluded, "<!--#parameters st#-->Testing {#str}");
|
|
ferencd@0
|
314 STRING_TEMPLATE(VarTestStuff, "Testing <!--#include TestIncluded(str:{#more_str})#-->");
|
|
ferencd@0
|
315
|
|
ferencd@0
|
316 template_par<std::string> a("more_str", "blabla");
|
|
ferencd@0
|
317 std::string tf = templater<VarTestStuff>().templatize(a).get();
|
|
ferencd@0
|
318
|
|
ferencd@0
|
319 ASSERT_STREQ(tf.c_str(), "Testing Testing blabla");
|
|
ferencd@0
|
320 }
|
|
ferencd@0
|
321
|
|
ferencd@0
|
322 TEST(StringTemplate, DISABLED_SimpleStruct)
|
|
ferencd@0
|
323 {
|
|
ferencd@0
|
324 STRING_TEMPLATE(SimpleStructTemplate, "<!--#struct simple_pair(a,b)#-->"
|
|
ferencd@0
|
325 "<!--#parameters st:simple_pair#-->"
|
|
ferencd@0
|
326 "Testing {#st.a}{#st.b}");
|
|
ferencd@0
|
327 template_struct st("st", "simple_pair");
|
|
ferencd@0
|
328 st["a"] = "A";
|
|
ferencd@0
|
329 st["b"] = "B";
|
|
ferencd@0
|
330 std::string s = templater<SimpleStructTemplate>().templatize(st).get();
|
|
ferencd@0
|
331
|
|
ferencd@0
|
332 ASSERT_STREQ(s.c_str(), "Testing AB");
|
|
ferencd@0
|
333 }
|
|
ferencd@0
|
334
|
|
ferencd@0
|
335
|
|
ferencd@0
|
336 TEST(StringTemplate,DISABLED_SimpleStructAndVar)
|
|
ferencd@0
|
337 {
|
|
ferencd@0
|
338 STRING_TEMPLATE(VarSimpleStructTemplate, "<!--#struct simple_pair(a,b)#-->"
|
|
ferencd@0
|
339 "<!--#parameters st:simple_pair#-->"
|
|
ferencd@0
|
340 "Testing {#st.a}{#st.b}{#x}");
|
|
ferencd@0
|
341 template_struct st("st", "simple_pair");
|
|
ferencd@0
|
342 st["a"] = "A";
|
|
ferencd@0
|
343 st["b"] = "B";
|
|
ferencd@0
|
344 std::string s = templater<VarSimpleStructTemplate>().templatize(
|
|
ferencd@0
|
345 st,
|
|
ferencd@0
|
346 "x" <is> 42
|
|
ferencd@0
|
347 ).get();
|
|
ferencd@0
|
348
|
|
ferencd@0
|
349 ASSERT_STREQ(s.c_str(), "Testing AB42");
|
|
ferencd@0
|
350 }
|
|
ferencd@0
|
351
|
|
ferencd@0
|
352
|
|
ferencd@0
|
353 TEST(StringTemplate,DISABLED_VarAndSimpleStruct)
|
|
ferencd@0
|
354 {
|
|
ferencd@0
|
355 STRING_TEMPLATE(VarAndSimpleStructTemplate, "<!--#struct simple_pair(a,b)#-->"
|
|
ferencd@0
|
356 "<!--#parameters st:simple_pair#-->"
|
|
ferencd@0
|
357 "Testing {#x}{#st.a}{#st.b}");
|
|
ferencd@0
|
358 template_struct st("st", "simple_pair");
|
|
ferencd@0
|
359 st["a"] = "A";
|
|
ferencd@0
|
360 st["b"] = "B";
|
|
ferencd@0
|
361 std::string s = templater<VarAndSimpleStructTemplate>().templatize(
|
|
ferencd@0
|
362 "x" <is> 42,
|
|
ferencd@0
|
363 st
|
|
ferencd@0
|
364 ).get();
|
|
ferencd@0
|
365
|
|
ferencd@0
|
366 ASSERT_STREQ(s.c_str(), "Testing 42AB");
|
|
ferencd@0
|
367 }
|
|
ferencd@0
|
368
|
|
ferencd@0
|
369 TEST(StringTemplate,DISABLED_SimpleStruct2)
|
|
ferencd@0
|
370 {
|
|
ferencd@0
|
371 STRING_TEMPLATE(SecondSimpleStructTemplate, "<!--#struct simple(c)#-->"
|
|
ferencd@0
|
372 "<!--#struct simple_pair(a,b)#-->"
|
|
ferencd@0
|
373 "<!--#parameters st:simple_pair, x:simple#-->"
|
|
ferencd@0
|
374 "Testing {#x.c}{#st.a}{#st.b}");
|
|
ferencd@0
|
375
|
|
ferencd@0
|
376 template_struct st("st", "simple_pair");
|
|
ferencd@0
|
377 st["a"] = "A";
|
|
ferencd@0
|
378 st["b"] = "B";
|
|
ferencd@0
|
379
|
|
ferencd@0
|
380 template_struct x("x", "simple");
|
|
ferencd@0
|
381 x["c"] = "C";
|
|
ferencd@0
|
382
|
|
ferencd@0
|
383 std::string s = templater<SecondSimpleStructTemplate>().templatize(
|
|
ferencd@0
|
384 x,
|
|
ferencd@0
|
385 st
|
|
ferencd@0
|
386 ).get();
|
|
ferencd@0
|
387
|
|
ferencd@0
|
388 ASSERT_STREQ(s.c_str(), "Testing CAB");
|
|
ferencd@0
|
389 }
|
|
ferencd@0
|
390
|
|
ferencd@0
|
391 TEST(StringTemplate, Iterator)
|
|
ferencd@0
|
392 {
|
|
ferencd@0
|
393 STRING_TEMPLATE(ItSimpleStructTemplate, "<!--#struct simple(c)#-->"
|
|
ferencd@0
|
394 "<!--#parameters v:simple[]#-->"
|
|
ferencd@0
|
395 "Testing"
|
|
ferencd@0
|
396 "<!--#loop v#-->"
|
|
ferencd@0
|
397 "{#v.c}"
|
|
ferencd@0
|
398 "<!--#endloop v#-->");
|
|
ferencd@0
|
399
|
|
ferencd@0
|
400 std::vector<template_struct> structs;
|
|
ferencd@0
|
401
|
|
ferencd@0
|
402 template_struct ts("unused", "simple");
|
|
ferencd@0
|
403
|
|
ferencd@0
|
404 ts["c"] = "1";
|
|
ferencd@0
|
405 structs.push_back(ts);
|
|
ferencd@0
|
406
|
|
ferencd@0
|
407 ts["c"] = "2";
|
|
ferencd@0
|
408 structs.push_back(ts);
|
|
ferencd@0
|
409
|
|
ferencd@0
|
410 template_vector_par tvp("v", structs);
|
|
ferencd@0
|
411
|
|
ferencd@0
|
412 std::string s = templater<ItSimpleStructTemplate>().templatize(
|
|
ferencd@0
|
413 tvp
|
|
ferencd@0
|
414 ).get();
|
|
ferencd@0
|
415
|
|
ferencd@0
|
416 ASSERT_STREQ(s.c_str(), "Testing12");
|
|
ferencd@0
|
417 }
|
|
ferencd@0
|
418
|
|
ferencd@0
|
419
|
|
ferencd@0
|
420 TEST(StringTemplate,DISABLED_IteratorTwoStructsIfEq)
|
|
ferencd@0
|
421 {
|
|
ferencd@0
|
422 STRING_TEMPLATE(IteratorTwoStructsIfEq,"<!--#struct simple(c)#-->"
|
|
ferencd@0
|
423 "<!--#struct complex(d)#-->"
|
|
ferencd@0
|
424 "<!--#parameters v:simple[],w:complex[]#-->"
|
|
ferencd@0
|
425 "Testing"
|
|
ferencd@0
|
426 "<!--#loop v#-->"
|
|
ferencd@0
|
427 "{#v.c}"
|
|
ferencd@0
|
428 "<!--#endloop v#-->"
|
|
ferencd@0
|
429 "<!--#loop w#-->"
|
|
ferencd@0
|
430 "<!--#eq {#stg},{#w.d}#-->"
|
|
ferencd@0
|
431 "{#w.d}"
|
|
ferencd@0
|
432 "<!--#endeq#-->"
|
|
ferencd@0
|
433 "<!--#endloop w#-->"
|
|
ferencd@0
|
434 );
|
|
ferencd@0
|
435
|
|
ferencd@0
|
436 std::vector<template_struct> structs;
|
|
ferencd@0
|
437 std::vector<template_struct> structs2;
|
|
ferencd@0
|
438
|
|
ferencd@0
|
439 template_struct ts("simples", "simple");
|
|
ferencd@0
|
440 template_struct tsw("doubles", "double");
|
|
ferencd@0
|
441
|
|
ferencd@0
|
442 ts["c"] = "1"; structs.push_back(ts);
|
|
ferencd@0
|
443 ts["c"] = "2"; structs.push_back(ts);
|
|
ferencd@0
|
444
|
|
ferencd@0
|
445 tsw["d"] = "3"; structs2.push_back(tsw);
|
|
ferencd@0
|
446 tsw["d"] = "4"; structs2.push_back(tsw);
|
|
ferencd@0
|
447
|
|
ferencd@0
|
448 template_vector_par tvp("v", structs);
|
|
ferencd@0
|
449 template_vector_par tvp2("w", structs2);
|
|
ferencd@0
|
450
|
|
ferencd@0
|
451 std::string s = templater<IteratorTwoStructsIfEq>().templatize("stg" <is> "3").
|
|
ferencd@0
|
452 templatize(tvp2).
|
|
ferencd@0
|
453 templatize(tvp).
|
|
ferencd@0
|
454 get();
|
|
ferencd@0
|
455
|
|
ferencd@0
|
456 ASSERT_STREQ(s.c_str(), "Testing123");
|
|
ferencd@0
|
457 }
|
|
ferencd@0
|
458
|
|
ferencd@0
|
459
|
|
ferencd@0
|
460 TEST(StringTemplate,IteratorTwoStructs)
|
|
ferencd@0
|
461 {
|
|
ferencd@0
|
462 STRING_TEMPLATE(IteratorTwoStructs, "<!--#struct simple(c)#-->"
|
|
ferencd@0
|
463 "<!--#struct complex(d)#-->"
|
|
ferencd@0
|
464 "<!--#parameters v:simple[],w:complex[]#-->"
|
|
ferencd@0
|
465 "Testing"
|
|
ferencd@0
|
466 "<!--#loop v#-->"
|
|
ferencd@0
|
467 "{#v.c}"
|
|
ferencd@0
|
468 "<!--#endloop v#-->"
|
|
ferencd@0
|
469 "<!--#loop w#-->"
|
|
ferencd@0
|
470 "{#w.d}"
|
|
ferencd@0
|
471 "<!--#endloop w#-->"
|
|
ferencd@0
|
472 );
|
|
ferencd@0
|
473
|
|
ferencd@0
|
474 std::vector<template_struct> structs;
|
|
ferencd@0
|
475 std::vector<template_struct> structs2;
|
|
ferencd@0
|
476
|
|
ferencd@0
|
477 template_struct ts("simples", "simple");
|
|
ferencd@0
|
478 template_struct tsw("doubles", "double");
|
|
ferencd@0
|
479
|
|
ferencd@0
|
480 ts["c"] = "1"; structs.push_back(ts);
|
|
ferencd@0
|
481 ts["c"] = "2"; structs.push_back(ts);
|
|
ferencd@0
|
482
|
|
ferencd@0
|
483 tsw["d"] = "3"; structs2.push_back(tsw);
|
|
ferencd@0
|
484 tsw["d"] = "4"; structs2.push_back(tsw);
|
|
ferencd@0
|
485
|
|
ferencd@0
|
486 template_vector_par tvp("v", structs);
|
|
ferencd@0
|
487 template_vector_par tvp2("w", structs2);
|
|
ferencd@0
|
488
|
|
ferencd@0
|
489 std::string s = templater<IteratorTwoStructs>().templatize(tvp2).templatize(tvp).get();
|
|
ferencd@0
|
490
|
|
ferencd@0
|
491 ASSERT_STREQ(s.c_str(), "Testing1234");
|
|
ferencd@0
|
492 }
|
|
ferencd@0
|
493
|
|
ferencd@0
|
494 TEST(StringTemplate,DISABLED_JsonSource)
|
|
ferencd@0
|
495 {
|
|
ferencd@0
|
496 STRING_TEMPLATE(RequiredJsonTest, "Testing {str}");
|
|
ferencd@0
|
497 std::string s = templater<RequiredJsonTest>().templatize(nlohmann::json{
|
|
ferencd@0
|
498 {"str", "BLaaaaa"}
|
|
ferencd@0
|
499 }).get();
|
|
ferencd@0
|
500 std::cout << s << std::endl;
|
|
ferencd@0
|
501 }
|
|
ferencd@0
|
502
|
|
ferencd@0
|
503 /********************************************************************************************************************/
|
|
ferencd@0
|
504
|
|
ferencd@0
|
505 TABLE(Address)
|
|
ferencd@0
|
506 COLUMN(Id, INTEGER);
|
|
ferencd@0
|
507 COLUMN(StreetName, VARCHAR(256));
|
|
ferencd@0
|
508 COLUMN(Code, INTEGER);
|
|
ferencd@0
|
509 ENDTABLE(Address)
|
|
ferencd@0
|
510
|
|
ferencd@0
|
511 TABLE(Person)
|
|
ferencd@0
|
512 COLUMN(Id, INTEGER, PRIMARY_KEY);
|
|
ferencd@0
|
513 COLUMN(AddressId, INTEGER, NOT_NULL, DEFAULT(1));
|
|
ferencd@0
|
514 COLUMN(Name, VARCHAR(256));
|
|
ferencd@0
|
515 COLUMN(Age, INTEGER);
|
|
ferencd@0
|
516 COLUMN(Birthday, TIMESTAMP, DEFAULT(CURRENT_TIMESTAMP));
|
|
ferencd@0
|
517 FOREIGN_KEY(AddressId -> Address.Id);
|
|
ferencd@0
|
518 ENDTABLE(Person)
|
|
ferencd@0
|
519
|
|
ferencd@0
|
520 TEST(CppDb, DISABLED_BasicOperations)
|
|
ferencd@0
|
521 {
|
|
ferencd@0
|
522
|
|
ferencd@0
|
523 std::string combined_select = SELECT(Person.Id, Person.Name, Person.Age, Address.StreetName) +
|
|
ferencd@0
|
524 FROM ( Person, Address) +
|
|
ferencd@0
|
525 WHERE( Person.Id != 23 AND Person.AddressId == Address.Id );
|
|
ferencd@0
|
526 std::string p_create = Person.create();
|
|
ferencd@0
|
527 std::string insert = Person( Person.Age, Person.Name ).insert( 14, std::string("John Doe") );
|
|
ferencd@0
|
528 std::string prep_insert = Person( Person.Age, Person.Name ).prepare_insert( );
|
|
ferencd@0
|
529
|
|
ferencd@0
|
530 ASSERT_STREQ("SELECT Person.Id, Person.Name, Person.Age, Address.StreetName FROM Person, Address WHERE ((Person.Id<>23) AND (Person.AddressId=Address.Id))", combined_select.c_str() );
|
|
ferencd@0
|
531 ASSERT_STREQ("CREATE TABLE IF NOT EXISTS Person (Id INTEGER PRIMARY KEY, AddressId INTEGER NOT NULL DEFAULT 1, Name VARCHAR(256), Age INTEGER, Birthday TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (AddressId) REFERENCES Address(Id))", p_create.c_str());
|
|
ferencd@0
|
532 ASSERT_STREQ("INSERT OR IGNORE INTO Person(Age, Name) VALUES (14, \"John Doe\")", insert.c_str() );
|
|
ferencd@0
|
533 ASSERT_STREQ("INSERT OR IGNORE INTO Person(Age, Name) VALUES (:v1, :v2)", prep_insert.c_str() );
|
|
ferencd@0
|
534
|
|
ferencd@0
|
535 std::string ordered_select = SELECT(Person.Id, Person.Name, Person.Age, Address.StreetName) +
|
|
ferencd@0
|
536 FROM ( Person, Address) +
|
|
ferencd@0
|
537 WHERE( Person.Id != 23 AND Person.AddressId == Address.Id ) + ORDER_BY(Person.Name DESC, Person.Age ASC);
|
|
ferencd@0
|
538
|
|
ferencd@0
|
539 std::cout << ordered_select << std::endl;
|
|
ferencd@0
|
540
|
|
ferencd@0
|
541 std::string ordered_select2 = SELECT(Person.Id, Person.Name, Person.Age, Address.StreetName) +
|
|
ferencd@0
|
542 FROM ( Person, Address) +
|
|
ferencd@0
|
543 WHERE( Person.Id != 23 AND Person.AddressId == Address.Id ) + ORDER_BY(Person.Name DESC, Person.Age);
|
|
ferencd@0
|
544
|
|
ferencd@0
|
545 std::cout << ordered_select2;
|
|
ferencd@0
|
546 }
|
|
ferencd@0
|
547
|
|
ferencd@0
|
548 TEST(CppDb, DISABLED_Delete)
|
|
ferencd@0
|
549 {
|
|
ferencd@0
|
550 std::string s = DELETE + FROM (Person) + WHERE (Person.Id == 23);
|
|
ferencd@0
|
551 std::cout << s;
|
|
ferencd@0
|
552 }
|
|
ferencd@0
|
553
|
|
ferencd@0
|
554
|
|
ferencd@0
|
555 TEST(XSSSanitizer, DISABLED_RemoveIp)
|
|
ferencd@0
|
556 {
|
|
ferencd@0
|
557 std::string s = "THIS HAS AN IP192.168.1.1ABC";
|
|
ferencd@0
|
558 std::string s2 = "THIS HAS AN IP 192.168.1.1.ABC";
|
|
ferencd@0
|
559 std::string sanit = unafrog::utils::sanitize_user_input(s);
|
|
ferencd@0
|
560 std::string sanit2 = unafrog::utils::sanitize_user_input(s2);
|
|
ferencd@0
|
561 ASSERT_STREQ(sanit.c_str(), "THIS HAS AN IPABC");
|
|
ferencd@0
|
562 ASSERT_STREQ(sanit2.c_str(), "THIS HAS AN IP 192.168.1.1.ABC");
|
|
ferencd@0
|
563 }
|
|
ferencd@0
|
564
|
|
ferencd@0
|
565 TEST(ComponentBreaker, DISABLED_cb1)
|
|
ferencd@0
|
566 {
|
|
ferencd@0
|
567 url_breaker a("/A/B/C", "/alpha/beta/gamma");
|
|
ferencd@0
|
568 ASSERT_EQ( (a["A"] == "alpha"), true);
|
|
ferencd@0
|
569 ASSERT_EQ( (a["B"] == "beta"), true);
|
|
ferencd@0
|
570 ASSERT_EQ( (a["C"] == "gamma"), true);
|
|
ferencd@0
|
571 }
|
|
ferencd@0
|
572
|
|
ferencd@0
|
573
|
|
ferencd@0
|
574 TEST(B62, DISABLED_b62_enc)
|
|
ferencd@0
|
575 {
|
|
ferencd@0
|
576 std::string s = "5zn2cg3h";
|
|
ferencd@0
|
577
|
|
ferencd@0
|
578 uint64_t l = 19617184805931;
|
|
ferencd@0
|
579 std::string g = unafrog::utils::b62::base62_encode(l);
|
|
ferencd@0
|
580
|
|
ferencd@0
|
581 ASSERT_EQ(s, g);
|
|
ferencd@0
|
582 }
|
|
ferencd@0
|
583
|
|
ferencd@0
|
584 TEST(Convert, DISABLED_HexStringToNr)
|
|
ferencd@0
|
585 {
|
|
ferencd@0
|
586 ASSERT_EQ(9, unafrog::utils::hex_string_to_nr<int>("09"));
|
|
ferencd@0
|
587 ASSERT_EQ(0, unafrog::utils::hex_string_to_nr<int>("00"));
|
|
ferencd@0
|
588 ASSERT_EQ(10, unafrog::utils::hex_string_to_nr<int>("0A"));
|
|
ferencd@0
|
589 ASSERT_EQ(1987, unafrog::utils::hex_string_to_nr<int>("07c3"));
|
|
ferencd@0
|
590 }
|
|
ferencd@0
|
591
|
|
ferencd@0
|
592
|
|
ferencd@0
|
593 TEST(UrlMaker, DISABLED_args)
|
|
ferencd@0
|
594 {
|
|
ferencd@0
|
595 std::string s = unafrog::utils::make_url("a", "b", "c");
|
|
ferencd@0
|
596 std::string s1 = unafrog::utils::make_url("a");
|
|
ferencd@0
|
597 std::string s2 = unafrog::utils::make_url("a", "b");
|
|
ferencd@0
|
598
|
|
ferencd@0
|
599 ASSERT_EQ(s, "a/b/c");
|
|
ferencd@0
|
600 ASSERT_EQ(s1, "a");
|
|
ferencd@0
|
601 ASSERT_EQ(s2, "a/b");
|
|
ferencd@0
|
602 }
|
|
ferencd@0
|
603
|
|
ferencd@0
|
604 TEST(Conversion, DISABLED_IntToHex)
|
|
ferencd@0
|
605 {
|
|
ferencd@0
|
606 ASSERT_EQ("0f", unafrog::utils::int_to_hex<char>(15));
|
|
ferencd@0
|
607 }
|
|
ferencd@0
|
608
|
|
ferencd@0
|
609
|
|
ferencd@0
|
610 TEST(Common, DISABLED_DuplicateRemover)
|
|
ferencd@0
|
611 {
|
|
ferencd@0
|
612 ASSERT_EQ("ABC/DEF", remove_duplicates("ABC//DEF", '/'));
|
|
ferencd@0
|
613 ASSERT_EQ("ABCC/DEF", remove_duplicates("ABCC/DEF", '/'));
|
|
ferencd@0
|
614 ASSERT_EQ("/", remove_duplicates("//", '/'));
|
|
ferencd@0
|
615 }
|
|
ferencd@0
|
616
|