xref: /netbsd-src/external/lgpl3/mpc/dist/tests/data_check.tpl (revision 39f28e1e142c5bfb6be935a49cb55e2287fec7ea)
1/* data_check.tpl -- template file for checking result against data
2   file.
3
4   Usage: Before including this template file in your source file,
5   #define the prototype of the function under test in the
6   CALL_MPC_FUNCTION symbol, see tadd_tmpl.c for an example.
7
8   To test the reuse of the first parameter, #define the
9   MPC_FUNCTION_CALL_REUSE_OP1 and MPC_FUNCTION_CALL_REUSE_OP2 symbols
10   with the first and second input parameter reused as the output, see
11   tadd_tmpl.c for an example. It is not possible to test parameter
12   reuse in functions with two output (like mpc_sin_cos) with this
13   system.
14
15Copyright (C) 2012, 2013 INRIA
16
17This file is part of GNU MPC.
18
19GNU MPC is free software; you can redistribute it and/or modify it under
20the terms of the GNU Lesser General Public License as published by the
21Free Software Foundation; either version 3 of the License, or (at your
22option) any later version.
23
24GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
25WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
27more details.
28
29You should have received a copy of the GNU Lesser General Public License
30along with this program. If not, see http://www.gnu.org/licenses/ .
31*/
32
33#ifndef MPC_FUNCTION_CALL
34#error Define MPC_FUNCTION_CALL before including 'data_check.tpl'.
35#endif
36
37int
38data_check_template (const char* descr_file, const char * data_file)
39{
40  static int rand_counter = 0;
41
42  mpc_datafile_context_t datafile_context;
43  mpc_datafile_context_t *dc = &datafile_context;
44
45  mpc_fun_param_t params;
46  mpc_operand_t *P = params.P; /* developer-friendly alias */
47
48  read_description (&params, descr_file);
49  init_parameters (&params);
50
51  open_datafile (dc, data_file);
52  while (datafile_context.nextchar != EOF) {
53    read_line (dc, &params);
54    set_mpfr_flags (rand_counter);
55    MPC_FUNCTION_CALL;
56    check_mpfr_flags (rand_counter++);
57    check_data (dc, &params, 0);
58
59#ifdef MPC_FUNCTION_CALL_SYMMETRIC
60      MPC_FUNCTION_CALL_SYMMETRIC;
61      check_data (dc, &params, 0);
62#endif
63
64#ifdef MPC_FUNCTION_CALL_REUSE_OP1
65    if (copy_parameter (&params, 1, 2) == 0)
66      {
67        MPC_FUNCTION_CALL_REUSE_OP1;
68        check_data (dc, &params, 2);
69      }
70#endif
71
72#ifdef MPC_FUNCTION_CALL_REUSE_OP2
73    if (copy_parameter (&params, 1, 3) == 0)
74      {
75        MPC_FUNCTION_CALL_REUSE_OP2;
76        check_data (dc, &params, 3);
77      }
78#endif
79
80#ifdef MPC_FUNCTION_CALL_REUSE_OP3
81    if (copy_parameter (&params, 1, 4) == 0)
82      {
83        MPC_FUNCTION_CALL_REUSE_OP3;
84        check_data (dc, &params, 4);
85      }
86#endif
87  }
88  close_datafile (dc);
89
90  clear_parameters (&params);
91
92  return 0;
93}
94