LCOV - code coverage report
Current view: top level - templating - test_mustach_jansson.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 42 42
Test Date: 2025-12-28 14:06:02 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2014-2020 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify
       6              :   it under the terms of the GNU General Public License as
       7              :   published by the Free Software Foundation; either version 3, or
       8              :   (at your option) any later version.
       9              : 
      10              :   TALER is distributed in the hope that it will be useful, but
      11              :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13              :   GNU General Public License for more details.
      14              : 
      15              :   You should have received a copy of the GNU General Public
      16              :   License along with TALER; see the file COPYING.  If not, see
      17              :   <http://www.gnu.org/licenses/>
      18              : */
      19              : 
      20              : /**
      21              :  * @file test_mustach_jansson.c
      22              :  * @brief testcase to test the mustach/jansson integration
      23              :  * @author Florian Dold
      24              :  */
      25              : #include "taler/platform.h"
      26              : #include "mustach-jansson.h"
      27              : #include <gnunet/gnunet_util_lib.h>
      28              : 
      29              : static void
      30            6 : assert_template (const char *template,
      31              :                  json_t *root,
      32              :                  const char *expected)
      33              : {
      34              :   char *r;
      35              :   size_t sz;
      36              : 
      37            6 :   GNUNET_assert (0 == mustach_jansson_mem (template,
      38              :                                            0,
      39              :                                            root,
      40              :                                            Mustach_With_AllExtensions,
      41              :                                            &r,
      42              :                                            &sz));
      43            6 :   GNUNET_assert (0 == strcmp (r,
      44              :                               expected));
      45            6 :   GNUNET_free (r);
      46            6 : }
      47              : 
      48              : 
      49              : int
      50            1 : main (int argc,
      51              :       char *const *argv)
      52              : {
      53            1 :   json_t *root = json_object ();
      54            1 :   json_t *arr = json_array ();
      55            1 :   json_t *obj = json_object ();
      56              :   /* test 1 */
      57            1 :   const char *t1 = "hello world";
      58            1 :   const char *x1 = "hello world";
      59              :   /* test 2 */
      60            1 :   const char *t2 = "hello {{ v1 }}";
      61            1 :   const char *x2 = "hello world";
      62              :   /* test 3 */
      63            1 :   const char *t3 = "hello {{ v3.x }}";
      64            1 :   const char *x3 = "hello baz";
      65              :   /* test 4 */
      66            1 :   const char *t4 = "hello {{# v2 }}{{ . }}{{/ v2 }}";
      67            1 :   const char *x4 = "hello foobar";
      68              :   /* test 5 */
      69            1 :   const char *t5 = "hello {{# v3 }}{{ y }}/{{ x }}{{ z }}{{/ v3 }}";
      70            1 :   const char *x5 = "hello quux/baz";
      71              :   /* test 8 */
      72            1 :   const char *t8 = "{{^ v4 }}fallback{{/ v4 }}";
      73            1 :   const char *x8 = "fallback";
      74              : 
      75              :   (void) argc;
      76              :   (void) argv;
      77            1 :   GNUNET_log_setup ("test-mustach-jansson",
      78              :                     "INFO",
      79              :                     NULL);
      80            1 :   GNUNET_assert (NULL != root);
      81            1 :   GNUNET_assert (NULL != arr);
      82            1 :   GNUNET_assert (NULL != obj);
      83            1 :   GNUNET_assert (0 ==
      84              :                  json_object_set_new (root,
      85              :                                       "v1",
      86              :                                       json_string ("world")));
      87            1 :   GNUNET_assert (0 ==
      88              :                  json_object_set_new (root,
      89              :                                       "v4",
      90              :                                       json_array ()));
      91            1 :   GNUNET_assert (0 ==
      92              :                  json_array_append_new (arr,
      93              :                                         json_string ("foo")));
      94            1 :   GNUNET_assert (0 ==
      95              :                  json_array_append_new (arr,
      96              :                                         json_string ("bar")));
      97            1 :   GNUNET_assert (0 ==
      98              :                  json_object_set_new (root,
      99              :                                       "v2",
     100              :                                       arr));
     101            1 :   GNUNET_assert (0 ==
     102              :                  json_object_set_new (root,
     103              :                                       "v3",
     104              :                                       obj));
     105            1 :   GNUNET_assert (0 ==
     106              :                  json_object_set_new (root,
     107              :                                       "amt",
     108              :                                       json_string ("EUR:123.00")));
     109            1 :   GNUNET_assert (0 ==
     110              :                  json_object_set_new (obj,
     111              :                                       "x",
     112              :                                       json_string ("baz")));
     113            1 :   GNUNET_assert (0 ==
     114              :                  json_object_set_new (obj,
     115              :                                       "y",
     116              :                                       json_string ("quux")));
     117            1 :   assert_template (t1, root, x1);
     118            1 :   assert_template (t2, root, x2);
     119            1 :   assert_template (t3, root, x3);
     120            1 :   assert_template (t4, root, x4);
     121            1 :   assert_template (t5, root, x5);
     122            1 :   assert_template (t8, root, x8);
     123            1 :   json_decref (root);
     124            1 :   return 0;
     125              : }
        

Generated by: LCOV version 2.0-1