test_typst.c (4194B)
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 do_shutdown (void *cls) 34 { 35 if (NULL != tc) 36 { 37 TALER_MHD_typst_cancel (tc); 38 tc = NULL; 39 } 40 } 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 result_cb (void *cls, 51 const struct TALER_MHD_TypstResponse *tr) 52 { 53 tc = NULL; 54 if (TALER_EC_NONE != tr->ec) 55 { 56 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 57 "PDF generation failed\n"); 58 global_ret = 1; 59 } 60 else 61 { 62 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 63 "PDF created at %s\n", 64 tr->details.filename); 65 } 66 GNUNET_SCHEDULER_shutdown (); 67 } 68 69 70 /** 71 * Main function that will be run. 72 */ 73 static void 74 run (void *cls, 75 char *const *args, 76 const char *cfgfile, 77 const struct GNUNET_CONFIGURATION_Handle *cfg) 78 { 79 char *datadir 80 = GNUNET_OS_installation_get_path (TALER_EXCHANGE_project_data (), 81 GNUNET_OS_IPK_DATADIR); 82 json_t *forms[] = { 83 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 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 struct TALER_MHD_TypstDocument docs[] = { 100 { 101 .form_name = "test_typst_1", 102 .data = forms[0], 103 }, 104 { 105 .form_name = "test_typst_1", 106 .data = forms[1], 107 }, 108 }; 109 110 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 111 NULL); 112 tc = TALER_MHD_typst (cfg, 113 keep_output ? true : false, 114 "test-typst", 115 2, 116 docs, 117 &result_cb, 118 NULL); 119 for (unsigned int i = 0; NULL != forms[i]; i++) 120 json_decref (forms[i]); 121 GNUNET_free (datadir); 122 } 123 124 125 int 126 main (int argc, 127 const char *const argv[]) 128 { 129 const char *argvx[] = { 130 "test_typst", 131 "-c", "test_typst.conf", 132 "-L", "INFO", 133 NULL 134 }; 135 struct GNUNET_GETOPT_CommandLineOption options[] = { 136 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 GNUNET_log_setup ("test-typst", 146 "INFO", 147 NULL); 148 if (GNUNET_OK != 149 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 GNUNET_break (0); 158 return 1; 159 } 160 return global_ret; 161 } 162 163 164 /* end of test_typst.c */