LCOV - code coverage report
Current view: top level - mhd - test_typst.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 67.6 % 37 25
Test Date: 2025-12-28 14:06:02 Functions: 75.0 % 4 3

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2025 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify it under the
       6              :   terms of the GNU General Public License as published by the Free Software
       7              :   Foundation; either version 3, or (at your option) any later version.
       8              : 
       9              :   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
      10              :   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11              :   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12              : 
      13              :   You should have received a copy of the GNU General Public License along with
      14              :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15              : */
      16              : 
      17              : /**
      18              :  * @file mhd/test_typst.c
      19              :  * @brief Tests for Typst-MHD logic
      20              :  * @author Christian Grothoff <christian@grothoff.org>
      21              :  */
      22              : #include "taler/platform.h"
      23              : #include "taler/taler_util.h"
      24              : #include "taler/taler_mhd_lib.h"
      25              : 
      26              : static int global_ret;
      27              : 
      28              : static struct TALER_MHD_TypstContext *tc;
      29              : 
      30              : static int keep_output;
      31              : 
      32              : static void
      33            1 : do_shutdown (void *cls)
      34              : {
      35            1 :   if (NULL != tc)
      36              :   {
      37            0 :     TALER_MHD_typst_cancel (tc);
      38            0 :     tc = NULL;
      39              :   }
      40            1 : }
      41              : 
      42              : 
      43              : /**
      44              :  * Function called with the result of a #TALER_MHD_typst() operation.
      45              :  *
      46              :  * @param cls closure
      47              :  * @param tr result of the operation
      48              :  */
      49              : static void
      50            0 : result_cb (void *cls,
      51              :            const struct TALER_MHD_TypstResponse *tr)
      52              : {
      53            0 :   tc = NULL;
      54            0 :   if (TALER_EC_NONE != tr->ec)
      55              :   {
      56            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      57              :                 "PDF generation failed\n");
      58            0 :     global_ret = 1;
      59              :   }
      60              :   else
      61              :   {
      62            0 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      63              :                 "PDF created at %s\n",
      64              :                 tr->details.filename);
      65              :   }
      66            0 :   GNUNET_SCHEDULER_shutdown ();
      67            0 : }
      68              : 
      69              : 
      70              : /**
      71              :  * Main function that will be run.
      72              :  */
      73              : static void
      74            1 : run (void *cls,
      75              :      char *const *args,
      76              :      const char *cfgfile,
      77              :      const struct GNUNET_CONFIGURATION_Handle *cfg)
      78              : {
      79              :   char *datadir
      80            1 :     = GNUNET_OS_installation_get_path (TALER_EXCHANGE_project_data (),
      81              :                                        GNUNET_OS_IPK_DATADIR);
      82            2 :   json_t *forms[] = {
      83            1 :     GNUNET_JSON_PACK (
      84              :       GNUNET_JSON_pack_string ("VQF_MEMBER_NUMBER",
      85              :                                "12345"),
      86              :       GNUNET_JSON_pack_string ("FILE_NUMBER",
      87              :                                "-1"),
      88              :       GNUNET_JSON_pack_string ("DATADIR",
      89              :                                datadir)),
      90            1 :     GNUNET_JSON_PACK (
      91              :       GNUNET_JSON_pack_string ("VQF_MEMBER_NUMBER",
      92              :                                "54321"),
      93              :       GNUNET_JSON_pack_string ("FILE_NUMBER",
      94              :                                "-1"),
      95              :       GNUNET_JSON_pack_string ("DATADIR",
      96              :                                datadir)),
      97              :     NULL,
      98              :   };
      99            1 :   struct TALER_MHD_TypstDocument docs[] = {
     100              :     {
     101              :       .form_name = "test_typst_1",
     102            1 :       .data = forms[0],
     103              :     },
     104              :     {
     105              :       .form_name = "test_typst_1",
     106            1 :       .data = forms[1],
     107              :     },
     108              :   };
     109              : 
     110            1 :   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
     111              :                                  NULL);
     112            1 :   tc = TALER_MHD_typst (cfg,
     113              :                         keep_output ? true : false,
     114              :                         "test-typst",
     115              :                         2,
     116              :                         docs,
     117              :                         &result_cb,
     118              :                         NULL);
     119            3 :   for (unsigned int i = 0; NULL != forms[i]; i++)
     120            2 :     json_decref (forms[i]);
     121            1 :   GNUNET_free (datadir);
     122            1 : }
     123              : 
     124              : 
     125              : int
     126            1 : main (int argc,
     127              :       const char *const argv[])
     128              : {
     129            1 :   const char *argvx[] = {
     130              :     "test_typst",
     131              :     "-c", "test_typst.conf",
     132              :     "-L", "INFO",
     133              :     NULL
     134              :   };
     135            1 :   struct GNUNET_GETOPT_CommandLineOption options[] = {
     136            1 :     GNUNET_GETOPT_option_flag ('k',
     137              :                                "keep-output",
     138              :                                "do not delete directory at the end of the test",
     139              :                                &keep_output),
     140              :     GNUNET_GETOPT_OPTION_END
     141              :   };
     142              : 
     143              :   (void) argc;
     144              :   (void) argv;
     145            1 :   GNUNET_log_setup ("test-typst",
     146              :                     "INFO",
     147              :                     NULL);
     148            1 :   if (GNUNET_OK !=
     149            1 :       GNUNET_PROGRAM_run (TALER_EXCHANGE_project_data (),
     150              :                           5, (char **) argvx,
     151              :                           "test_typst",
     152              :                           "Test typst",
     153              :                           options,
     154              :                           &run,
     155              :                           NULL))
     156              :   {
     157            0 :     GNUNET_break (0);
     158            0 :     return 1;
     159              :   }
     160            1 :   return global_ret;
     161              : }
     162              : 
     163              : 
     164              : /* end of test_typst.c */
        

Generated by: LCOV version 2.0-1