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/taler_util.h"
23 : #include "taler/taler_mhd_lib.h"
24 :
25 : static int global_ret;
26 :
27 : static struct TALER_MHD_TypstContext *tc;
28 :
29 : static int keep_output;
30 :
31 : static void
32 1 : do_shutdown (void *cls)
33 : {
34 1 : if (NULL != tc)
35 : {
36 0 : TALER_MHD_typst_cancel (tc);
37 0 : tc = NULL;
38 : }
39 1 : }
40 :
41 :
42 : /**
43 : * Function called with the result of a #TALER_MHD_typst() operation.
44 : *
45 : * @param cls closure
46 : * @param tr result of the operation
47 : */
48 : static void
49 0 : result_cb (void *cls,
50 : const struct TALER_MHD_TypstResponse *tr)
51 : {
52 0 : tc = NULL;
53 0 : if (TALER_EC_NONE != tr->ec)
54 : {
55 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
56 : "PDF generation failed\n");
57 0 : global_ret = 1;
58 : }
59 : else
60 : {
61 0 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
62 : "PDF created at %s\n",
63 : tr->details.filename);
64 : }
65 0 : GNUNET_SCHEDULER_shutdown ();
66 0 : }
67 :
68 :
69 : /**
70 : * Main function that will be run.
71 : */
72 : static void
73 1 : run (void *cls,
74 : char *const *args,
75 : const char *cfgfile,
76 : const struct GNUNET_CONFIGURATION_Handle *cfg)
77 : {
78 : char *datadir
79 1 : = GNUNET_OS_installation_get_path (TALER_EXCHANGE_project_data (),
80 : GNUNET_OS_IPK_DATADIR);
81 2 : json_t *forms[] = {
82 1 : GNUNET_JSON_PACK (
83 : GNUNET_JSON_pack_string ("VQF_MEMBER_NUMBER",
84 : "12345"),
85 : GNUNET_JSON_pack_string ("FILE_NUMBER",
86 : "-1"),
87 : GNUNET_JSON_pack_string ("DATADIR",
88 : datadir)),
89 1 : GNUNET_JSON_PACK (
90 : GNUNET_JSON_pack_string ("VQF_MEMBER_NUMBER",
91 : "54321"),
92 : GNUNET_JSON_pack_string ("FILE_NUMBER",
93 : "-1"),
94 : GNUNET_JSON_pack_string ("DATADIR",
95 : datadir)),
96 : NULL,
97 : };
98 1 : struct TALER_MHD_TypstDocument docs[] = {
99 : {
100 : .form_name = "test_typst_1.typ",
101 1 : .data = forms[0],
102 : },
103 : {
104 : .form_name = "test_typst_1.typ",
105 1 : .data = forms[1],
106 : },
107 : };
108 :
109 1 : GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
110 : NULL);
111 1 : tc = TALER_MHD_typst (TALER_EXCHANGE_project_data (),
112 : 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 */
|