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