1 /* Test Grid_Generator ascii_dump() and ascii_load().
2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4
5 This file is part of the Parma Polyhedra Library (PPL).
6
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23
24 #include "ppl_test.hh"
25
26 #include "files.hh"
27 #include <string>
28 #include <fstream>
29
30 using std::string;
31 using std::fstream;
32 using std::ios_base;
33
34 namespace {
35
36 // Load the result of a dump.
37 bool
test01()38 test01() {
39 const char* my_file = "ascii_dump_load5.dat";
40 Variable A(0);
41 Variable B(1);
42
43 Grid_Generator g1 = grid_point(A - B);
44
45 fstream f;
46 open(f, my_file, ios_base::out);
47 g1.ascii_dump(f);
48 close(f);
49
50 open(f, my_file, ios_base::in);
51 Grid_Generator g2(grid_point(0*B));
52 g2.ascii_load(f);
53 close(f);
54
55 bool ok = (g1 == g2);
56
57 print_generator(g1, "*** g1 ***");
58 print_generator(g2, "*** g2 ***");
59
60 return ok;
61 }
62
63 // ascii_load failure.
64 bool
test02()65 test02() {
66 const char* my_file = "ascii_dump_load5.dat";
67 Variable A(0);
68
69 fstream f;
70 open(f, my_file, ios_base::out);
71 f << "1\n";
72 close(f);
73
74 open(f, my_file, ios_base::in);
75 Grid_Generator g(grid_point(0*A));
76 bool ok = !g.ascii_load(f);
77 close(f);
78
79 return ok;
80 }
81
82 // ascii_load failure.
83 bool
test03()84 test03() {
85 const char* my_file = "ascii_dump_load5.dat";
86 Variable A(0);
87
88 fstream f;
89 open(f, my_file, ios_base::out);
90 f << "1 0 3\n";
91 close(f);
92
93 open(f, my_file, ios_base::in);
94 Grid_Generator g(grid_point(0*A));
95 bool ok = !g.ascii_load(f);
96 close(f);
97
98 return ok;
99 }
100
101 // ascii_load failure.
102 bool
test04()103 test04() {
104 const char* my_file = "ascii_dump_load5.dat";
105 Variable A(0);
106
107 fstream f;
108 open(f, my_file, ios_base::out);
109 f << "1 0 1 err\n";
110 close(f);
111
112 open(f, my_file, ios_base::in);
113 Grid_Generator g(grid_point(0*A));
114 bool ok = !g.ascii_load(f);
115 close(f);
116
117 return ok;
118 }
119
120 // Load and dump a line.
121 bool
test05()122 test05() {
123 const char* my_file = "ascii_dump_load5.dat";
124 Variable A(0);
125 Variable B(0);
126
127 Grid_Generator g1 = grid_line(2*A - B);
128
129 fstream f;
130 open(f, my_file, ios_base::out);
131 g1.ascii_dump(f);
132 close(f);
133
134 open(f, my_file, ios_base::in);
135 Grid_Generator g2(grid_point(0*B));
136 g2.ascii_load(f);
137 close(f);
138
139 bool ok = (g1 == g2);
140
141 print_generator(g1, "*** g1 ***");
142 print_generator(g2, "*** g2 ***");
143
144 return ok;
145 }
146
147 } // namespace
148
149 BEGIN_MAIN
150 DO_TEST(test01);
151 DO_TEST(test02);
152 DO_TEST(test03);
153 DO_TEST(test04);
154 DO_TEST(test05);
155 END_MAIN
156