1 /*
2 4ti2 -- A software package for algebraic, geometric and combinatorial
3 problems on linear spaces.
4 
5 Copyright (C) 2008 4ti2 team.
6 Main author(s): Peter Malkin.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
26 #include <cstdlib>
27 
28 #include "4ti2/4ti2.h"
29 #include "4ti2/4ti2xx.h"
30 #include <gmpxx.h>
31 
32 using namespace std;
33 
34 static void
usage()35 usage()
36 {
37   cerr << "usage: ..." << endl;
38   exit(1);
39 }
40 
41 #define CHECK_STATUS(expr)			\
42 if ((expr) != _4ti2_OK ) {			\
43   cerr << "Error on " << #expr << endl;		\
44   exit (1);					\
45 }
46 
check_matrix(_4ti2_state * qsolve_api,const char * name,mpz_class & x)47 static void check_matrix(_4ti2_state* qsolve_api, const char *name, mpz_class &x)
48 {
49   _4ti2_matrix* matrix;
50   mpz_class y;
51   CHECK_STATUS(_4ti2_state_create_matrix(qsolve_api, 1, 1, name, &matrix));
52   CHECK_STATUS(_4ti2_matrix_set_entry_mpz_ptr(matrix, 0, 0, x.get_mpz_t()));
53   CHECK_STATUS(_4ti2_matrix_get_entry_mpz_ptr(matrix, 0, 0, y.get_mpz_t()));
54   if (x != y) {
55     cerr << "Data conversion failed: " << name << ": " << x << " != " << y << endl;
56     exit(1);
57   }
58 }
59 
60 // usage: test_input_conversion_APIPRECISION INTERNAL-PRECISION MATRIX-NAME DATA
61 int
main(int argc,char ** argv)62 main(int argc, char **argv)
63 {
64     // Input data.
65     if (argc != 4) usage();
66 
67     _4ti2_precision prec;
68     switch (atoi(argv[1])) {
69     case 0:
70       prec = _4ti2_PREC_INT_ARB;
71       break;
72     case 32:
73       prec = _4ti2_PREC_INT_32;
74       break;
75     case 64:
76       prec = _4ti2_PREC_INT_64;
77       break;
78     default:
79       usage();
80     }
81 
82     _4ti2_state* qsolve_api = _4ti2_qsolve_create_state(prec);
83     const int qsolve_argc = 2;
84     char *qsolve_argv[2] = { "qsolve", "-q" };
85     _4ti2_state_set_options(qsolve_api, qsolve_argc, qsolve_argv);
86 
87     mpz_class x;
88     stringstream datastream(argv[3]);
89     datastream >> x;
90     if (datastream.bad()) {
91       cerr << "Error reading data" << endl;
92       exit(1);
93     }
94     check_matrix(qsolve_api, argv[2], x);
95 
96     _4ti2_state_delete(qsolve_api);
97     return 0;
98 }
99 
100